-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathtest_dynamic_maze_solver.py
More file actions
65 lines (45 loc) · 1.19 KB
/
test_dynamic_maze_solver.py
File metadata and controls
65 lines (45 loc) · 1.19 KB
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
57
58
59
60
61
62
63
64
65
import conftest
from PathPlanning.DynamicMazeSolver import dynamic_maze_solver as m
def test_bfs_finds_path():
# small maze: 0=open, 1=wall
maze = [
[0, 0, 0],
[1, 1, 0],
[0, 0, 0]
]
start = (0, 0)
target = (2, 2)
# module `dynamic_maze_solver` exposes `MazeVisualizer` class
viz = m.MazeVisualizer(maze, start, target)
path, visited = viz._bfs()
assert path is not None
assert path[0] == start
assert path[-1] == target
def test_bfs_unreachable_target():
# target is enclosed by walls
maze = [
[0, 1, 0],
[1, 1, 1],
[0, 1, 0]
]
start = (0, 0)
target = (2, 2)
viz = m.MazeVisualizer(maze, start, target)
path, visited = viz._bfs()
assert path is None
assert target not in visited
def test_bfs_start_equals_target():
# trivial case where start == target
maze = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
start = (1, 1)
target = start
viz = m.MazeVisualizer(maze, start, target)
path, visited = viz._bfs()
assert path is not None
assert path == [start]
if __name__ == '__main__':
conftest.run_this_test(__file__)