summaryrefslogtreecommitdiff
path: root/networkx/algorithms/centrality/tests/test_harmonic_centrality.py
diff options
context:
space:
mode:
Diffstat (limited to 'networkx/algorithms/centrality/tests/test_harmonic_centrality.py')
-rw-r--r--networkx/algorithms/centrality/tests/test_harmonic_centrality.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/networkx/algorithms/centrality/tests/test_harmonic_centrality.py b/networkx/algorithms/centrality/tests/test_harmonic_centrality.py
index 8048508b..ae2bad7d 100644
--- a/networkx/algorithms/centrality/tests/test_harmonic_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_harmonic_centrality.py
@@ -1,9 +1,9 @@
"""
Tests for degree centrality.
"""
+import pytest
import networkx as nx
from networkx.algorithms.centrality import harmonic_centrality
-from networkx.testing import almost_equal
class TestClosenessCentrality:
@@ -27,43 +27,43 @@ class TestClosenessCentrality:
c = harmonic_centrality(self.P3)
d = {0: 1.5, 1: 2, 2: 1.5}
for n in sorted(self.P3):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_p4_harmonic(self):
c = harmonic_centrality(self.P4)
d = {0: 1.8333333, 1: 2.5, 2: 2.5, 3: 1.8333333}
for n in sorted(self.P4):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_clique_complete(self):
c = harmonic_centrality(self.K5)
d = {0: 4, 1: 4, 2: 4, 3: 4, 4: 4}
for n in sorted(self.P3):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_cycle_C4(self):
c = harmonic_centrality(self.C4)
d = {0: 2.5, 1: 2.5, 2: 2.5, 3: 2.5}
for n in sorted(self.C4):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_cycle_C5(self):
c = harmonic_centrality(self.C5)
d = {0: 3, 1: 3, 2: 3, 3: 3, 4: 3, 5: 4}
for n in sorted(self.C5):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_bal_tree(self):
c = harmonic_centrality(self.T)
d = {0: 4.0, 1: 4.1666, 2: 4.1666, 3: 2.8333, 4: 2.8333, 5: 2.8333, 6: 2.8333}
for n in sorted(self.T):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_exampleGraph(self):
c = harmonic_centrality(self.Gb)
d = {0: 0, 1: 2, 2: 1, 3: 2.5, 4: 1}
for n in sorted(self.Gb):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_weighted_harmonic(self):
XG = nx.DiGraph()
@@ -80,7 +80,7 @@ class TestClosenessCentrality:
c = harmonic_centrality(XG, distance="weight")
d = {"a": 0, "b": 0.1, "c": 2.533, "d": 0, "e": 0, "f": 0.83333}
for n in sorted(XG):
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_empty(self):
G = nx.DiGraph()
@@ -99,16 +99,16 @@ class TestClosenessCentrality:
c = harmonic_centrality(self.C4_directed, nbunch=[0, 1], sources=[1, 2])
d = {0: 0.833, 1: 0.333}
for n in [0, 1]:
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_p3_harmonic_subset(self):
c = harmonic_centrality(self.P3, sources=[0, 1])
d = {0: 1, 1: 1, 2: 1.5}
for n in self.P3:
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)
def test_p4_harmonic_subset(self):
c = harmonic_centrality(self.P4, nbunch=[2, 3], sources=[0, 1])
d = {2: 1.5, 3: 0.8333333}
for n in [2, 3]:
- assert almost_equal(c[n], d[n], places=3)
+ assert c[n] == pytest.approx(d[n], abs=1e-3)