-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
83 lines (65 loc) · 2.62 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
import agentframework as af
import matplotlib.pyplot as plt
import unittest
# Test environment import
environment = af.import_environment()
# plt.imshow(environment)
# plt.show()
# create agents to test
agents = []
a = af.Agent(environment, agents, init_coords=[0,300],sex='m')
b = af.Agent(environment, agents, init_coords=[0,2],sex='f')
c = af.Agent(environment, agents, init_coords=[2,0],sex='f')
agents.extend([a,b,c])
# Test basic attributes of agents
class TestAgent(unittest.TestCase):
def test_get(self):
self.assertEqual(0,a.get_x())
self.assertEqual(300,a.get_y())
self.assertEqual(0,a.get_store())
self.assertEqual(0,a.get_pregnancy())
self.assertEqual(0,a.get_age())
self.assertEqual('m',a.get_sex())
def test_set(self):
a.set_x(50)
a.set_y(60)
a.set_store(20)
a.set_pregnancy(10)
a.set_age(30)
#Note: a.set_sex() is not an option
def test_get_post_set(self):
TestAgent.test_set(TestAgent)
self.assertEqual(50,a.get_x())
self.assertEqual(60,a.get_y())
self.assertEqual(20,a.get_store())
self.assertEqual(10,a.get_pregnancy())
self.assertEqual(30,a.get_age())
self.assertEqual('m',a.get_sex())
def test_is_dead(self):
a.set_age(10)
self.assertFalse(a.is_dead(max_age=20))
self.assertTrue(a.is_dead(max_age=5))
def test_increment_age(self):
a.set_age(1)
a.increment_age()
self.assertEqual(2,a.get_age())
def test_perturb(self):
for _ in range(100):
# test the mod300 and that is is perturbed
self.assertLess(af.perturb(300),300)
self.assertGreater(af.perturb(0),0)
def test_distance_to(self):
self.assertEqual(298,a.distance_to(b))
self.assertEqual(8**0.5,b.distance_to(c))
###### Other tests that were performed:
# 1. Made sure that slider values are passed into the run function in model.py
# 2. Fixed frame number edge cases to make sure first frame was spawn, then move
# and eat and mate were in the correct order
# 3. Whether there was need for randomisation of the agents list (as this was causing
# drawing flickers) - answer is no
# 4. Made sure 'optimised movement' did not get stuck by addin random movement if this happens
# 5. Type and value checking was added to the main python scripts and mistakes will be caught by them
# 6. move, eat, and mate were checked against their behaviours in the simulation
# to run the tests without extra text from command line
if __name__ == '__main__':
unittest.main()