forked from AndreevP/FSE_LabW6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
57 lines (48 loc) · 2.19 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
import unittest
import random
from runtime_utils import create_persons
from person import *
def get_random_virus():
return get_infectable(InfectableType(random.randint(1, 3)))
def get_random_state():
return random.choice([Healthy, Dead, AsymptomaticSick, SymptomaticSick])
class ContactingTestCase(unittest.TestCase):
def setUp(self):
min_i, max_i = 0, 100 #this numbers can be arbitrary
min_j, max_j = 0, 100
n_persons = 3000
self.persons = create_persons(min_j, max_j, min_i, max_i, n_persons)
for person in self.persons:
state = get_random_state()
if (state != Healthy):
person.virus = get_random_virus()
person.set_state(state(person))
elif (random.random() > 0.5): #a half of healthy people have antibodies
person.antibody_types.add(type(get_random_virus()))
def tearDown(self):
pass
def test_transmition(self):
for p1 in self.persons:
for p2 in self.persons:
if (p1 is not p2) and (type(p2.state) == Healthy) and \
(type(p1.state) in [AsymptomaticSick, SymptomaticSick]) and \
(type(p1.virus) not in p2.antibody_types):
p1.interact(p2)
self.assertEqual(type(p2.state), AsymptomaticSick)
self.assertEqual(type(p1.virus), type(p2.virus))
def test_healthy_interaction(self):
for p1 in self.persons:
for p2 in self.persons:
if (p1 is not p2) and (type(p2.state) == Healthy) and (type(p1.state) == Healthy):
p1.interact(p2)
self.assertEqual(type(p1.state), Healthy)
self.assertEqual(type(p2.state), Healthy)
def test_antibodies(self):
for p1 in self.persons:
for p2 in self.persons:
if (p1 is not p2) and (type(p1.virus) in p2.antibody_types):
t = type(p2.state)
p1.interact(p2)
self.assertEqual(type(p2.state), t)
if __name__ == '__main__':
unittest.main()