forked from gabits/zoo_exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
56 lines (43 loc) · 1.81 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
from zoo import (Zoo, Cage, Mouse, WildCat, Lion)
from unittest import TestCase, main
class UserStory(TestCase):
def test_requirements(self):
""" Creates zoo and cages: """
zoo = Zoo()
cage_1 = Cage()
cage_2 = Cage()
""" Creation of animals: """
mouse = Mouse()
wildcat = WildCat()
lion = Lion()
""" Attempt to add objects that are not cages to a zoo """
zoo.add_cages([mouse])
self.assertFalse(zoo.cages, [mouse])
""" Tests zoo with empty cages """
self.assertEqual(cage_1.n_of_animals(), 0)
zoo.add_cages([cage_1, cage_2])
self.assertEqual(zoo.cages, [cage_1, cage_2])
""" Multiple addition of animals among repeated ones """
cage_1.add_animals([mouse, mouse, lion, lion, mouse])
# Set up to test more than one duplicated animal and different orders
self.assertEqual(cage_1.animals_list, [mouse, lion])
""" Tests zoo attributes """
zoo.cages = []
zoo.add_cages([cage_1, cage_2])
self.assertEqual(zoo.cages, [cage_1, cage_2])
self.assertEqual(zoo.n_of_cages(), 2)
self.assertEqual(zoo.n_of_animals(), 2)
""" Tests competition between prey and predator """
cage_2.add_animals([mouse, wildcat, lion])
self.assertEqual(cage_2.animals_list, [lion])
""" Tests if animal already in another cage """
# ----- Should I do it?
""" Attempt to add objects that are not animals to a cage """
cage_1.animals_list = []
cage_1.add_animals([zoo])
self.assertFalse(cage_1.animals_list, [zoo])
""" Only if file is primarily called on Python (executed by its name)
the main() function will be called and tests will be initiated.
"""
if __name__ == '__main__':
main()