forked from aimacode/aima-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_grid.py
More file actions
41 lines (25 loc) · 899 Bytes
/
test_grid.py
File metadata and controls
41 lines (25 loc) · 899 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
import pytest
from grid import *
def compare_list(x, y):
return all([elm_x == y[i] for i, elm_x in enumerate(x)])
def test_distance():
assert distance((1, 2), (5, 5)) == 5.0
def test_distance_squared():
assert distance_squared((1, 2), (5, 5)) == 25.0
def test_vector_clip():
assert vector_clip((-1, 10), (0, 0), (9, 9)) == (0, 9)
def test_turn_heading():
assert turn_heading((0, 1), 1) == (-1, 0)
assert turn_heading((0, 1), -1) == (1, 0)
assert turn_heading((1, 0), 1) == (0, 1)
assert turn_heading((1, 0), -1) == (0, -1)
assert turn_heading((0, -1), 1) == (1, 0)
assert turn_heading((0, -1), -1) == (-1, 0)
assert turn_heading((-1, 0), 1) == (0, -1)
assert turn_heading((-1, 0), -1) == (0, 1)
def test_turn_left():
assert turn_left((0, 1)) == (-1, 0)
def test_turn_right():
assert turn_right((0, 1)) == (1, 0)
if __name__ == '__main__':
pytest.main()