Passed
Push — master ( 38602d...192324 )
by Xianshun
01:33
created

DijkstraShortestPathUnitTest.test_shortest_path()   A

Complexity

Conditions 4

Size

Total Lines 9

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 9
rs 9.2
1
import unittest
2
3
from pyalgs.algorithms.graphs.shortest_path import DijkstraShortestPath
4
from tests.algorithms.graphs.util import create_edge_weighted_digraph
5
6
7
class DijkstraShortestPathUnitTest(unittest.TestCase):
8
    def test_shortest_path(self):
9
        g = create_edge_weighted_digraph()
10
        s = 0
11
        dijkstra = DijkstraShortestPath(g, s)
12
        for v in range(1, g.vertex_count()):
13
            if dijkstra.hasPathTo(v):
14
                print(str(s) + ' is connected to ' + str(v))
15
                print('shortest path is ' + ' .. '.join([str(i) for i in dijkstra.shortestPathTo(v)]))
16
                print('path length is ' + str(dijkstra.path_length_to(v)))
17
18
19
if __name__ == '__main__':
20
    unittest.main()