@@ 20-30 (lines=11) @@ | ||
17 | print('path length is ' + str(dijkstra.path_length_to(v))) |
|
18 | ||
19 | ||
20 | class TopologicalSortShortestPathUnitTest(unittest.TestCase): |
|
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__': |
|
@@ 8-17 (lines=10) @@ | ||
5 | from tests.algorithms.graphs.util import create_edge_weighted_digraph |
|
6 | ||
7 | ||
8 | class DijkstraShortestPathUnitTest(unittest.TestCase): |
|
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 | class TopologicalSortShortestPathUnitTest(unittest.TestCase): |