32 lines
756 B
Python
32 lines
756 B
Python
from dijkstra import dijkstra
|
|
|
|
def test_basic():
|
|
g = {"a": [("b", 1), ("c", 4)], "b": [("c", 2)], "c": []}
|
|
d = dijkstra(g, "a")
|
|
assert d["a"] == 0 and d["b"] == 1 and d["c"] == 3
|
|
|
|
def test_unreachable():
|
|
g = {"a": [], "b": []}
|
|
d = dijkstra(g, "a")
|
|
assert d["b"] == float("inf")
|
|
|
|
def test_unknown_src():
|
|
try:
|
|
dijkstra({"a": []}, "z")
|
|
raise AssertionError("expected")
|
|
except ValueError:
|
|
pass
|
|
|
|
def test_negative():
|
|
try:
|
|
dijkstra({"a": [("b", -1)]}, "a")
|
|
raise AssertionError("expected")
|
|
except ValueError:
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
for n in [x for x in globals() if x.startswith("test_")]:
|
|
globals()[n]()
|
|
print("PASS", n)
|
|
print("ALL PASS")
|