-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.py
executable file
·145 lines (106 loc) · 5.59 KB
/
unit_test.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
'''@authors Simone Orsi (305461) and Martina Gualtieri (308783)'''
import unittest, constants
from assets import Background, Rover, Hole, Rock, Bullet, Ufo, Cannon
from actor import Arena
class BackgroundTest(unittest.TestCase):
def setUp(self):
self._arena = Arena((constants.ARENA_WIDTH, constants.ARENA_HEIGHT))
self._background_values = (((50, 0), 1, constants.MOUNTAINS),
((470, 150), 2, constants.HILLS),
((50, 247), 4, constants.GROUND),
((150, 150), 2, constants.CITY))
def test_symbol(self):
for param in self._background_values:
pos, speed, player = param
with self.subTest(param=param):
background = Background(self._arena, pos, speed, player)
background.move()
if background.setting() == constants.MOUNTAINS:
self.assertTrue(background.symbol() == (0, 50, 512, 210))
elif background.setting() == constants.HILLS:
self.assertTrue(background.symbol() == (0, 256, 512, 126))
elif background.setting() == constants.CITY:
self.assertTrue(background.symbol() == (0, 384, 512, 70))
elif background.setting() == constants.GROUND:
self.assertTrue(background.symbol() == (0, 512, 512, 15 ))
def test_collision(self):
bullet = Bullet(self._arena, (50, 245), constants.BULLET_DOWN)
for param in self._background_values:
pos, speed, player = param
with self.subTest(param=param):
background = Background(self._arena, pos, speed, player)
background.move()
if background.setting() == constants.GROUND:
self.assertTrue(self._arena.check_collision(background, bullet))
class RoverTest(unittest.TestCase):
def setUp(self):
self._arena = Arena((constants.ARENA_WIDTH, constants.ARENA_HEIGHT))
self._rover_values = (((40, 250), 2.3, constants.PLAYER_2),
((60, 230), 2.3, constants.PLAYER_1),
((50, 200), 2.3, constants.PLAYER_1),
((100, 247), 2.3, constants.PLAYER_1))
def test_jump(self):
for param in self._rover_values:
pos, speed, player = param
with self.subTest(param=param):
rover = Rover(self._arena, pos, speed, player)
rover.jump()
rover.move()
new_pos = rover.position()[0], rover.position()[1]
self.assertTrue(new_pos[1] <= pos[1])
def test_symbol(self):
for param in self._rover_values:
pos, speed, player = param
with self.subTest(param=param):
rover = Rover(self._arena, pos, speed, player)
rover.move()
rover.jump()
new_pos = rover.position()[0], rover.position()[1]
if new_pos[1] <= pos[1] and new_pos[1] != pos[1]:
if rover.player() == constants.PLAYER_1:
self.assertTrue(rover.symbol() == (47, 103, 27, 27))
else:
self.assertTrue(rover.symbol() == (49, 152, 27, 27))
else:
if rover.player() == constants.PLAYER_1:
self.assertTrue(rover.symbol() == (212, 158, 32, 23))
else:
self.assertTrue(rover.symbol() == (248, 158, 32, 23))
class HoleTest(unittest.TestCase):
def setUp(self):
self._arena = Arena((constants.ARENA_WIDTH, constants.ARENA_HEIGHT))
self._hole = Hole(self._arena, (60, 247), False, constants.SMALL_SIZE)
def test_collision(self):
rover = Rover(self._arena, (65, 247), 2.3, constants.PLAYER_1)
self._hole.move()
self.assertTrue(self._arena.check_collision(self._hole, rover))
class RockTest(unittest.TestCase):
def setUp(self):
self._arena = Arena((constants.ARENA_WIDTH, constants.ARENA_HEIGHT))
self._rock = Rock(self._arena, (150, 236), constants.BIG_SIZE)
def test_collision(self):
bullet = Bullet(self._arena, (152, 247), constants.BULLET_RIGHT)
self._rock.move()
self.assertTrue(self._arena.check_collision(self._rock, bullet))
def test_position(self):
cannon = Cannon(self._arena, (200, 247))
cannon_pos = cannon.position()[0], cannon.position()[1]
self._rock.check_position()
rock_pos = self._rock.position()[0], self._rock.position()[1]
self.assertTrue(rock_pos[0] + constants.MIN_DISTANCE > cannon_pos[0])
class UfoTest(unittest.TestCase):
def setUp(self):
self._arena = Arena((constants.ARENA_WIDTH, constants.ARENA_HEIGHT))
self._ufo = Ufo(self._arena, (100, 50), 4, constants.BONUS_UFO)
def test_collision(self):
bullet = Bullet(self._arena, (105, 55), constants.BULLET_UP)
self._ufo.move()
self.assertTrue(self._arena.check_collision(self._ufo, bullet))
def test_symbol(self):
self._ufo.move()
if self._ufo.get_rotate():
self.assertTrue(self._ufo.symbol() == (104, 226, 13, 16))
else:
self.assertTrue(self._ufo.symbol() == (88, 227, 14, 14))
if __name__ == '__main__':
unittest.main()