4
4
5
5
6
6
class EdmondsBlossomAlgorithmTest (unittest .TestCase ):
7
-
8
7
def convert_matching_to_array (self , matching ):
9
- """ Helper method to convert a
8
+ """Helper method to convert a
10
9
list of matching pairs into a sorted 2D array.
11
10
"""
12
11
# Convert the list of pairs into a list of lists
@@ -21,39 +20,39 @@ def convert_matching_to_array(self, matching):
21
20
return result
22
21
23
22
def test_case_1 (self ):
24
- """ Test Case 1: A triangle graph where vertices 0, 1, and 2 form a cycle. """
23
+ """Test Case 1: A triangle graph where vertices 0, 1, and 2 form a cycle."""
25
24
edges = [[0 , 1 ], [1 , 2 ], [2 , 0 ]]
26
25
matching = EdmondsBlossomAlgorithm .maximum_matching (edges , 3 )
27
26
28
27
expected = [[0 , 1 ]]
29
28
assert expected == self .convert_matching_to_array (matching )
30
29
31
30
def test_case_2 (self ):
32
- """ Test Case 2: A disconnected graph with two components. """
31
+ """Test Case 2: A disconnected graph with two components."""
33
32
edges = [[0 , 1 ], [1 , 2 ], [3 , 4 ]]
34
33
matching = EdmondsBlossomAlgorithm .maximum_matching (edges , 5 )
35
34
36
35
expected = [[0 , 1 ], [3 , 4 ]]
37
36
assert expected == self .convert_matching_to_array (matching )
38
37
39
38
def test_case_3 (self ):
40
- """ Test Case 3: A cycle graph with an additional edge outside the cycle. """
39
+ """Test Case 3: A cycle graph with an additional edge outside the cycle."""
41
40
edges = [[0 , 1 ], [1 , 2 ], [2 , 3 ], [3 , 0 ], [4 , 5 ]]
42
41
matching = EdmondsBlossomAlgorithm .maximum_matching (edges , 6 )
43
42
44
43
expected = [[0 , 1 ], [2 , 3 ], [4 , 5 ]]
45
44
assert expected == self .convert_matching_to_array (matching )
46
45
47
46
def test_case_no_matching (self ):
48
- """ Test Case 4: A graph with no edges. """
47
+ """Test Case 4: A graph with no edges."""
49
48
edges = [] # No edges
50
49
matching = EdmondsBlossomAlgorithm .maximum_matching (edges , 3 )
51
50
52
51
expected = []
53
52
assert expected == self .convert_matching_to_array (matching )
54
53
55
54
def test_case_large_graph (self ):
56
- """ Test Case 5: A complex graph with multiple cycles and extra edges. """
55
+ """Test Case 5: A complex graph with multiple cycles and extra edges."""
57
56
edges = [[0 , 1 ], [1 , 2 ], [2 , 3 ], [3 , 4 ], [4 , 5 ], [5 , 0 ], [1 , 4 ], [2 , 5 ]]
58
57
matching = EdmondsBlossomAlgorithm .maximum_matching (edges , 6 )
59
58
@@ -69,5 +68,5 @@ def test_case_large_graph(self):
69
68
assert result in (possible_matching_1 , possible_matching_2 )
70
69
71
70
72
- if __name__ == ' __main__' :
71
+ if __name__ == " __main__" :
73
72
unittest .main ()
0 commit comments