-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
96 lines (72 loc) · 2.89 KB
/
tests.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
"""
Starter Unit Tests using the built-in Python unittest library.
See https://docs.python.org/3/library/unittest.html
You can expand these to cover more cases!
To run the unit tests, use the following command in your terminal,
in the folder where this file exists:
python tests.py -v
"""
import unittest
from server_logic import avoid_my_neck
class AvoidNeckTest(unittest.TestCase):
def test_avoid_neck_all(self):
"""
The possible move set should be all moves.
In the starter position, a Battlesnake body is 'stacked' in a
single place, and thus all directions are valid.
"""
# Arrange
test_head = {"x": 5, "y": 5}
test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 5}, {"x": 5, "y": 5}]
possible_moves = ["up", "down", "left", "right"]
# Act
result_moves = avoid_my_neck(test_head, test_body, possible_moves)
# Assert
self.assertEqual(len(result_moves), 4)
self.assertEqual(possible_moves, result_moves)
def test_avoid_neck_left(self):
# Arrange
test_head = {"x": 5, "y": 5}
test_body = [{"x": 5, "y": 5}, {"x": 4, "y": 5}, {"x": 3, "y": 5}]
possible_moves = ["up", "down", "left", "right"]
expected = ["up", "down", "right"]
# Act
result_moves = avoid_my_neck(test_head, test_body, possible_moves)
# Assert
self.assertEqual(len(result_moves), 3)
self.assertEqual(expected, result_moves)
def test_avoid_neck_right(self):
# Arrange
test_head = {"x": 5, "y": 5}
test_body = [{"x": 5, "y": 5}, {"x": 6, "y": 5}, {"x": 7, "y": 5}]
possible_moves = ["up", "down", "left", "right"]
expected = ["up", "down", "left"]
# Act
result_moves = avoid_my_neck(test_head, test_body, possible_moves)
# Assert
self.assertEqual(len(result_moves), 3)
self.assertEqual(expected, result_moves)
def test_avoid_neck_up(self):
# Arrange
test_head = {"x": 5, "y": 5}
test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 6}, {"x": 5, "y": 7}]
possible_moves = ["up", "down", "left", "right"]
expected = ["down", "left", "right"]
# Act
result_moves = avoid_my_neck(test_head, test_body, possible_moves)
# Assert
self.assertEqual(len(result_moves), 3)
self.assertEqual(expected, result_moves)
def test_avoid_neck_down(self):
# Arrange
test_head = {"x": 5, "y": 5}
test_body = [{"x": 5, "y": 5}, {"x": 5, "y": 4}, {"x": 5, "y": 3}]
possible_moves = ["up", "down", "left", "right"]
expected = ["up", "left", "right"]
# Act
result_moves = avoid_my_neck(test_head, test_body, possible_moves)
# Assert
self.assertEqual(len(result_moves), 3)
self.assertEqual(expected, result_moves)
if __name__ == "__main__":
unittest.main()