BreadthFirstSearchUnitTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 20
loc 20
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_dfs_digraph() 9 9 4
A test_dfs() 9 9 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
3
from pyalgs.algorithms.graphs.search import DepthFirstSearch, BreadthFirstSearch
4
from tests.algorithms.graphs.util import create_graph, create_digraph
5
6
7 View Code Duplication
class DepthFirstSearchUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8
    def test_dfs(self):
9
        g = create_graph() # or create_digraph
10
        s = 0
11
        dfs = DepthFirstSearch(g, s)
12
13
        for v in range(1, g.vertex_count()):
14
            if dfs.hasPathTo(v):
15
                print(str(s) + ' is connected to ' + str(v))
16
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
17
18
    def test_dfs_digraph(self):
19
        g = create_digraph()
20
        s = 0
21
        dfs = DepthFirstSearch(g, s)
22
23
        for v in range(1, g.vertex_count()):
24
            if dfs.hasPathTo(v):
25
                print(str(s) + ' is connected to ' + str(v))
26
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
27
28 View Code Duplication
class BreadthFirstSearchUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29
    def test_dfs(self):
30
        g = create_graph() # or create_digraph
31
        s = 0
32
        dfs = BreadthFirstSearch(g, s)
33
34
        for v in range(1, g.vertex_count()):
35
            if dfs.hasPathTo(v):
36
                print(str(s) + ' is connected to ' + str(v))
37
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
38
39
    def test_dfs_digraph(self):
40
        g = create_digraph()
41
        s = 0
42
        dfs = BreadthFirstSearch(g, s)
43
44
        for v in range(1, g.vertex_count()):
45
            if dfs.hasPathTo(v):
46
                print(str(s) + ' is connected to ' + str(v))
47
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
48
49
50
if __name__ == '__main__':
51
    unittest.main()
52