-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_spfa.py
57 lines (50 loc) · 1.47 KB
/
test_spfa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from pathfinder.city import City
from pathfinder.spfa import SPFA
from pathfinder.graph import spfa_graph
tests = [
{
"start": City.BORDEAUX,
"end": City.STRASBOURG,
"path": {
"total": 15,
"steps": [City.BORDEAUX, City.NANTES, City.RENNES, City.ROUEN, City.PARIS, City.ORLEANS, City.STRASBOURG]
}
},
{
"start": City.NANTES,
"end": City.LILLE,
"path": {
"total": 15,
"steps": [City.NANTES, City.RENNES, City.ROUEN, City.PARIS, City.ORLEANS, City.STRASBOURG, City.LILLE]
}
},
{
"start": City.BORDEAUX,
"end": City.LYON,
"path": {
"total": -25,
"steps": [City.BORDEAUX, City.TOULOUSE, City.LYON]
}
},
{
"start": City.NANTES,
"end": City.ORLEANS,
"path": {
"total": -50,
"steps": [City.NANTES, City.RENNES, City.ROUEN, City.PARIS, City.ORLEANS]
}
}
]
test_spfa = SPFA(spfa_graph)
error = False
for test in tests:
print("\033[34m-> Testing SPFA path from", test["start"], "to", test["end"], "\033[0m")
spfa_path = test_spfa.get_shortest_path(test["start"], test["end"])
if spfa_path == test["path"]:
print("\033[92m✓ Test OK for SPFA path from", test["start"], "to", test["end"], "\033[0m")
else:
print("\033[91mError for SPFA path from", test["start"], "to", test["end"], "\033[0m")
print("Expected", test["path"])
print("Got ", spfa_path)
error = True
print('\033[92m✓ OK' if not error else '\033[91m❌ KO')