diff options
Diffstat (limited to 'networkx/algorithms/tests/test_structuralholes.py')
-rw-r--r-- | networkx/algorithms/tests/test_structuralholes.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/networkx/algorithms/tests/test_structuralholes.py b/networkx/algorithms/tests/test_structuralholes.py index a0499e65..31f62416 100644 --- a/networkx/algorithms/tests/test_structuralholes.py +++ b/networkx/algorithms/tests/test_structuralholes.py @@ -1,7 +1,7 @@ """Unit tests for the :mod:`networkx.algorithms.structuralholes` module.""" import math +import pytest import networkx as nx -from networkx.testing import almost_equal class TestStructuralHoles: @@ -51,67 +51,67 @@ class TestStructuralHoles: def test_constraint_directed(self): constraint = nx.constraint(self.D) - assert almost_equal(constraint[0], 1.003, places=3) - assert almost_equal(constraint[1], 1.003, places=3) - assert almost_equal(constraint[2], 1.389, places=3) + assert constraint[0] == pytest.approx(1.003, abs=1e-3) + assert constraint[1] == pytest.approx(1.003, abs=1e-3) + assert constraint[2] == pytest.approx(1.389, abs=1e-3) def test_effective_size_directed(self): effective_size = nx.effective_size(self.D) - assert almost_equal(effective_size[0], 1.167, places=3) - assert almost_equal(effective_size[1], 1.167, places=3) - assert almost_equal(effective_size[2], 1, places=3) + assert effective_size[0] == pytest.approx(1.167, abs=1e-3) + assert effective_size[1] == pytest.approx(1.167, abs=1e-3) + assert effective_size[2] == pytest.approx(1, abs=1e-3) def test_constraint_weighted_directed(self): D = self.D.copy() nx.set_edge_attributes(D, self.D_weights, "weight") constraint = nx.constraint(D, weight="weight") - assert almost_equal(constraint[0], 0.840, places=3) - assert almost_equal(constraint[1], 1.143, places=3) - assert almost_equal(constraint[2], 1.378, places=3) + assert constraint[0] == pytest.approx(0.840, abs=1e-3) + assert constraint[1] == pytest.approx(1.143, abs=1e-3) + assert constraint[2] == pytest.approx(1.378, abs=1e-3) def test_effective_size_weighted_directed(self): D = self.D.copy() nx.set_edge_attributes(D, self.D_weights, "weight") effective_size = nx.effective_size(D, weight="weight") - assert almost_equal(effective_size[0], 1.567, places=3) - assert almost_equal(effective_size[1], 1.083, places=3) - assert almost_equal(effective_size[2], 1, places=3) + assert effective_size[0] == pytest.approx(1.567, abs=1e-3) + assert effective_size[1] == pytest.approx(1.083, abs=1e-3) + assert effective_size[2] == pytest.approx(1, abs=1e-3) def test_constraint_undirected(self): constraint = nx.constraint(self.G) - assert almost_equal(constraint["G"], 0.400, places=3) - assert almost_equal(constraint["A"], 0.595, places=3) - assert almost_equal(constraint["C"], 1, places=3) + assert constraint["G"] == pytest.approx(0.400, abs=1e-3) + assert constraint["A"] == pytest.approx(0.595, abs=1e-3) + assert constraint["C"] == pytest.approx(1, abs=1e-3) def test_effective_size_undirected_borgatti(self): effective_size = nx.effective_size(self.G) - assert almost_equal(effective_size["G"], 4.67, places=2) - assert almost_equal(effective_size["A"], 2.50, places=2) - assert almost_equal(effective_size["C"], 1, places=2) + assert effective_size["G"] == pytest.approx(4.67, abs=1e-2) + assert effective_size["A"] == pytest.approx(2.50, abs=1e-2) + assert effective_size["C"] == pytest.approx(1, abs=1e-2) def test_effective_size_undirected(self): G = self.G.copy() nx.set_edge_attributes(G, 1, "weight") effective_size = nx.effective_size(G, weight="weight") - assert almost_equal(effective_size["G"], 4.67, places=2) - assert almost_equal(effective_size["A"], 2.50, places=2) - assert almost_equal(effective_size["C"], 1, places=2) + assert effective_size["G"] == pytest.approx(4.67, abs=1e-2) + assert effective_size["A"] == pytest.approx(2.50, abs=1e-2) + assert effective_size["C"] == pytest.approx(1, abs=1e-2) def test_constraint_weighted_undirected(self): G = self.G.copy() nx.set_edge_attributes(G, self.G_weights, "weight") constraint = nx.constraint(G, weight="weight") - assert almost_equal(constraint["G"], 0.299, places=3) - assert almost_equal(constraint["A"], 0.795, places=3) - assert almost_equal(constraint["C"], 1, places=3) + assert constraint["G"] == pytest.approx(0.299, abs=1e-3) + assert constraint["A"] == pytest.approx(0.795, abs=1e-3) + assert constraint["C"] == pytest.approx(1, abs=1e-3) def test_effective_size_weighted_undirected(self): G = self.G.copy() nx.set_edge_attributes(G, self.G_weights, "weight") effective_size = nx.effective_size(G, weight="weight") - assert almost_equal(effective_size["G"], 5.47, places=2) - assert almost_equal(effective_size["A"], 2.47, places=2) - assert almost_equal(effective_size["C"], 1, places=2) + assert effective_size["G"] == pytest.approx(5.47, abs=1e-2) + assert effective_size["A"] == pytest.approx(2.47, abs=1e-2) + assert effective_size["C"] == pytest.approx(1, abs=1e-2) def test_constraint_isolated(self): G = self.G.copy() |