forked from BattlesnakeOfficial/starter-snake-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util.py
More file actions
78 lines (72 loc) · 1.67 KB
/
test_util.py
File metadata and controls
78 lines (72 loc) · 1.67 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
import unittest
from util import to_tuple, to_tuples, tuplify, tuplify_snake
class TestUtil(unittest.TestCase):
def test_to_tuple(self):
self.assertEqual((1, 2), to_tuple({"x": 1, "y": 2}))
def test_to_tuples(self):
expected = [(1, 2), (3, 4)]
actual = to_tuples([{"x": 1, "y": 2}, {"x": 3, "y": 4}])
self.assertEqual(expected, actual)
def test_tuplify_snake(self):
actual = tuplify_snake({
"id": "123",
"head": {"x": 1, "y": 2},
"body": [
{"x": 1, "y": 2},
{"x": 3, "y": 4}
]
})
expected = {
"id": "123",
"head": (1, 2),
"body": [(1, 2),(3, 4)]
}
self.assertEqual(expected, actual)
def test_tuplify(self):
actual = tuplify({
"game": {},
"board": {
"width": 5,
"height": 5,
"snakes": [{
"id": "123",
"head": {"x": 1, "y": 2},
"body": [
{"x": 1, "y": 2},
{"x": 3, "y": 4}
]
}],
"food": [{"x": 1, "y": 2}],
"hazards": [{"x": 1, "y": 2}]
},
"you": {
"id": "123",
"head": {"x": 1, "y": 2},
"body": [
{"x": 1, "y": 2},
{"x": 3, "y": 4}
]
}
})
expected = {
"game": {},
"board": {
"width": 5,
"height": 5,
"snakes": [{
"id": "123",
"head": (1, 2),
"body": [(1, 2), (3, 4)]
}],
"food": [(1, 2)],
"hazards": [(1, 2)]
},
"you": {
"id": "123",
"head": (1, 2),
"body": [(1, 2), (3, 4)]
}
}
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()