diff options
Diffstat (limited to 'networkx/algorithms/centrality/tests/test_load_centrality.py')
-rw-r--r-- | networkx/algorithms/centrality/tests/test_load_centrality.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/networkx/algorithms/centrality/tests/test_load_centrality.py b/networkx/algorithms/centrality/tests/test_load_centrality.py index 66d0ea56..5d69884a 100644 --- a/networkx/algorithms/centrality/tests/test_load_centrality.py +++ b/networkx/algorithms/centrality/tests/test_load_centrality.py @@ -1,5 +1,5 @@ +import pytest import networkx as nx -from networkx.testing import almost_equal class TestLoadCentrality: @@ -37,8 +37,8 @@ class TestLoadCentrality: b = nx.load_centrality(self.D) result = {0: 5.0 / 12, 1: 1.0 / 4, 2: 1.0 / 12, 3: 1.0 / 4, 4: 0.000} for n in sorted(self.D): - assert almost_equal(result[n], b[n], places=3) - assert almost_equal(result[n], nx.load_centrality(self.D, n), places=3) + assert result[n] == pytest.approx(b[n], abs=1e-3) + assert result[n] == pytest.approx(nx.load_centrality(self.D, n), abs=1e-3) def test_weighted_load(self): b = nx.load_centrality(self.G, weight="weight", normalized=False) @@ -50,25 +50,25 @@ class TestLoadCentrality: c = nx.load_centrality(G) d = {0: 0.000, 1: 0.000, 2: 0.000, 3: 0.000, 4: 0.000} for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_p3_load(self): G = self.P3 c = nx.load_centrality(G) d = {0: 0.000, 1: 1.000, 2: 0.000} for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) c = nx.load_centrality(G, v=1) - assert almost_equal(c, 1.0) + assert c == pytest.approx(1.0, abs=1e-7) c = nx.load_centrality(G, v=1, normalized=True) - assert almost_equal(c, 1.0) + assert c == pytest.approx(1.0, abs=1e-7) def test_p2_load(self): G = nx.path_graph(2) c = nx.load_centrality(G) d = {0: 0.000, 1: 0.000} for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_krackhardt_load(self): G = self.K @@ -86,7 +86,7 @@ class TestLoadCentrality: 9: 0.000, } for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_florentine_families_load(self): G = self.F @@ -109,7 +109,7 @@ class TestLoadCentrality: "Tornabuoni": 0.090, } for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_les_miserables_load(self): G = self.LM @@ -194,21 +194,21 @@ class TestLoadCentrality: "MmeHucheloup": 0.000, } for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_unnormalized_k5_load(self): G = self.K5 c = nx.load_centrality(G, normalized=False) d = {0: 0.000, 1: 0.000, 2: 0.000, 3: 0.000, 4: 0.000} for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_unnormalized_p3_load(self): G = self.P3 c = nx.load_centrality(G, normalized=False) d = {0: 0.000, 1: 2.000, 2: 0.000} for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_unnormalized_krackhardt_load(self): G = self.K @@ -227,7 +227,7 @@ class TestLoadCentrality: } for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_unnormalized_florentine_families_load(self): G = self.F @@ -251,7 +251,7 @@ class TestLoadCentrality: "Tornabuoni": 16.333, } for n in sorted(G): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_load_betweenness_difference(self): # Difference Between Load and Betweenness @@ -287,21 +287,21 @@ class TestLoadCentrality: c = nx.load_centrality(B, normalized=False) d = {0: 1.750, 1: 1.750, 2: 6.500, 3: 6.500, 4: 1.750, 5: 1.750} for n in sorted(B): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_c4_edge_load(self): G = self.C4 c = nx.edge_load_centrality(G) d = {(0, 1): 6.000, (0, 3): 6.000, (1, 2): 6.000, (2, 3): 6.000} for n in G.edges(): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_p4_edge_load(self): G = self.P4 c = nx.edge_load_centrality(G) d = {(0, 1): 6.000, (1, 2): 8.000, (2, 3): 6.000} for n in G.edges(): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_k5_edge_load(self): G = self.K5 @@ -319,7 +319,7 @@ class TestLoadCentrality: (3, 4): 5.000, } for n in G.edges(): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) def test_tree_edge_load(self): G = self.T @@ -333,4 +333,4 @@ class TestLoadCentrality: (2, 6): 12.000, } for n in G.edges(): - assert almost_equal(c[n], d[n], places=3) + assert c[n] == pytest.approx(d[n], abs=1e-3) |