-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
116 lines (92 loc) · 2.72 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from spatial_learning import Room, World, Experiment
"""Tests for Room"""
def test_room_init():
r1 = Room(1, 1)
r2 = Room(1, 2)
def test_is_left_of():
r1 = Room(1, 1)
r2 = Room(2, 2)
assert r1.is_left_of(r2)
assert not r2.is_left_of(r1)
def test_is_right_of():
r1 = Room(2, 2)
r2 = Room(1, 1)
assert r1.is_right_of(r2)
assert not r2.is_right_of(r1)
def test_is_in_front_of():
r1 = Room(1, 1)
r2 = Room(2, 2)
assert r1.is_in_front_of(r2)
assert not r2.is_in_front_of(r1)
def test_is_in_back_of():
r1 = Room(2, 2)
r2 = Room(1, 1)
assert r1.is_in_back_of(r2)
assert not r2.is_in_back_of(r1)
"""Tests for World"""
def test_world_init():
w1 = World()
assert len(w1.animals) == 0
animals = ['dog', 'cat']
w2 = World(animals)
assert len(w2.animals) == 2
assert w2.animals['dog'] is None
assert w2.animals['cat'] is None
def test_set_position():
w1 = World()
w1.set_position('dog', 1, 1)
assert w1.animals['dog'].x == 1
assert w1.animals['dog'].y == 1
try:
w1.set_position('dog', 0, 0)
except Exception as e:
assert type(e) is ValueError
w2 = World(['dog'])
w2.set_position('dog', 1, 1)
assert w2.animals['dog'].x == 1
assert w2.animals['dog'].y == 1
w2.set_position('cat', 0, 0)
assert w2.animals['cat'].x == 0
assert w2.animals['cat'].y == 0
def test_test_constraint():
animals = ['dog', 'cat']
w1 = World(animals)
c1 = ('dog', 'left of', 'cat')
c2 = ('cat', 'right of', 'dog')
c3 = ('dog', 'in front of', 'cat')
c4 = ('cat', 'in back of', 'dog')
w1.set_position('dog', 1, 1)
w1.set_position('cat', 2, 2)
assert w1.test_constraint(c1)
assert w1.test_constraint(c2)
assert w1.test_constraint(c3)
assert w1.test_constraint(c4)
def test_copy():
w1 = World(['dog'])
w1.set_position('dog', 1, 1)
w2 = w1.copy()
assert w1 is not w2 #not the same object
assert str(w1) == str(w2) #but identical contents
"""Tests for Experiment"""
def test_experiment_init():
animals = ['dog', 'cat']
constraints = [('dog', 'left of', 'cat')]
exp = Experiment(animals, constraints)
assert exp.animals == animals
assert exp.constraints == constraints
def test_add_animal():
exp = Experiment()
exp.add_animal('dog')
exp.add_animal('cat')
assert exp.animals == ['dog', 'cat']
exp.add_animal('frog')
exp.add_animal('cat')
assert exp.animals == ['dog', 'cat', 'frog']
def test_add_constraint():
c1 = ('dog', 'in front of', 'frog')
exp = Experiment(['dog'])
exp.add_constraint(c1)
assert exp.animals == ['dog', 'frog']
assert exp.constraints == [c1]
def test_update():
return None