-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_main.py
393 lines (303 loc) · 12.5 KB
/
test_main.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
from main import Main
from board import SuperCoin
test_maze = [
[1, 1, 1, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0],
[1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 1, 0, 0, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 1, 0, 1, 1, 1]
]
class TestMain:
def setup_method(self):
self.main = Main(test_maze)
self.board = self.main.board
self.pacman = self.main.pacman
self.ghost = self.main.ghost1
def set_pacman_to_position(self, x, y):
""""""
self.pacman.pos_x, self.pacman.pos_z = x, y
def set_ghost_to_position(self, x, y):
""""""
self.ghost.pos_x, self.ghost.pos_z = x, y
def test_outside_board1(self):
""""""
self.pacman.pos_x = -self.pacman.step
self.main.outside_board(self.pacman)
assert self.pacman.pos_x == self.board.maze_row_len-1
def test_outside_board2(self):
""""""
self.pacman.pos_x = 0
self.main.outside_board(self.pacman)
assert self.pacman.pos_x != self.board.maze_row_len-1
def test_outside_board3(self):
""""""
self.pacman.pos_x = self.board.maze_row_len + self.pacman.step
self.main.outside_board(self.pacman)
assert self.pacman.pos_x == 0
def test_outside_board4(self):
""""""
self.pacman.pos_x = self.board.maze_row_len -1
self.main.outside_board(self.pacman)
assert self.pacman.pos_x != 0
def test_outside_board5(self):
""""""
self.pacman.pos_z = -self.pacman.step
self.main.outside_board(self.pacman)
assert self.pacman.pos_z == self.board.maze_len -1
def test_outside_board6(self):
""""""
self.pacman.pos_z = 0
self.main.outside_board(self.pacman)
assert self.pacman.pos_z != self.board.maze_len -1
def test_outside_board7(self):
""""""
self.pacman.pos_z = self.board.maze_len + self.pacman.step
self.main.outside_board(self.pacman)
assert self.pacman.pos_z == 0
def test_outside_board8(self):
""""""
self.pacman.pos_z = self.board.maze_len -1
self.main.outside_board(self.pacman)
assert self.pacman.pos_z != 0
def test_outside_board9(self):
""""""
self.ghost.pos_x = -self.ghost.step
self.main.outside_board(self.ghost)
assert self.ghost.pos_x == self.board.maze_row_len-1
def test_outside_board10(self):
""""""
self.ghost.pos_x = 0
self.main.outside_board(self.ghost)
assert self.ghost.pos_x != self.board.maze_row_len-1
def test_outside_board11(self):
""""""
self.ghost.pos_x = self.board.maze_row_len + self.ghost.step
self.main.outside_board(self.ghost)
assert self.ghost.pos_x == 0
def test_outside_board12(self):
""""""
self.ghost.pos_x = self.board.maze_row_len -1
self.main.outside_board(self.ghost)
assert self.ghost.pos_x != 0
def test_outside_board13(self):
""""""
self.ghost.pos_z = -self.ghost.step
self.main.outside_board(self.ghost)
assert self.ghost.pos_z == self.board.maze_len -1
def test_outside_board14(self):
""""""
self.ghost.pos_z = 0
self.main.outside_board(self.ghost)
assert self.ghost.pos_z != self.board.maze_len -1
def test_outside_board15(self):
""""""
self.ghost.pos_z = self.board.maze_len + self.ghost.step
self.main.outside_board(self.ghost)
assert self.ghost.pos_z == 0
def test_outside_board16(self):
""""""
self.ghost.pos_z = self.board.maze_len -1
self.main.outside_board(self.ghost)
assert self.ghost.pos_z != 0
def test_collision_pacman_coin1(self):
"""No collision with coin."""
self.set_pacman_to_position(1.60, 1)
coin_no = len(self.board.coins)
self.main.collision_pacman_coin(self.board.coins[0])
assert len(self.board.coins) == coin_no
def test_collision_pacman_coin2(self):
"""Collision with coin."""
self.set_pacman_to_position(1.59, 1)
coin_no = len(self.board.coins)
self.main.collision_pacman_coin(self.board.coins[1])
assert len(self.board.coins) == coin_no - 1
def test_collision_pacman_super_coin1(self):
"""No collision with super coin."""
self.set_pacman_to_position(1, 2.25)
self.board.super_coins.append(SuperCoin(1, 3))
super_coin_no = len(self.board.super_coins)
self.main.collision_pacman_coin(self.board.super_coins[-1])
assert len(self.board.super_coins) == super_coin_no
def test_collision_pacman_super_coin2(self):
"""Collision with super coin. One coin less"""
self.set_pacman_to_position(1, 2.26)
self.board.super_coins.append(SuperCoin(1, 3))
super_coin_no = len(self.board.super_coins)
self.main.collision_pacman_coin(self.board.super_coins[-1])
assert len(self.board.super_coins) == super_coin_no - 1
def test_collision_pacman_super_coin3(self):
"""Collision with super coin. Ghosts become eatable"""
self.set_pacman_to_position(1, 2.26)
self.board.super_coins.append(SuperCoin(1, 3))
self.main.collision_pacman_coin(self.board.super_coins[-1])
assert self.ghost.eatable is True
def test_collision_pacman_super_coin4(self):
"""Collision with super coin. Ghosts change color"""
self.set_pacman_to_position(1, 2.26)
self.board.super_coins.append(SuperCoin(1, 3))
self.main.collision_pacman_coin(self.board.super_coins[-1])
assert self.ghost.color == (0.75, 0.75, 0.75)
def test_collision_pacman_super_coin5(self):
"""Collision with super coin. Ghost become again normal after 10 sek"""
self.set_pacman_to_position(1, 2.26)
self.board.super_coins.append(SuperCoin(1, 3))
self.main.collision_pacman_coin(self.board.super_coins[-1])
self.ghost.eatable_time -= 10 # shift in time for 10 sek
self.ghost.become_not_eatable()
assert self.ghost.eatable is False
def test_collision_pacman_super_coin6(self):
"""Collision with super coin. Ghost is normal color after 10 sek"""
self.set_pacman_to_position(1, 2.26)
self.board.super_coins.append(SuperCoin(1, 3))
self.main.collision_pacman_coin(self.board.super_coins[-1])
self.ghost.eatable_time -= 10 # shift in time for 10 sek
self.ghost.become_not_eatable()
assert self.ghost.color == self.ghost.primary_color
def test_collision_pacman_super_coin7(self):
"""Collision with 2 super coins."""
# TODO
def test_collision_pacman_ghost1(self):
"""Collision with eatable ghost"""
self.set_pacman_to_position(1, 1)
self.set_ghost_to_position(1, 1.99)
self.ghost.eatable = True
self.main.collision_pacman_ghost(self.ghost)
assert self.ghost.was_eaten is True
def test_collision_pacman_ghost2(self):
"""No collision with ghost"""
self.set_pacman_to_position(1, 1)
self.set_ghost_to_position(1, 2)
self.ghost.eatable = True
self.main.collision_pacman_ghost(self.ghost)
assert self.ghost.was_eaten is False
def test_collision_pacman_ghost3(self):
"""Collision with no eatable ghost"""
# TODO
def test_pacman_move1(self):
"""PacMan outside knot"""
self.set_pacman_to_position(1, 2)
self.pacman.direction = "W"
self.main.pacman_move()
assert self.pacman.pos_x == 1 - self.pacman.step
def test_pacman_move2(self):
"""PacMan outside knot"""
self.set_pacman_to_position(1, 2)
self.pacman.direction = "E"
self.main.pacman_move()
assert self.pacman.pos_x == 1 + self.pacman.step
def test_pacman_move3(self):
"""PacMan outside knot"""
self.set_pacman_to_position(2, 1)
self.pacman.direction = "N"
self.main.pacman_move()
assert self.pacman.pos_z == 1 - self.pacman.step
def test_pacman_move4(self):
"""PacMan outside knot"""
self.set_pacman_to_position(2, 1)
self.pacman.direction = "S"
self.main.pacman_move()
assert self.pacman.pos_z == 1 + self.pacman.step
def test_pacman_move5(self):
"""PacMan in knot, next_direction in knot direction"""
self.set_pacman_to_position(1, 1)
self.pacman.next_direction = "S"
self.main.pacman_move()
assert self.pacman.pos_z == 1 + self.pacman.step
def test_pacman_move6(self):
"""PacMan in knot, next_direction in knot direction"""
self.set_pacman_to_position(1, 1)
self.pacman.next_direction = "E"
self.main.pacman_move()
assert self.pacman.pos_x == 1 + self.pacman.step
def test_pacman_move7(self):
"""PacMan in knot, next_direction in knot direction"""
self.set_pacman_to_position(1, 1)
self.pacman.next_direction = "E"
self.main.pacman_move()
assert self.pacman.direction == "E"
def test_pacman_move8(self):
"""PacMan in knot, next_direction not in knot direction"""
self.set_pacman_to_position(1, 1)
self.pacman.next_direction = "N"
self.main.pacman_move()
assert self.pacman.pos_z == 1
def test_pacman_move9(self):
"""PacMan in knot, next_direction not in knot direction"""
self.set_pacman_to_position(1, 1)
self.pacman.next_direction = "W"
self.main.pacman_move()
assert self.pacman.pos_x == 1
def test_ghost_move1(self):
"""Ghost outside knot"""
self.set_ghost_to_position(1, 2)
self.ghost.direction = "W"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_x == 1 - self.ghost.step
def test_ghost_move2(self):
"""Ghost outside knot"""
self.set_ghost_to_position(1, 2)
self.ghost.direction = "E"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_x == 1 + self.ghost.step
def test_ghost_move3(self):
"""Ghost outside knot"""
self.set_ghost_to_position(2, 1)
self.ghost.direction = "N"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_z == 1 - self.ghost.step
def test_ghost_move4(self):
"""Ghost outside knot"""
self.set_ghost_to_position(2, 1)
self.ghost.direction = "S"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_z == 1 + self.ghost.step
def test_ghost_move5(self):
"""Ghost in knot, next_direction in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "E"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_x == 1 + self.ghost.step
def test_ghost_move6(self):
"""Ghost in knot, next_direction in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "S"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_z == 1 + self.ghost.step
def test_ghost_move6a(self):
"""Ghost in knot, next_direction in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "S"
self.main.ghost_move(self.ghost)
assert self.ghost.direction == "S"
def test_ghost_move6b(self):
"""Ghost in knot, next_direction in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "S"
self.main.ghost_move(self.ghost)
assert self.ghost.next_direction in "NEW"
def test_ghost_move7(self):
"""Ghost in knot, next_direction not in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "N"
self.main.ghost_move(self.ghost)
assert self.ghost.pos_z == 1
def test_ghost_move8(self):
"""Ghost in knot, next_direction not in knot directions"""
self.set_ghost_to_position(1, 1)
self.ghost.next_direction = "W"
self.main.ghost_move(self.ghost)
assert self.ghost.next_direction in "W"
# TODO check new next direction TEST NIE DZIAŁA PRAWIDŁOWO !!!!
def test_ghost_move9(self):
"""Ghost in knot with one direction."""
# TODO
"""Ghost in knot, direction not in knot directions"""
"""Ghost in knot, direction in knot directions"""
"""Ghost in knot, direction and next_direction not in knot directions
new next direction"""
def test_ghost_move(self):
pass