From 308c82a831ed73d963925af22545e199db00b895 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 25 Jan 2021 07:57:03 -0500 Subject: [PATCH] Add test to compare output with random graph to networkx --- tests/test_max_weight_matching.py | 23 +++++++++++++++++++++++ tox.ini | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_max_weight_matching.py b/tests/test_max_weight_matching.py index 53a79fd91..cf731cb25 100644 --- a/tests/test_max_weight_matching.py +++ b/tests/test_max_weight_matching.py @@ -16,6 +16,7 @@ import unittest import retworkx +import networkx class TestMaxWeightMatching(unittest.TestCase): @@ -329,3 +330,25 @@ def test_nested_blossom_augmented(self): self.assertEqual( retworkx.max_weight_matching(graph, weight_fn=lambda x: x), expected) + + def test_gnp_random_against_networkx(self): + rx_graph = retworkx.undirected_gnp_random_graph(10, .75, seed=42) + nx_graph = networkx.Graph(list(rx_graph.edge_list())) + nx_matches = networkx.max_weight_matching(nx_graph) + rx_match_dict = retworkx.max_weight_matching(rx_graph) + # Convert retworkx dict output to networkx set of tuples + rx_matches = { + (u, v) for (u, v) in set(map(frozenset, rx_match_dict.items()))} + self.assertEqual(nx_matches, rx_matches) + + def test_gnp_random_against_networkx_max_cardinality(self): + rx_graph = retworkx.undirected_gnp_random_graph(10, .78, seed=428) + nx_graph = networkx.Graph(list(rx_graph.edge_list())) + nx_matches = networkx.max_weight_matching( + nx_graph, maxcardinality=True) + rx_match_dict = retworkx.max_weight_matching( + rx_graph, max_cardinality=True) + # Convert retworkx dict output to networkx set of tuples + rx_matches = { + (u, v) for (u, v) in set(map(frozenset, rx_match_dict.items()))} + self.assertEqual(nx_matches, rx_matches) diff --git a/tox.ini b/tox.ini index c62c1d8fe..c800243cd 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,9 @@ setenv = LANGUAGE=en_US LC_ALL=en_US.utf-8 ARGS="-V" -deps = setuptools-rust +deps = + setuptools-rust + networkx>=2.5 changedir = {toxinidir}/tests commands = python -m unittest discover .