summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMjh9122 <69970567+Mjh9122@users.noreply.github.com>2022-10-31 15:26:10 -0400
committerJarrod Millman <jarrod.millman@gmail.com>2022-11-01 10:28:46 -0700
commit040c356fcfa9c7de1e913d63f0ef9dcc10a5b218 (patch)
treecad216e28645f0f234cc3ed22148e0648002d4ea
parent2baa77640281f01a66e238235ed16f08b08597a7 (diff)
downloadnetworkx-040c356fcfa9c7de1e913d63f0ef9dcc10a5b218.tar.gz
Increased test coverage algorithms/matching.py (#6095)
Increased test coverage in is_matching, is_maximal_matching, is_perfect_matching
-rw-r--r--networkx/algorithms/tests/test_matching.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/networkx/algorithms/tests/test_matching.py b/networkx/algorithms/tests/test_matching.py
index b5a466da..57603bcb 100644
--- a/networkx/algorithms/tests/test_matching.py
+++ b/networkx/algorithms/tests/test_matching.py
@@ -450,7 +450,7 @@ class TestIsMatching:
assert not nx.is_matching(G, {(0, 0), (1, 2), (2, 3)})
# selfloop edge in G
G.add_edge(0, 0)
- assert not nx.is_matching(G, {(0, 0), (1, 2), (2, 3)})
+ assert not nx.is_matching(G, {(0, 0), (1, 2)})
def test_invalid_matching(self):
G = nx.path_graph(4)
@@ -476,6 +476,16 @@ class TestIsMaximalMatching:
G = nx.path_graph(4)
assert nx.is_maximal_matching(G, {0: 1, 1: 0, 2: 3, 3: 2})
+ def test_invalid_input(self):
+ error = nx.NetworkXError
+ G = nx.path_graph(4)
+ # edge to node not in G
+ raises(error, nx.is_maximal_matching, G, {(0, 5)})
+ raises(error, nx.is_maximal_matching, G, {(5, 0)})
+ # edge not a 2-tuple
+ raises(error, nx.is_maximal_matching, G, {(0, 1, 2), (2, 3)})
+ raises(error, nx.is_maximal_matching, G, {(0,), (2, 3)})
+
def test_valid(self):
G = nx.path_graph(4)
assert nx.is_maximal_matching(G, {(0, 1), (2, 3)})
@@ -483,6 +493,9 @@ class TestIsMaximalMatching:
def test_not_matching(self):
G = nx.path_graph(4)
assert not nx.is_maximal_matching(G, {(0, 1), (1, 2), (2, 3)})
+ assert not nx.is_maximal_matching(G, {(0, 3)})
+ G.add_edge(0, 0)
+ assert not nx.is_maximal_matching(G, {(0, 0)})
def test_not_maximal(self):
G = nx.path_graph(4)
@@ -511,8 +524,30 @@ class TestIsPerfectMatching:
assert nx.is_perfect_matching(G, {(1, 4), (0, 3), (5, 2)})
+ def test_invalid_input(self):
+ error = nx.NetworkXError
+ G = nx.path_graph(4)
+ # edge to node not in G
+ raises(error, nx.is_perfect_matching, G, {(0, 5)})
+ raises(error, nx.is_perfect_matching, G, {(5, 0)})
+ # edge not a 2-tuple
+ raises(error, nx.is_perfect_matching, G, {(0, 1, 2), (2, 3)})
+ raises(error, nx.is_perfect_matching, G, {(0,), (2, 3)})
+
+ def test_selfloops(self):
+ error = nx.NetworkXError
+ G = nx.path_graph(4)
+ # selfloop for node not in G
+ raises(error, nx.is_perfect_matching, G, {(5, 5), (2, 3)})
+ # selfloop edge not in G
+ assert not nx.is_perfect_matching(G, {(0, 0), (1, 2), (2, 3)})
+ # selfloop edge in G
+ G.add_edge(0, 0)
+ assert not nx.is_perfect_matching(G, {(0, 0), (1, 2)})
+
def test_not_matching(self):
G = nx.path_graph(4)
+ assert not nx.is_perfect_matching(G, {(0, 3)})
assert not nx.is_perfect_matching(G, {(0, 1), (1, 2), (2, 3)})
def test_maximal_but_not_perfect(self):