-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project.py
More file actions
107 lines (79 loc) · 2.7 KB
/
test_project.py
File metadata and controls
107 lines (79 loc) · 2.7 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import project
from project import is_on_square, change_cell_to_wall_or_to_empty, reset_grid
def main():
test_is_on_square()
test_change_cell_to_wall_or_to_empty()
test_reset_grid()
def test_is_on_square():
# if location is on first square, return first square
assert (
is_on_square(
project.GRID_ORIGIN[0] + project.GRID_CELL_DIMENSIONS / 2,
project.GRID_ORIGIN[1] + project.GRID_CELL_DIMENSIONS / 2,
)
== project.grid[0][0]
)
# if location is on last square, return last square
assert (
is_on_square(
project.GRID_ORIGIN[0]
+ project.GRID_SIZE_X * project.GRID_CELL_DIMENSIONS
- project.GRID_CELL_DIMENSIONS / 2,
project.GRID_ORIGIN[1]
+ project.GRID_SIZE_Y * project.GRID_CELL_DIMENSIONS
- project.GRID_CELL_DIMENSIONS / 2,
)
== project.grid[-1][-1]
)
def test_change_cell_to_wall_or_to_empty():
# create an empty cell
cell = project.Cell(0, 0)
# make sure that the cell is empty
assert not cell.is_wall
# convert cell to wall
change_cell_to_wall_or_to_empty(cell, cell.is_wall)
# checks if hte cell was changed to wall
assert cell.is_wall
# change cell back to empty
change_cell_to_wall_or_to_empty(cell, cell.is_wall)
# checks of the cell was changed to a wall
assert not cell.is_wall
def test_reset_grid():
# creates a 3x3 test grid
grid = []
for y in range(3):
grid.append([])
for x in range(3):
grid[y].append(project.Cell(x, y))
# sets first cell as start
grid[0][0].make_start()
# sets last grid as end
grid[-1][-1].make_end()
# makes some cells walls:
# first row, last cell
grid[0][-1].make_wall()
# middle row, middle cell
grid[1][1].make_wall()
# make a cells seen
grid[1][0].make_seen()
# makes a cell solution
grid[2][0].make_solution()
# calls reset grid function
reset_grid(grid)
# checks that the start is still a start
assert grid[0][0].is_start
# checks that the last cell is still an end cell
assert grid[-1][-1].is_end
# checks that all wall cells are still walls
# first row, last cell
assert grid[0][-1].is_wall
# middle row, middle cell
assert grid[1][1].is_wall
# checks that en empty cells remains empty
assert not grid[0][1].is_wall
# checks that a seen cell is now empty
assert not grid[1][0].is_wall
# checks that a solution cell is not empty
assert not grid[2][0].is_wall
if __name__ == "__main__":
main()