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

StronglyConnectedComponentsUnitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 100 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_cc() 14 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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