Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Vikings Mini Project #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .ipynb_checkpoints/1-testsSoldier-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest
from vikingsClasses import Soldier
from inspect import signature


class TestSoldier(unittest.TestCase):

@classmethod
def setUp(cls):
cls.strength = 150
cls.health = 300
cls.soldier = Soldier(cls.health, cls.strength)

def testConstructorSignature(self):
self.assertEqual(len(signature(Soldier).parameters), 2)

def testHealth(self):
self.assertEqual(self.soldier.health, self.health)

def testStrength(self):
self.assertEqual(self.soldier.strength, self.strength)

def testAttackShouldBeFunction(self):
self.assertEqual(callable(self.soldier.attack), True)

def testAttackHasNoParams(self):
self.assertEqual(len(signature(self.soldier.attack).parameters), 0)

def testAttackRetunsStrength(self):
self.assertEqual(self.soldier.attack(), self.strength)

def testReceivesDamage(self):
self.assertEqual(callable(self.soldier.receiveDamage), True)

def testReceivesDamageHasParams(self):
self.assertEqual(
len(signature(self.soldier.receiveDamage).parameters), 1)

def testReceiveDamageReturnNone(self):
self.assertEqual(self.soldier.receiveDamage(50), None)

def testCanReceiveDamage(self):
self.soldier.receiveDamage(50)
self.assertEqual(self.soldier.health, self.health - 50)


if __name__ == '__main__':
unittest.main()
57 changes: 57 additions & 0 deletions .ipynb_checkpoints/3-testsSaxons-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from vikingsClasses import Saxon
from inspect import signature


class TestSaxon(unittest.TestCase):

@classmethod
def setUp(cls):
cls.health = 60
cls.strength = 25
cls.saxon = Saxon(cls.health, cls.strength)

def testSaxonShouldReceiveTwoParams(self):
self.assertEqual(len(signature(Saxon).parameters), 2)

def testHealth(self):
self.assertEqual(self.saxon.health, self.health)

def testStrength(self):
self.assertEqual(self.saxon.strength, self.strength)

def testAttack(self):
self.assertEqual(callable(self.saxon.attack), True)

def testAttackShouldReceiveNoParams(self):
self.assertEqual(len(signature(self.saxon.attack).parameters), 0)

def testAttackREturnStrength(self):
self.assertEqual(self.saxon.attack(), self.strength)

def testReceiveDamageIsFunction(self):
self.assertEqual(callable(self.saxon.receiveDamage), True)

def testReceiveDamageShouldReceiveOneParam(self):
self.assertEqual(
len(signature(self.saxon.receiveDamage).parameters), 1)

def testReceiveDamage(self):
self.saxon.receiveDamage(1)
self.assertEqual(self.saxon.health, self.health - 1)

def testReceiveDamageString45(self):
self.assertEqual(self.saxon.receiveDamage(
45), 'A Saxon has received 45 points of damage')

def testReceiveDamageString10(self):
self.assertEqual(self.saxon.receiveDamage(
10), 'A Saxon has received 10 points of damage')

def testReceiveDamageStringDied(self):
self.assertEqual(self.saxon.receiveDamage(self.health),
'A Saxon has died in combat')


if __name__ == '__main__':
unittest.main()
130 changes: 130 additions & 0 deletions .ipynb_checkpoints/4-testsWar-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
Loading