Completed
Push — master ( 60d34b...f90dfb )
by Xianshun
01:18
created

TopologicalSortShortestPathUnitTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 11
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_shortest_path() 10 10 5

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.directed_cycle import DirectedCycle
4
from pyalgs.algorithms.graphs.shortest_path import DijkstraShortestPath, TopologicalSortShortestPath
5
from tests.algorithms.graphs.util import create_edge_weighted_digraph
6
7
8 View Code Duplication
class DijkstraShortestPathUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    def test_shortest_path(self):
10
        g = create_edge_weighted_digraph()
11
        s = 0
12
        dijkstra = DijkstraShortestPath(g, s)
13
        for v in range(1, g.vertex_count()):
14
            if dijkstra.hasPathTo(v):
15
                print(str(s) + ' is connected to ' + str(v))
16
                print('shortest path is ' + ' .. '.join([str(i) for i in dijkstra.shortestPathTo(v)]))
17
                print('path length is ' + str(dijkstra.path_length_to(v)))
18
19
20 View Code Duplication
class TopologicalSortShortestPathUnitTest(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
21
    def test_shortest_path(self):
22
        g = create_edge_weighted_digraph()
23
        assert not DirectedCycle(g).hasCycle()
24
        s = 0
25
        dijkstra = TopologicalSortShortestPath(g, s)
26
        for v in range(1, g.vertex_count()):
27
            if dijkstra.hasPathTo(v):
28
                print(str(s) + ' is connected to ' + str(v))
29
                print('shortest path is ' + ' .. '.join([str(i) for i in dijkstra.shortestPathTo(v)]))
30
                print('path length is ' + str(dijkstra.path_length_to(v)))
31
32
33
if __name__ == '__main__':
34
    unittest.main()