-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bird.py
More file actions
98 lines (81 loc) · 2.49 KB
/
test_bird.py
File metadata and controls
98 lines (81 loc) · 2.49 KB
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
import agressionSimulation as sim
# Testing bird creation
bird1 = sim.bird()
bird1.setBirdChars("H", "M", 100, 200, 10)
bird2 = sim.bird()
bird2.setBirdChars('H', "F", 100, 200, 10)
# Check basic setters
assert bird1.isHawk() == True
assert bird1.isDove() == False
assert bird1.isMale() == True
assert bird2.isMale() == False
assert bird1.isFemale() == False
assert bird2.isFemale() == True
# Check addCalories function
# Try passing in incoorect type for addCalories
try:
bird1.addCalories(None)
raise AssertionError("Failed adding None calories to bird")
except ValueError as ex:
pass
# Try passing in incoorect TYpe for addCalories
try:
bird1.addCalories(-1)
raise AssertionError("Failed adding negative calories to bird")
except ValueError as ex:
pass
# Pass in proper values and check for caloric limit cdcd
bird1.addCalories(100)
assert bird1.calories == 200
bird1.addCalories(100)
assert bird1.calories == 200
# Check agression function
# Try passing in incorrect types
# TODO: redo these tests
try:
bird1.aggresion(1, 1)
raise AssertionError("Failed agression function with incorrect bird type")
except TypeError as ex:
pass
# Try passing in None calories
try:
bird1.aggresion(bird2, None)
raise AssertionError("Failed agression function with None calories")
except ValueError as ex:
pass
# Try passing in negative calories
try:
bird1.aggresion(bird2, -1)
raise AssertionError("Failed agression function with negative calories")
except ValueError as ex:
pass
# Try passing in correct values
bird1.calories = 100
bird1.aggresion(bird2, 100)
assert bird1.calories + bird2.calories == 300
bird1.calories = 100
bird1.aggresion(None, 100)
assert bird1.calories == 200
# Check procreate function
# Try passing in incorrect types
try:
bird1.procreate(1)
raise AssertionError("Failed procreate function with incorrect bird type")
except TypeError as ex:
pass
# Try passing in a dead pird
bird3 = sim.bird()
bird3.alive == False
assert bird1.procreate(bird3) == []
# Try passing in a bird of the same gender
bird3.alive = True
bird3.gender = bird1.gender
assert bird1.procreate(bird3) == []
# Try passing in a bird of a different species
bird3.gender = 'F'
bird3.species = "D"
assert bird1.procreate(bird1) == []
# Try passing in a bird with all the correct characteristics
assert len(bird1.procreate(bird2)) == 1
assert bird1.procreate(None) == []
print("All bird tests passed successfully!")