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

ConnectedComponentsUnitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_cc() 0 14 4
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