Passed
Push — master ( dc545e...500623 )
by Xianshun
01:42
created

ConnectedComponentsUnitTest.test_cc()   A

Complexity

Conditions 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 14
rs 9.2
1
import unittest
2
from random import randint
3
4
from pyalgs.algorithms.graphs.connectivity import ConnectedComponents
5
from tests.algorithms.graphs.util import create_graph_4_connected_components
6
7
8
class ConnectedComponentsUnitTest(unittest.TestCase):
9
    def test_cc(self):
10
        G = create_graph_4_connected_components()
11
12
        cc = ConnectedComponents(G)
13
        print('connected component count: ' + str(cc.count()))
14
15
        self.assertEqual(3, cc.count())
16
17
        for v in range(G.vertex_count()):
18
            print('id[' + str(v) + ']: ' + str(cc.id(v)))
19
        for v in range(G.vertex_count()):
20
            r = randint(0, G.vertex_count()-1)
21
            if cc.connected(v, r):
22
                print(str(v) + ' is connected to ' + str(r))
23
24
25
if __name__ == '__main__':
26
    unittest.main()
27