-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarvation_tests.py
42 lines (37 loc) · 1.45 KB
/
starvation_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
import unittest
from starvation import Forager
class TestForager(unittest.TestCase):
def setUp(self):
self.person = Forager(0, 0, 1, 0)
def test_is_starving(self):
self.assertFalse(self.person.is_starving())
self.person.days_without_food = 4
self.assertTrue(self.person.is_starving())
def test_eat(self):
# Starts Fed and zero days w/o food.
self.assertTrue(self.person.fed)
self.assertEqual(self.person.days_without_food, 0)
# Eat with no food
self.person.eat()
self.assertFalse(self.person.fed)
self.assertEqual(self.person.days_without_food, 1)
# Add a day and a half of food.
self.person.food = 1.5
self.person.eat()
self.assertTrue(self.person.fed)
self.assertEqual(self.person.days_without_food, 0)
# Eat with half rations.
self.person.eat()
self.assertTrue(self.person.fed)
self.assertEqual(self.person.days_without_food, 0.5)
# Eat again
self.person.eat()
self.assertFalse(self.person.fed)
self.assertEqual(self.person.days_without_food, 1.5)
def test_sleep(self):
self.assertEqual(self.person.exhaustion_level, 0)
self.assertTrue(self.person.fed)
self.person.sleep()
self.assertEqual(self.person.exhaustion_level, 0)
self.assertFalse(self.person.fed)
self.person.sleep()