class damage(unittest.TestCase): """ Test cases of damage """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() attack = AttackFactory.getAttackAsNew("TACKLE") self.hp = 100 self.target.setCurrHP(self.hp) self.delegate = OneHitDelegate(attack, 1) def oneHitKO(self): """ Test that the attack is a one-hit KO """ self.target.setCurrHP(self.hp) self.target.pkmn.battleDelegate.types = ["NORMAL"] damage, messages = self.delegate.damage(self.user, self.target) assert damage == self.hp, "The damage should be the targets health" assert len(messages) == 1, "Should only get one message" assert messages[0] == OneHitDelegate.message, "Should get the One Hit KO message" def noDamage(self): """ Test that the attack does no damage when the effectiveness is 0 """ self.target.pkmn.battleDelegate.types = ["GHOST"] damage, messages = self.delegate.damage(self.user, self.target) assert damage == 0, "The damage should be zero"
class calcDamage(unittest.TestCase): """ Test cases of calcDamage """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.delegate = HalfHealthDelegate(None, 1) def halfHealth(self): """ Test that the damage is Half the Health of the target """ hp = 100 self.target.setCurrHP(hp) damage = self.delegate.calcDamage(self.user, self.target) assert damage == hp/2, "Damage should be half the targets health" def halfHealthNotFloored(self): """ Test that the damage is Half the Health of the target """ hp = 101 self.target.setCurrHP(hp) damage = self.delegate.calcDamage(self.user, self.target) assert damage == hp/2.0, "Damage should be half the targets health, not floored"
class heal(unittest.TestCase): """ Test cases of heal """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.ratio = 2 self.delegate = HealByHPRatioDelegate(self.ratio) def heal(self): """ Test that it heals by the ratio of the damage done """ self.pkmn.setCurrHP(0) self.delegate.heal(self.pkmn) hp = self.pkmn.getCurrHP() heal = self.pkmn.getStat("HP") / self.ratio assert hp == heal, "Should be healed by the ratio of the user's health"
class heal(unittest.TestCase): """ Test cases of heal """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.ratio = 2 self.damage = 10 self.delegate = HealByDamageRatioDelegate(self.ratio) def heal(self): """ Test that it heals by the ratio of the damage done """ self.pkmn.setCurrHP(0) self.delegate.damage = self.damage self.delegate.heal(self.pkmn) hp = self.pkmn.getCurrHP() heal = self.damage/self.ratio assert hp == heal, "Should be healed by the ratio of the damage"
class afterTurn(unittest.TestCase): """ Test that afterTurn works correctly """ def setUp(self): """ Builds the Paralysis status""" self.status = Burn() self.pkmn = BuildPokemonBattleWrapper() def damage(self): """ Test that the damage is done correctly """ self.pkmn.setStat("HP", 32) self.pkmn.setCurrHP(32) self.status.afterTurn(self.pkmn) damage = self.pkmn.getStat("HP") - self.pkmn.getCurrHP() assert damage == self.pkmn.getRatioOfHealth(Burn.ratio), "Damage should be Burn Ratio of Health" def message(self): """ Test that the message is returned correctly """ messages = self.status.afterTurn(self.pkmn) message = self.pkmn.getHeader() + Burn.intermittent assert len(messages) == 1, "Should get one message" assert messages[0] == message, "Message should be that the Pkmn was damaged by the Burn"
class afterTurn(unittest.TestCase): """ Test that afterTurn returns correctly """ def setUp(self): """ Builds the Pkmn and the Leech Effect """ self.pkmn = BuildPokemonBattleWrapper() self.message = " hurt." self.pkmn2 = BuildPokemonBattleWrapper() self.leech = Leech(self.pkmn2, self.message) def message(self): """ Test the message is correct """ message = self.leech.afterTurn(self.pkmn) assert message == [self.pkmn.getHeader() + self.message], "Message should be the pokemon's name and the message given to the Leech." def faint(self): """ Test that the messsages returned when the target faints """ self.pkmn.setCurrHP(self.leech.getAmount(self.pkmn)) messages = self.leech.afterTurn(self.pkmn) assert len(messages) == 2, "Should have 2 messages" assert messages[1] == self.pkmn.getHeader() + Faint.start, "Should have a faint message."
class afterTurn(unittest.TestCase): """ Test that afterTurn works correctly """ def setUp(self): """ Builds the Paralysis status""" self.status = Burn() self.pkmn = BuildPokemonBattleWrapper() def damage(self): """ Test that the damage is done correctly """ self.pkmn.setStat("HP", 32) self.pkmn.setCurrHP(32) self.status.afterTurn(self.pkmn) damage = self.pkmn.getStat("HP") - self.pkmn.getCurrHP() assert damage == self.pkmn.getRatioOfHealth( Burn.ratio), "Damage should be Burn Ratio of Health" def message(self): """ Test that the message is returned correctly """ messages = self.status.afterTurn(self.pkmn) message = self.pkmn.getHeader() + Burn.intermittent assert len(messages) == 1, "Should get one message" assert messages[ 0] == message, "Message should be that the Pkmn was damaged by the Burn"
class afterTurn(unittest.TestCase): """ Test that afterTurn returns correctly """ def setUp(self): """ Builds the Pkmn and the Leech Effect """ self.pkmn = BuildPokemonBattleWrapper() self.message = " hurt." self.pkmn2 = BuildPokemonBattleWrapper() self.leech = Leech(self.pkmn2, self.message) def message(self): """ Test the message is correct """ message = self.leech.afterTurn(self.pkmn) assert message == [ self.pkmn.getHeader() + self.message ], "Message should be the pokemon's name and the message given to the Leech." def faint(self): """ Test that the messsages returned when the target faints """ self.pkmn.setCurrHP(self.leech.getAmount(self.pkmn)) messages = self.leech.afterTurn(self.pkmn) assert len(messages) == 2, "Should have 2 messages" assert messages[1] == self.pkmn.getHeader() + Faint.start, "Should have a faint message."
class calcDamage(unittest.TestCase): """ Test cases of calcDamage """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.delegate = HalfHealthDelegate(None, 1) def halfHealth(self): """ Test that the damage is Half the Health of the target """ hp = 100 self.target.setCurrHP(hp) damage = self.delegate.calcDamage(self.user, self.target) assert damage == hp / 2, "Damage should be half the targets health" def halfHealthNotFloored(self): """ Test that the damage is Half the Health of the target """ hp = 101 self.target.setCurrHP(hp) damage = self.delegate.calcDamage(self.user, self.target) assert damage == hp / 2.0, "Damage should be half the targets health, not floored"
class effectOnMiss(unittest.TestCase): """ Test cases of effectOnMiss """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.attack = BuildAttack() self.damage, messages = self.attack.damageDelegate.damage(self.pkmn, self.pkmn) self.ratio = 2 self.delegate = CrashDelegate(self.attack, self.ratio) def recoil(self): """ Test that recoil damage is done """ self.pkmn.setCurrHP(self.damage*2) self.delegate.effectOnMiss(self.pkmn, self.pkmn, None) damageDone = self.damage*2 - self.pkmn.getCurrHP() damage = self.damage/self.ratio assert damageDone == damage or damageDone == 2*damage, "Should do damage over ratio as damage" def message(self): """ Test that the message returned is correct """ self.pkmn.setCurrHP(self.damage) self.delegate.damage = self.damage messages = self.delegate.effectOnMiss(self.pkmn, self.pkmn, None) message = CrashDelegate.message % self.pkmn.getHeader() assert len(messages) == 1, "Should get one message" assert messages[0] == message, "Message should be Pkmn's header and the Delegate's message" def faints(self): """ Test that the message is correct when the Pkmn faints """ self.pkmn.setCurrHP(1) self.delegate.damage = self.damage messages = self.delegate.effectOnMiss(self.pkmn, self.pkmn, None) faintMessage = self.pkmn.getHeader() + Faint.start assert len(messages) == 2, "Should get 2 messages" assert messages[1] == faintMessage, "Message should be that the Pkmn Fainted"
class applyEffect(unittest.TestCase): """ Test cases of applyEffect """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.ratio = 2 self.damage = 50 self.delegate = RecoilDelegate(self.ratio) def recoil(self): """ Test that recoil damage is done """ self.pkmn.setCurrHP(self.damage) self.delegate.damage = self.damage self.delegate.applyEffect(self.pkmn, None, None) damageDone = self.damage - self.pkmn.getCurrHP() damage = self.damage / self.ratio assert damageDone == damage, "Should do damage over ratio as damage" def message(self): """ Test that the message returned is correct """ self.pkmn.setCurrHP(self.damage) self.delegate.damage = self.damage messages = self.delegate.applyEffect(self.pkmn, None, None) message = RecoilDelegate.message % self.pkmn.getHeader() assert len(messages) == 1, "Should get one message" assert messages[ 0] == message, "Message should be Pkmn's header and the Delegate's message" def faints(self): """ Test that the message is correct when the Pkmn faints """ self.pkmn.setCurrHP(1) self.delegate.damage = self.damage messages = self.delegate.applyEffect(self.pkmn, None, None) faintMessage = self.pkmn.getHeader() + Faint.start assert len(messages) == 2, "Should get 2 messages" assert messages[ 1] == faintMessage, "Message should be that the Pkmn Fainted"
class afterTurn(unittest.TestCase): """ Test that afterTurn returns correctly """ def setUp(self): """ Builds the side and trap """ self.source = BuildPokemonBattleWrapper() self.pkmn = BuildPokemonBattleWrapper() self.message = " hurt." self.doneMessage = " done." self.trap = Trap(None, self.message, self.doneMessage) def turnDecreases(self): """ Test the turn counter decreases """ self.trap.turns = 5 turns = self.trap.turns self.trap.afterTurn(self.pkmn) assert self.trap.turns == turns - 1, "Turns should decrement" def effectIsRemoved(self): """ Test that the effect is removed when the turn count is reduced to zero """ self.trap.turns = 1 self.pkmn.secondaryEffects.append(self.trap) self.trap.afterTurn(self.pkmn) assert self.trap.turns == 0, "Turns should be zero" assert not self.trap in self.pkmn.secondaryEffects def message(self): """ Test the message is correct """ message = self.trap.afterTurn(self.pkmn) assert message == [self.pkmn.getHeader() + self.message], "Message should be the pokemon's name and the message given to the Trap." def doneMessage(self): """ Test the done message is correct """ self.trap.turns = 1 self.pkmn.secondaryEffects.append(self.trap) messages = self.trap.afterTurn(self.pkmn) assert len(messages) == 2, "Should have two messages" assert messages[1] == self.pkmn.getHeader() + self.doneMessage, "Done message should be returned." def faintMessage(self): """ Test the faint message appears if the Pkmn faints """ self.trap.turns = 3 self.pkmn.setCurrHP(self.trap.getDamage(self.pkmn)) self.pkmn.secondaryEffects.append(self.trap) messages = self.trap.afterTurn(self.pkmn) assert len(messages) == 2, "Should have two messages" assert messages[1] == self.pkmn.getHeader() + Faint.start, "Pkmn should have fainted." def faintAndDoneMessage(self): """ Test the done message is correct """ self.trap.turns = 1 self.pkmn.setCurrHP(self.trap.getDamage(self.pkmn)) self.pkmn.secondaryEffects.append(self.trap) messages = self.trap.afterTurn(self.pkmn) assert len(messages) == 2, "Should have two messages" assert messages[1] == self.pkmn.getHeader() + Faint.start, "Pkmn should have fainted."