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 Viking #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
198 changes: 171 additions & 27 deletions vikingsClasses.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,204 @@
import random

# Soldier


class Soldier:
def __init__(self, health, strength):
# your code here

self.health = health
self.strength = strength

def attack(self):
# your code here
return self.strength

def receiveDamage(self, damage):
# your code here
self.health -= damage


# Viking

class Viking(Soldier):
def __init__(self, name, health, strength):
# your code here
super().__init__(health, strength)
self.name = name

def battleCry(self):
# your code here
return "Odin Owns You All!"

def receiveDamage(self, damage):
# your code here
self.health -= damage
if self.health > 0:
return f"{self.name} has received {damage} points of damage"
else:
return f"{self.name} has died in act of combat"

# Saxon

class Saxon(Soldier):
def __init__(self, health, strength):
# your code here
super().__init__(health, strength)

def receiveDamage(self, damage):
# your code here

# Davicente

class War():
self.health -= damage
if self.health > 0:
return f"A Saxon has received {damage} points of damage"
else:
return "A Saxon has died in combat"
# War
class War:
def __init__(self):
# your code here
self.vikingArmy = []
self.saxonArmy = []

def addViking(self, viking):
# your code here
self.vikingArmy.append(viking)

def addSaxon(self, saxon):
# your code here
self.saxonArmy.append(saxon)

def vikingAttack(self):
# your code here

import random
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
result = saxon.receiveDamage(viking.strength)
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return result

def saxonAttack(self):
# your code here
import random
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
result = viking.receiveDamage(saxon.strength)
if viking.health <= 0:
self.vikingArmy.remove(viking)
return result

def showStatus(self):
# your code here
pass
if not self.saxonArmy:
return "Vikings have won the war of the century!"
elif not self.vikingArmy:
return "Saxons have fought for their lives and survive another day..."
else:
return "Vikings and Saxons are still in the thick of battle."

import unittest
from vikingsClasses import Viking
from inspect import signature


class TestViking(unittest.TestCase):

@classmethod
def setUp(cls):
cls.name = 'Harald'
cls.strength = 150
cls.health = 300
cls.viking = Viking(cls.name, cls.health, cls.strength)

def testShouldReciveThreeParams(self):
self.assertEqual(len(signature(Viking).parameters), 3)

def testName(self):
self.assertEqual(self.viking.name, self.name)

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

def testStrenght(self):
self.assertEqual(self.viking.strength, self.strength)

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

def testAttackReciveNoParameters(self):
self.assertEqual(len(signature(self.viking.attack).parameters), 0)

def testAttackShouldReturnStrength(self):
self.assertEqual(self.viking.attack(), self.strength)

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

def testReceiveDamageReciveOneParam(self):
self.assertEqual(
len(signature(self.viking.receiveDamage).parameters), 1)

def testReciveDamageShouldRestHealth(self):
self.viking.receiveDamage(50)
self.assertEqual(self.viking.health, self.health - 50)

def testReciveDamageShouldReturnString50(self):
self.assertEqual(self.viking.receiveDamage(50), self.name +
' has received 50 points of damage')

def testReciveDamageShouldReturnString70(self):
self.assertEqual(self.viking.receiveDamage(70), self.name +
' has received 70 points of damage')

def testReceiveDamageShouldReturnStringDeath(self):
self.assertEqual(self.viking.receiveDamage(self.health),
self.name + ' has died in act of combat')

def testBattleCry(self):
self.assertEqual(callable(self.viking.battleCry), True)

def testBattleCryReturnString(self):
self.assertEqual(self.viking.battleCry(), 'Odin Owns You All!')

if __name__ == '__main__':
unittest.main()

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()