forked from ironhack-labs/mini-project-vikings-en
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-testsWar.py
130 lines (95 loc) · 4.15 KB
/
4-testsWar.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import unittest
from vikingsClasses import War, Viking, Saxon
from inspect import signature
class TestWar(unittest.TestCase):
@classmethod
def setUp(cls):
cls.war = War()
def testWarShouldReciveNoParams(self):
self.assertEqual(len(signature(War).parameters), 0)
def testVikingArmy(self):
self.assertEqual(self.war.vikingArmy, [])
def testSaxonArmy(self):
self.assertEqual(self.war.saxonArmy, [])
class TestWar2(unittest.TestCase):
@classmethod
def setUp(cls):
def generateViking():
cls.name = 'Harald'
cls.strength = 150
cls.health = 300
return Viking(cls.name, cls.health, cls.strength)
def generateSaxon():
cls.health = 60
cls.strength = 25
return Saxon(cls.health, cls.strength)
cls.viking = generateViking()
cls.saxon = generateSaxon()
cls.war = War()
cls.war.addSaxon(cls.saxon)
cls.war.addViking(cls.viking)
def testAddViking(self):
self.assertEqual(callable(self.war.addViking), True)
def testAddVikingShouldReceiveOneParam(self):
self.assertEqual(len(signature(self.war.addViking).parameters), 1)
def testAddVikingInList(self):
self.assertEqual(self.war.vikingArmy, [self.viking])
def testAddVikingReturnNull(self):
self.assertEqual(self.war.addViking(self.viking), None)
def testAddSaxonShouldBeFunction(self):
self.assertEqual(callable(self.war.addSaxon), True)
def testAddSaxonReceiveOneParam(self):
self.assertEqual(len(signature(self.war.addSaxon).parameters), 1)
def testSaxonArmyReturnEmptyList(self):
self.assertEqual(self.war.saxonArmy, [self.saxon])
def testAddSaxonReturnNone(self):
self.assertEqual(self.war.addSaxon(self.saxon), None)
def testVikingAttackIsFunction(self):
self.assertEqual(callable(self.war.vikingAttack), True)
def testVikingAttackReceiveNoParam(self):
self.assertEqual(len(signature(self.war.vikingAttack).parameters), 0)
def testSaxonHealth(self):
oldHealt = self.saxon.health
self.war.vikingAttack()
self.assertEqual(self.saxon.health, oldHealt - self.viking.strength)
def testVikingAttack(self):
self.war.vikingAttack()
self.assertEqual(len(self.war.saxonArmy), 0)
def testAddSaxon(self):
print(self.war.__dict__)
self.assertEqual(self.war.vikingAttack(), 'A Saxon has died in combat')
def testSaxonAttackIsFunction(self):
self.assertEqual(callable(self.war.saxonAttack), True)
def testSaxonAttackReceiveNoParam(self):
self.assertEqual(len(signature(self.war.saxonAttack).parameters), 0)
def testVikingHealth(self):
oldHealt = self.viking.health
self.war.saxonAttack()
self.assertEqual(self.viking.health, oldHealt - self.saxon.strength)
def testVikingArmyList(self):
for i in range(12):
if(len(self.war.vikingArmy) == 0):
break
self.war.saxonAttack()
self.assertEqual(len(self.war.vikingArmy), 0)
def testReturnOfSaxonAttack(self):
self.assertEqual(self.war.saxonAttack(), self.viking.name +
' has received ' + str(self.saxon.strength) + ' points of damage')
def testShowStatusShouldIsFunction(self):
self.assertEqual(callable(self.war.showStatus), True)
def testShowStatusReceiveNoParams(self):
self.assertEqual(len(signature(self.war.showStatus).parameters), 0)
def testShouldReturnStringVikingsWon(self):
self.war.vikingAttack()
self.assertEqual(self.war.showStatus(),
'Vikings have won the war of the century!')
def testShouldReturnStringSaxonsWon(self):
for i in range(12):
self.war.saxonAttack()
self.assertEqual(self.war.showStatus(
), 'Saxons have fought for their lives and survive another day...')
def testShouldReturnStringStillFighting(self):
self.assertEqual(
self.war.showStatus(), 'Vikings and Saxons are still in the thick of battle.')
if __name__ == '__main__':
unittest.main()