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)
class normalize(unittest.TestCase): """ Tests that Normalize normalizes correctly """ def setUp(self): """ Build the Recoil Delegate """ self.delegate = RecoilDelegate(2) def zero(self): """ Test that < 1 is normalized correctly """ damage = 0 newDamage = self.delegate.normalize(damage) assert newDamage == 1, "Should return one if between 0 and 1" def normalize(self): """ Test that normalizing an int returns the int """ damage = 3 newDamage = self.delegate.normalize(damage) assert newDamage == damage, "Should return the number if its an int"
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 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"
def __init__(self, parent, recoilRatio): """ Builds a Recoil Effect with a set ration """ self.parent = parent RecoilDelegate.__init__(self, recoilRatio, preventable=False)
def effectOnMiss(self, user, target, environment): """ Applies the Recoil on Miss """ self.damage, messages = self.parent.damageDelegate.damage(user, target) return RecoilDelegate.applyEffect(self, user, target, environment)
def setUp(self): """ Build the Recoil Delegate """ self.delegate = RecoilDelegate(2)