Skip to content

Commit c6dea4e

Browse files
committed
CI: Added python tests to test_cycle_basis.py
- Added `TestCycleBasisEdges` class for unit testing. - Added similar tests to those present on `TestCycleBasis`. - Tests are similar due to the same methodology. - Graphs used for testing are different.
1 parent c22c0b5 commit c6dea4e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/rustworkx_tests/graph/test_cycle_basis.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,54 @@ def test_self_loop(self):
6767
self.graph.add_edge(1, 1, None)
6868
res = sorted(sorted(c) for c in rustworkx.cycle_basis(self.graph, 0))
6969
self.assertEqual([[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5], [1]], res)
70+
71+
72+
class TestCycleBasisEdges(unittest.TestCase):
73+
def setUp(self):
74+
self.graph = rustworkx.PyGraph()
75+
self.graph.add_nodes_from(list(range(10)))
76+
self.graph.add_edges_from_no_data(
77+
[
78+
(0, 1),
79+
(0, 2),
80+
(1, 2),
81+
(2, 3),
82+
(3, 4),
83+
(3, 5),
84+
(4, 5),
85+
(4, 6),
86+
(6, 7),
87+
(6, 8),
88+
(8, 9),
89+
]
90+
)
91+
92+
def test_cycle_basis_edges(self):
93+
graph = self.graph
94+
res = sorted(sorted(c) for c in rustworkx.cycle_basis_edges(graph, 0))
95+
self.assertEqual([[0, 1, 2], [4, 5, 6]], res)
96+
97+
def test_cycle_basis_edges_multiple_roots_same_cycles(self):
98+
res = sorted(sorted(x) for x in rustworkx.cycle_basis_edges(self.graph, 0))
99+
self.assertEqual([[0, 1, 2], [4, 5, 6]], res)
100+
res = sorted(sorted(x) for x in rustworkx.cycle_basis_edges(self.graph, 5))
101+
self.assertEqual([[0, 1, 2], [4, 5, 6]], res)
102+
res = sorted(sorted(x) for x in rustworkx.cycle_basis_edges(self.graph, 7))
103+
self.assertEqual([[0, 1, 2], [4, 5, 6]], res)
104+
105+
def test_cycle_basis_disconnected_graphs(self):
106+
self.graph.add_nodes_from(["A", "B", "C"])
107+
self.graph.add_edges_from_no_data([(10, 11), (10, 12), (11, 12)])
108+
cycles = rustworkx.cycle_basis_edges(self.graph, 9)
109+
res = sorted(sorted(x) for x in cycles[:-1]) + [sorted(cycles[-1])]
110+
self.assertEqual(res, [[0, 1, 2], [4, 5, 6], [11, 12, 13]])
111+
112+
def test_invalid_types(self):
113+
digraph = rustworkx.PyDiGraph()
114+
with self.assertRaises(TypeError):
115+
rustworkx.cycle_basis_edges(digraph)
116+
117+
def test_self_loop(self):
118+
self.graph.add_edge(1, 1, None)
119+
res = sorted(sorted(c) for c in rustworkx.cycle_basis_edges(self.graph, 0))
120+
self.assertEqual([[0, 1, 2], [4, 5, 6], [11]], res)

0 commit comments

Comments
 (0)