Passed
Push — master ( dfbdfc...38602d )
by Xianshun
01:26
created

StronglyConnectedComponentsUnitTest.test_cc()   A

Complexity

Conditions 4

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
dl 14
loc 14
rs 9.2
c 0
b 0
f 0
1
import unittest
2
from random import randint
3
4
from pyalgs.algorithms.graphs.connectivity import ConnectedComponents, StronglyConnectedComponents
5
from tests.algorithms.graphs.util import create_graph_4_connected_components, \
6
    create_digraph_4_strongly_connected_components
7
8
9 View Code Duplication
class ConnectedComponentsUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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 View Code Duplication
class StronglyConnectedComponentsUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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__':
44
    unittest.main()
45