summaryrefslogtreecommitdiffstats
path: root/test_dijkstra.py
diff options
context:
space:
mode:
authorjullinator <justus.karlsson@hotmail.se>2018-08-25 02:03:46 +0200
committerjullinator <justus.karlsson@hotmail.se>2018-08-25 02:03:46 +0200
commite3b6cb5c1cf67286409ae5f9789f203e6beddff1 (patch)
tree40df5783f85193b885cffc3c1cc8efc4bfdf61b0 /test_dijkstra.py
parentb72e4ee4ae112beb4894c4cdb4cf69c6c8dcc061 (diff)
downloadtdde25-e3b6cb5c1cf67286409ae5f9789f203e6beddff1.tar.gz
new structure
Diffstat (limited to 'test_dijkstra.py')
-rw-r--r--test_dijkstra.py46
1 files changed, 13 insertions, 33 deletions
diff --git a/test_dijkstra.py b/test_dijkstra.py
index 76799de..4f54b4e 100644
--- a/test_dijkstra.py
+++ b/test_dijkstra.py
@@ -1,39 +1,19 @@
import Graph
-
+from collections import defaultdict
+from heapq import heappush, heappop
+import math
def dijkstra(adjacency_list, source, target):
- """ To be implemented by students. Should return (distance, path).
- Path should be a list of the vertices in the shortest path
- including the source and target. """
- return 6.433, ['A', 'C', 'D']
-
-
-def test_dijkstra():
- vertices = [
- ('A', 0, 0),
- ('B', 2, 2),
- ('C', 2, -2),
- ('D', 4, 1),
- ('E', 4, -2),
- ('F', 6, 1)
- ]
-
- edges = [
- ('A', 'B'),
- ('A', 'C'),
- ('C', 'D'),
- ('B', 'C'),
- ('D', 'F'),
- ('B', 'E'),
- ('A', 'F')
- ]
+ """ To be implemented by students. `adjacency_list` is a dictionary with values: (vertice, weight).
+ Function should return (distance, path). Path should be a list of the vertices in the shortest path
+ **including** the source and target. If no shortest path is found, it should return (infinity, []) """
- graph = Graph.Dijkstra(vertices, edges, 'A', 'D')
- dist1, path1 = graph.get_shortest_path()
- dist2, path2 = dijkstra(graph.adjacency_list, graph.source, graph.target)
- assert abs(dist1-dist2) < 1e-3
- print('Correct distance')
- assert path1 == path2
- print('Correct path')
+ return math.inf, [source]
+if __name__ == '__main__':
+ try:
+ Graph.test_dijkstra(dijkstra)
+ print('Passed ALL tests!')
+ except AssertionError:
+ print('Failed one or more tests') \ No newline at end of file