-
Notifications
You must be signed in to change notification settings - Fork 65
/
test_graph.py
35 lines (30 loc) · 912 Bytes
/
test_graph.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
from pathfinding.core.graph import Graph
from pathfinding.finder.dijkstra import DijkstraFinder
def test_graph_dijkstra():
edges = [
[1, 2, 7],
[1, 3, 9],
[1, 6, 14],
[2, 3, 10],
[2, 4, 15],
[3, 4, 11],
[3, 6, 2],
[4, 5, 6],
[6, 5, 9]
]
graph = Graph(edges=edges, bi_directional=True)
finder = DijkstraFinder()
path, _ = finder.find_path(graph.node(1), graph.node(5), graph)
assert [n.node_id for n in path] == [1, 3, 6, 5]
def test_connected_end():
# see https://github.com/brean/python-pathfinding/issues/51
edges = [
[0, 1, 1],
[1, 0, 1],
[1, 2, 1],
[2, 1, 1],
]
graph = Graph(edges=edges, bi_directional=False)
finder = DijkstraFinder()
path, _ = finder.find_path(graph.node(0), graph.node(2), graph)
assert [n.node_id for n in path] == [0, 1, 2]