forked from BattlesnakeOfficial/starter-snake-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_a_star.py
More file actions
55 lines (47 loc) · 972 Bytes
/
test_a_star.py
File metadata and controls
55 lines (47 loc) · 972 Bytes
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
import unittest
from util import merge_dict, default_data
from board import Board
from a_star import a_star
class TestAStar(unittest.TestCase):
def test_safe_neighbor(self):
board = Board(default_data())
start = (0, 0)
goal = (1, 0)
"""
| | | |
| | | |
|S|G| |
"""
path = a_star(board, start, goal)
self.assertEqual(path, [start, goal])
def test_navigate_around_obstacle(self):
test_data = default_data()
merge_dict(test_data, {
"board": {
"snakes": [{
"id": "them",
"health": 100,
"body": [(1, 0), (1, 1)]
}]
}
})
board = Board(test_data)
start = (0, 0)
goal = (2, 0)
"""
| | | |
| |█| |
|S|█|G|
"""
path = a_star(board, start, goal)
self.assertEqual(path, [
start,
(0, 1),
(0, 2),
(1, 2),
(2, 2),
(2, 1),
goal
])
if __name__ == '__main__':
unittest.main()