|
@@ 26-40 (lines=15) @@
|
| 23 |
|
print(str(v) + ' is connected to ' + str(r)) |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
class StronglyConnectedComponentsUnitTest(unittest.TestCase): |
| 27 |
|
def test_cc(self): |
| 28 |
|
G = create_digraph_4_strongly_connected_components() |
| 29 |
|
|
| 30 |
|
cc = StronglyConnectedComponents(G) |
| 31 |
|
print('strongly connected component count: ' + str(cc.count())) |
| 32 |
|
|
| 33 |
|
self.assertEqual(5, cc.count()) |
| 34 |
|
|
| 35 |
|
for v in range(G.vertex_count()): |
| 36 |
|
print('id[' + str(v) + ']: ' + str(cc.id(v))) |
| 37 |
|
for v in range(G.vertex_count()): |
| 38 |
|
r = randint(0, G.vertex_count() - 1) |
| 39 |
|
if cc.connected(v, r): |
| 40 |
|
print(str(v) + ' is connected to ' + str(r)) |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
if __name__ == '__main__': |
|
@@ 9-23 (lines=15) @@
|
| 6 |
|
create_digraph_4_strongly_connected_components |
| 7 |
|
|
| 8 |
|
|
| 9 |
|
class ConnectedComponentsUnitTest(unittest.TestCase): |
| 10 |
|
def test_cc(self): |
| 11 |
|
G = create_graph_4_connected_components() |
| 12 |
|
|
| 13 |
|
cc = ConnectedComponents(G) |
| 14 |
|
print('connected component count: ' + str(cc.count())) |
| 15 |
|
|
| 16 |
|
self.assertEqual(3, cc.count()) |
| 17 |
|
|
| 18 |
|
for v in range(G.vertex_count()): |
| 19 |
|
print('id[' + str(v) + ']: ' + str(cc.id(v))) |
| 20 |
|
for v in range(G.vertex_count()): |
| 21 |
|
r = randint(0, G.vertex_count() - 1) |
| 22 |
|
if cc.connected(v, r): |
| 23 |
|
print(str(v) + ' is connected to ' + str(r)) |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
class StronglyConnectedComponentsUnitTest(unittest.TestCase): |