From 927c8799a5255bd03baee0390e6b46fb751e50ee Mon Sep 17 00:00:00 2001 From: Alimi Qudirah Date: Tue, 2 May 2023 16:26:02 +0100 Subject: Added tests to test_correlation.py (#6590) * added tests to test_correlation.py * bugfix-for-6588 --- .../algorithms/assortativity/tests/test_correlation.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/networkx/algorithms/assortativity/tests/test_correlation.py b/networkx/algorithms/assortativity/tests/test_correlation.py index dbaa432e..5203f944 100644 --- a/networkx/algorithms/assortativity/tests/test_correlation.py +++ b/networkx/algorithms/assortativity/tests/test_correlation.py @@ -15,6 +15,13 @@ class TestDegreeMixingCorrelation(BaseTestDegreeMixing): r = nx.degree_assortativity_coefficient(self.P4) np.testing.assert_almost_equal(r, -1.0 / 2, decimal=4) + def test_degree_assortativity_node_kwargs(self): + G = nx.Graph() + edges = [(0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (5, 9), (9, 0)] + G.add_edges_from(edges) + r = nx.degree_assortativity_coefficient(G, nodes=[1, 2, 4]) + np.testing.assert_almost_equal(r, -1.0, decimal=4) + def test_degree_assortativity_directed(self): r = nx.degree_assortativity_coefficient(self.D) np.testing.assert_almost_equal(r, -0.57735, decimal=4) @@ -99,6 +106,14 @@ class TestAttributeMixingCorrelation(BaseTestAttributeMixing): r = nx.numeric_assortativity_coefficient(self.N, "margin") np.testing.assert_almost_equal(r, -0.2903, decimal=4) + def test_assortativity_node_kwargs(self): + G = nx.Graph() + G.add_nodes_from([0, 1], size=2) + G.add_nodes_from([2, 3], size=3) + G.add_edges_from([(0, 1), (2, 3)]) + r = nx.numeric_assortativity_coefficient(G, "size", nodes=[0, 3]) + np.testing.assert_almost_equal(r, 1.0, decimal=4) + def test_attribute_assortativity_float(self): r = nx.numeric_assortativity_coefficient(self.F, "margin") np.testing.assert_almost_equal(r, -0.1429, decimal=4) -- cgit v1.2.1