-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_maze.py
36 lines (25 loc) · 994 Bytes
/
test_maze.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
from maze import *
from random import randint
if __name__ == '__main__':
maze = Maze(5, 4)
assert(maze.coord(3) == Coord(0, 3))
assert(not maze.is_valid(maze.coord(21)))
assert(maze.is_valid(maze.coord(maze.size() - 1)))
for i in range(10):
r = randint(0, maze.size() - 1)
assert(r == maze.index(maze.coord(r)))
current = Coord(0, 0)
neighbor = Coord(0, 1)
assert(get_direction(current, neighbor) == EAST)
assert(get_direction(neighbor, current) == WEST)
assert((get_direction(current, neighbor) + 2) %
4 == get_direction(neighbor, current))
assert(not maze.has_wall(current, neighbor))
assert(not maze.has_wall(neighbor, current))
maze.add_wall(current, 2)
assert(maze.has_wall(current, neighbor))
assert(maze.has_wall(neighbor, current))
maze.remove_wall(current, 2)
assert(not maze.has_wall(current, neighbor))
assert(not maze.has_wall(neighbor, current))
print(maze.encode())