-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
187 lines (146 loc) · 5.95 KB
/
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
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
#!/bin/env python3
import unittest
from src.game import Game
from src.player_control import PlayerControl
from src.player_instance import PlayerInstance
from src.box_container import BoxContainer
import src.exceptions as exceptions
class TestBoxContainer(unittest.TestCase):
def testBoxContainer(self):
bc=BoxContainer(5, 5)
bc.insert(1,2,1)
bc.insert(1,3,1)
bc.insert(1,3,2)
bc.insert(2,2,1)
bc.remove(1,2)
bc.remove(2,2)
self.assertRaises(exceptions.OutOfRangeError, bc.insert, 6,6,1)
self.assertEqual(list(bc), [(1,3,2)])
self.assertEqual(bc.get(2,2), None)
self.assertEqual(bc.get(1,3), 2)
bc.clear()
self.assertEqual(list(bc), [])
class TestGame(unittest.TestCase):
def testInterface(self):
testing=Game("arenas/testing", "arenas/testing_out")
self.assertEqual(testing.get_iteration(), 1)
self.assertEqual(testing.no_iterations(), 10)
self.assertEqual(testing.get_timeout(), 2)
self.assertEqual(testing.no_players(), 2)
boxes=[(0,0, -1),
(1,2, -1),
(3,3, 0),
(2,0, 1),
(0,3, 2)]
for x,y,val in boxes:
self.assertEqual(testing.get_square(x, y), val)
# |# xx| |# x |
# | x | --> | xx|
# | # #| --> | # #|
# |ooo | |ooo |
testing.move(2, 0, 2, 1)
testing.move(2, 1, 2, 2)
testing.move(3, 0, 3, 1)
testing.move(2, 3, 2, 2)
testing.move(0, 3, 1, 3)
testing.next_iteration()
boxes=[(0,0, -1),
(1,2, -1),
(3,3, 0),
(2,0, 1),
(2,1, 1),
(0,3, 2)]
for x,y,val in boxes:
self.assertEqual(testing.get_square(x, y), val)
self.assertEqual(testing.get_iteration(), 2)
walls=testing.get_walls()
self.assertEqual(walls.get(3,0), None)
self.assertEqual(walls.get(3,2), -1)
ants=testing.get_ants()
self.assertEqual(ants.get(2,0), 1)
self.assertEqual(ants.get(0,3), 2)
self.assertEqual(ants.get(3,0), None)
last_moves=testing.last_moves()
self.assertEqual(last_moves.get(3,0), (3,1,1))
self.assertEqual(last_moves.get(2,2), None)
self.assertEqual(last_moves.get(0,3), None)
def testCyclest(self):
# not moving cycle
testing=Game("arenas/testing_cycle", "arenas/testing_cycle_out")
testing.move(0, 0, 1, 0)
testing.move(1, 0, 1, 1)
testing.move(1, 1, 0, 1)
testing.move(0, 1, 0, 0)
testing.next_iteration()
self.assertEqual(testing.get_square(0, 0), 1)
self.assertEqual(testing.get_square(1, 1), 1)
self.assertEqual(testing.get_square(1, 0), 2)
self.assertEqual(testing.get_square(0, 1), 2)
# not moving cycle with additional "branches"
testing=Game("arenas/testing_cycle", "arenas/testing_cycle_out2")
testing.move(0, 0, 1, 0)
testing.move(1, 0, 1, 1)
testing.move(1, 1, 0, 1)
testing.move(0, 1, 0, 0)
testing.move(2, 0, 1, 0)
testing.move(2, 1, 2, 0)
testing.next_iteration()
self.assertEqual(testing.get_square(0, 0), 1)
self.assertEqual(testing.get_square(1, 1), 1)
self.assertEqual(testing.get_square(1, 0), 2)
self.assertEqual(testing.get_square(0, 1), 2)
self.assertEqual(testing.get_square(2, 0), 1)
self.assertEqual(testing.get_square(2, 1), 1)
def testKill(self):
testing=Game("arenas/testing_kills", "arenas/testing_kills_out")
testing.next_iteration()
self.assertEqual(list(testing.last_kills()), [(1, 0, 2)])
self.assertEqual(testing.get_square(1, 0), 0)
class TestPlayer(unittest.TestCase):
def testInterface(self):
testing=Game("arenas/testing", "arenas/testing_out")
self.assertEqual(testing.get_players()[0][2]._pc.get_iteration(), 1)
self.assertEqual(testing.get_players()[0][2]._pc.no_iterations(), 10)
self.assertEqual(testing.get_players()[0][2]._pc.get_timeout(), 2)
self.assertEqual(testing.get_players()[0][2]._pc.no_players(), 2)
boxes=[(0,0, -1),
(1,2, -1),
(3,3, 0),
(2,0, 1),
(0,3, 2)]
for x,y,val in boxes:
self.assertEqual(testing.get_players()[0][2]._pc.get_square(x, y), val)
# |# xx| |# x |
# | x | --> | xx|
# | # #| --> | # #|
# |ooo | |ooo |
testing.get_players()[0][2]._pc.move(2, 0, 2, 1)
testing.get_players()[0][2]._pc.move(2, 1, 2, 2)
testing.get_players()[0][2]._pc.move(3, 0, 3, 1)
testing.get_players()[1][2]._pc.move(2, 3, 2, 2)
testing.get_players()[0][2]._pc.move(0, 3, 0, 2) # trying to move enemious ant
testing.next_iteration()
boxes=[(0,0, -1),
(1,2, -1),
(3,3, 0),
(2,0, 1),
(2,1, 1),
(0,3, 2)]
for x,y,val in boxes:
self.assertEqual(testing.get_players()[0][2]._pc.get_square(x, y), val)
self.assertEqual(testing.get_players()[0][2]._pc.get_iteration(), 2)
walls=testing.get_players()[0][2]._pc.get_walls()
self.assertEqual(walls.get(3,0), None)
self.assertEqual(walls.get(3,2), -1)
self.assertEqual(walls.get(2,2), None)
ants=testing.get_players()[0][2]._pc.get_ants()
self.assertEqual(ants.get(2,0), 1)
self.assertEqual(ants.get(0,3), 2)
self.assertEqual(ants.get(3,2), None)
last_moves=testing.get_players()[0][2]._pc.last_moves()
self.assertEqual(last_moves.get(3,0), (3,1,1))
self.assertEqual(last_moves.get(0,0), None)
self.assertEqual(last_moves.get(1,0), None)
self.assertEqual(last_moves.get(2,0), None)
if __name__ == '__main__':
unittest.main()