예제 #1
0
class normalize(unittest.TestCase):
    """ Tests that Normalize normalizes correctly """
    def setUp(self):
        """ Build the Damage Delegate """
        self.target = BuildPokemonBattleWrapper()
        self.delegate = NoFaintDelegate(None, 0, 1)

    def lessThanTargetHP(self):
        """ Test that damage is normalized correctly when less than the target's HP """
        damage = self.target.getCurrHP() - 1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == damage, "Should return the original damage"

    def targetHP(self):
        """ Test that damage is normalized correctly when equal to the target's HP """
        damage = self.target.getCurrHP()
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == self.target.getCurrHP(
        ) - 1, "Should return one less than the target's HP as damage"

    def greaterThanTargetHP(self):
        """ Test that damage is normalized correctly when greater than the target's HP """
        damage = self.target.getCurrHP() + 1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == self.target.getCurrHP(
        ) - 1, "Should return one less than the target's HP as damage"
예제 #2
0
class normalize(unittest.TestCase):
    """ Tests that Normalize normalizes correctly """
    
    def setUp(self):
        """ Build the Damage Delegate """
        self.target = BuildPokemonBattleWrapper()
        self.delegate = NoFaintDelegate(None, 0, 1)
        
    def lessThanTargetHP(self):
        """ Test that damage is normalized correctly when less than the target's HP """
        damage = self.target.getCurrHP()-1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == damage, "Should return the original damage"
        
    def targetHP(self):
        """ Test that damage is normalized correctly when equal to the target's HP """
        damage = self.target.getCurrHP()
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == self.target.getCurrHP() -1 , "Should return one less than the target's HP as damage"
        
    def greaterThanTargetHP(self):
        """ Test that damage is normalized correctly when greater than the target's HP """
        damage = self.target.getCurrHP()+1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == self.target.getCurrHP() -1, "Should return one less than the target's HP as damage"
class takeDamage(unittest.TestCase):
    """ Test cases of takeDamage """
    
    def  setUp(self):
        """ Build the Pkmn """
        self.pkmn = BuildPokemonBattleWrapper()
    
    def faints(self):
        """ Test that Faint Exception is thrown """
        messages = self.pkmn.takeDamage(self.pkmn.getCurrHP())
        assert messages == [self.pkmn.getHeader() + Faint.start], "The Pkmn should have fainted"
        
    def noFaint(self):
        """ Test that Faint Exception is not thrown if the pkmn doesn't faint """
        messages = self.pkmn.takeDamage(self.pkmn.getCurrHP()-1)
        assert messages == [], "Should receive any empty list when the Pkmn has not fainted"
예제 #4
0
class normalize(unittest.TestCase):
    """ Tests that Normalize normalizes correctly """
    
    def setUp(self):
        """ Build the Damage Delegate """
        self.target = BuildPokemonBattleWrapper()
        self.delegate = DamageDelegate(None, 0, 1)
        
    def zero(self):
        """ Test that 0 is normalized correctly """
        damage = 0
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == 0, "Should return zero"
        
    def lessThanOne(self):
        """ Test that < 1 is normalized correctly """
        damage = 0.1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == 1, "Should return one if between 0 and 1"
        
    def normalizeInt(self):
        """ Test that normalizing an int returns the int """
        damage = 3
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == damage, "Should return the number if its an int"
        
    def normalizeFloat(self):
        """ Test that normalizing a float returns the int """
        damage = 3.3
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == int(damage), "Should return the floored number if its an int"
        
    def greaterThanTargetHP(self):
        """ Test that damage is normalized correctly when greater than the target's HP """
        damage = self.target.getCurrHP()+1
        newDamage = self.delegate.normalize(damage, self.target)
        assert newDamage == int(self.target.getCurrHP()), "Should return the target's HP as damage"
예제 #5
0
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"
예제 #7
0
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"
예제 #8
0
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"
예제 #9
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    
    def  setUp(self):
        """ Build the Pkmn and Delegate for the test """
        self.user = BuildPokemonBattleWrapper()
        self.delegate = SelfDestructDelegate()
        
    def selfDestructed(self):
        """ Test that the user self destructs (aka dies) """
        self.delegate.applyEffect(self.user, None, None)
        assert self.user.getCurrHP() == 0, "Pkmn should have fainted"
    
    def message(self):
        """ Test that the user self destructs (aka dies) """
        messages = self.delegate.applyEffect(self.user, None, None)
        message = self.user.getHeader() + SelfDestructDelegate.message
        faintMessage = self.user.getHeader() + Faint.start
        assert len(messages) == 2, "Should get 1 message"
        assert messages[0] == message, "Should get the Pkmn's header and the Delegate's message"
        assert messages[1] == faintMessage, "Should have the Pkmn faint"
예제 #10
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    def setUp(self):
        """ Build the Pkmn and Delegate for the test """
        self.user = BuildPokemonBattleWrapper()
        self.delegate = SelfDestructDelegate()

    def selfDestructed(self):
        """ Test that the user self destructs (aka dies) """
        self.delegate.applyEffect(self.user, None, None)
        assert self.user.getCurrHP() == 0, "Pkmn should have fainted"

    def message(self):
        """ Test that the user self destructs (aka dies) """
        messages = self.delegate.applyEffect(self.user, None, None)
        message = self.user.getHeader() + SelfDestructDelegate.message
        faintMessage = self.user.getHeader() + Faint.start
        assert len(messages) == 2, "Should get 1 message"
        assert messages[
            0] == message, "Should get the Pkmn's header and the Delegate's message"
        assert messages[1] == faintMessage, "Should have the Pkmn faint"
예제 #11
0
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"
예제 #12
0
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"