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 cantHandle(unittest.TestCase): """ Test cases of cantHandle """ def setUp(self): """ Build the FaintDelegate for the test """ self.handler = AffectUserFaintDelegate() self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.effect = BuildEffectDelegate() def userFainted(self): """ Test that it can't handle the user fainting """ self.user.faint() self.effect.affectUser = 1 cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect) assert cantHandle, "Shouldn't handle when the user is fainted" def userNotFainted(self): """ Test that it can handle when the user is not fainted """ self.effect.affectUser = 1 cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect) assert not cantHandle, "Should handle when the user is not fainted" def targetFainted(self): """ Test that it can't handle the target fainting """ self.target.faint() self.effect.affectUser = 0 cantHandle = self.handler.cantHandle(target = self.target, effect = self.effect) assert cantHandle, "Shouldn't handle when the target is fainted" def targetNotFainted(self): """ Test that it can handle when the target is not fainted """ self.effect.affectUser = 0 cantHandle = self.handler.cantHandle(target = self.target, effect = self.effect) assert not cantHandle, "Should handle when the target is not fainted"
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 applyEffect(unittest.TestCase): """ Test cases of applyEffect """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.delegate = ConfuseDelegate(1) def alreadyConfused(self): """ Test that confusion is not applied when the target is already confused """ self.user.secondaryEffects = [Confusion()] message = self.user.getHeader() + Confusion.already messages = self.delegate.applyEffect(self.user, self.target, None) assert len(messages) == 1, "Should get one message" assert messages[0] == message, "Should say that the Pkmn is already confused" assert len(self.user.secondaryEffects) == 1, "Pkmn should not get another confusion effect" def notConfused(self): """ Test that confusion is applied when the target is not confused """ self.user.secondaryEffects = [] message = self.user.getHeader() + Confusion.start messages = self.delegate.applyEffect(self.user, self.target, None) assert len(messages) == 1, "Should get one message" assert messages[0] == message, "Should say that the Pkmn is now confused" assert len(self.user.secondaryEffects) == 1, "Pkmn should get a confusion effect" assert self.delegate.isConfused(self.user), "The Pkmn should now be confused"
class hit(unittest.TestCase): """ Test cases of hit """ def setUp(self): """ Build the Pkmn and Delegate for the test """ self.attack = BuildAttack() self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() self.toHit = 100.0 self.delegate = HitDelegate(self.attack, self.toHit) def fainted(self): """ Test that if the target is fainted the attack misses """ self.target.faint() hit, message = self.delegate.hit(self.user, self.target, self.environment) assert not hit, "Should miss if the target is fainted" def dodging(self): """ Test that if the target is dodging the attack misses """ self.target.dodge = "DIG" hit, message = self.delegate.hit(self.user, self.target, self.environment) assert not hit, "Should miss if the target is dodging" def otherwise(self): """ Test that the attack hits if the target is not dodging or fainted """ hit, message = self.delegate.hit(self.user, self.target, self.environment) assert hit, "Should hit otherwise"
def hasStab(self): """ Test that it correctly returns STAB modifier """ pkmn = BuildPokemonBattleWrapper("CHARMANDER") stab = self.delegate.getStab(pkmn) assert stab == 1.5, "Should return with STAB modifier"
def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.delegate = ConfuseDelegate(1)
def setUp(self): """ Build the Pkmn and AfterTurnEffect for the test """ self.effect = AfterTurnEffect() self.effect.faintHandler = BuildFaintHandler("USER") self.pkmn = BuildPokemonBattleWrapper()
def setUp(self): """ Builds the delegate and pkmn for use in the tests """ self.pkmn = BuildPokemonBattleWrapper() self.delegate = PeriodicHealDelegate("", "") self.heal = PeriodicHeal("")
def setUp(self): """ Builds the ability """ self.pkmn = BuildPokemonBattleWrapper() self.ability = Ability(None)
def setUp(self): """ Build the FaintDelegate for the test """ self.handler = UserFaintDelegate() self.user = BuildPokemonBattleWrapper()
def setUp(self): """ Build the FaintDelegate for the test """ self.handler = TargetFaintDelegate() self.target = BuildPokemonBattleWrapper()
def setUp(self): """ Build the Pkmn and Effect for the test """ self.delegate = EffectDelegate() self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper()
def getPkmnWithTypes(self, types): """ Returns a Pokemon Battle Wrapper with the given types """ pkmn = BuildPokemonBattleWrapper() pkmn.setTypes(types) return pkmn
def setUp(self): """ Build the Pkmn """ self.stat = "ATK" self.battlePkmn = BuildPokemonBattleWrapper() self.pkmn = self.battlePkmn.pkmn
def noStab(self): """ Test that it correctly returns STAB modifier """ pkmn = BuildPokemonBattleWrapper("BULBASAUR") stab = self.delegate.getStab(pkmn) assert stab == 1, "Should return with modifier of 1"
def setUp(self): """ Grabs the message dictionary from StatModDelegate """ self.environment = BattleEnvironment() self.pkmn = BuildPokemonBattleWrapper() self.delegate = ChargeDelegate(2, 0, "")
def setUp(self): """ Builds the delegate and side for use in the tests """ self.pkmn = BuildPokemonBattleWrapper() self.attacker = BuildPokemonBattleWrapper() self.ability = Ability(None)
def setUp(self): """ Builds the ability """ self.name = "Some Name" self.pkmn = BuildPokemonBattleWrapper() self.ability = ConfusionImmunityAbility(self.name)
def setUp(self): """ Builds the Pkmn and Leech """ self.pkmn = BuildPokemonBattleWrapper() self.pkmn2 = BuildPokemonBattleWrapper() self.leech = Leech(self.pkmn2, "") self.hp = 32
def setUp(self): """ Build the Trainer and Pokemon lists for use in tests """ self.trainer = Trainer() self.pkmnWithHealth = BuildPokemonBattleWrapper() self.pkmnWithoutHealth = BuildPokemon(pkmn = "CHARMANDER") self.pkmnWithoutHealth.battleDelegate.currHP = 0
def setUp(self): """ Builds the delegate and pkmn for use in the tests """ self.wrapper = BuildPokemonBattleWrapper() self.delegate = LeechDelegate("", "", "FIRE") self.leech = Leech(None, "") self.otherLeech = Leech(None, "other.")
def setUp(self): """ Build the Pkmn and Delegate for the test """ self.pkmn = BuildPokemonBattleWrapper() self.delegate = HealByRatioDelegate(2)
def setUp(self): """ Setup the attack and Pokemon to use the attack """ self.pkmn = BuildPokemonBattleWrapper() self.delegate = DamageScaleDelegate(None, 50, 1, 1, 5)
def setUp(self): """ Build the Pkmn and Delegate for the test """ self.target = BuildPokemonBattleWrapper() self.turns = 3 self.delegate = ApplyLockDelegate(self.turns, 0)
def setUp(self): """ Build Pkmn and Delegate for use in test cases """ self.pkmn = BuildPokemonBattleWrapper() self.delegate = HitDelegate(None, 100)
def setUp(self): """ Build side for use in test cases """ self.pkmn = BuildPokemonBattleWrapper() self.parent = Attack() self.parent.type = "NORMAL"
def setUp(self): """ Build the Pkmn and Delegate for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.delegate = HitDelegate(None, 100)
def setUp(self): """ Build the Pkmn and Delegate for the test """ self.target = BuildPokemonBattleWrapper() self.delegate = FlinchDelegate()
def setUp(self): """ Builds the Sleep status""" self.status = Sleep() self.pkmn = BuildPokemonBattleWrapper() self.pkmn.setStatus(self.status) self.turns = 1
def setUp(self): """ Build the Damage Delegate """ self.target = BuildPokemonBattleWrapper() self.delegate = DamageDelegate(None, 0, 1)
def setUp(self): """ Builds the BattleSide """ self.stat = "ATK" self.pkmn = BuildPokemonBattleWrapper()
def setUp(self): """ Build the Confusion for the test """ self.user = BuildPokemonBattleWrapper() self.confusion = Confusion() self.turns = 2