Skip to content

Commit

Permalink
Add test to compare output with random graph to networkx
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Jan 25, 2021
1 parent 7a72299 commit 308c82a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions tests/test_max_weight_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest

import retworkx
import networkx


class TestMaxWeightMatching(unittest.TestCase):
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down

0 comments on commit 308c82a

Please sign in to comment.