コード例 #1
0
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"
コード例 #2
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    
    def  setUp(self):
        """ Build the Pkmn, Abilities and Effect for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
        self.userAbility = Ability(None)
        self.targetAbility = Ability(None)
        
        self.user.setAbility(self.userAbility)
        self.target.setAbility(self.targetAbility)
        
        self.delegate = SwapAbilityDelegate()
        
    def swapped(self):
        """ Test that the abilities are swapped """
        self.delegate.applyEffect(self.user, self.target, None)
        
        assert self.user.getAbility() is self.targetAbility, "User should have target's ability"
        assert self.target.getAbility() is self.userAbility, "Target should have user's ability"
        
    def message(self):
        """ Test message is returned correctly """
        messages = self.delegate.applyEffect(self.user, self.target, None)
        
        assert messages == [SwapAbilityDelegate.message % (self.user.getHeader(), self.target.getHeader())], "Should have the Effect's message"
コード例 #3
0
ファイル: confuse_test.py プロジェクト: cloew/Pokemon-Project
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"
コード例 #4
0
class checkOver(unittest.TestCase):
    """ Test cases of checkOver """
    
    def  setUp(self):
        """ Build the Confusion for the test """
        self.user = BuildPokemonBattleWrapper()
        self.confusion = Confusion()
        self.turns = 2
        
    def overCured(self):
        """ Test that the Confusion is cured when it is over """
        messages = []
        self.confusion.turns = 0
        self.user.secondaryEffects = [self.confusion]
        self.confusion.checkOver(self.user, messages)
        
        assert self.user.secondaryEffects == [], "Should be cured"
        
    def overMessage(self):
        """ Test that the Message is correct when it is over """
        messages = []
        self.confusion.turns = 0
        self.user.secondaryEffects = [self.confusion]
        message = self.user.getHeader() + Confusion.over
        self.confusion.checkOver(self.user, messages)
        
        assert len(messages) == 1, "Should receive one message"
        assert messages[0] == message, "Should receive a message that the confusion is over"
    
    def notOverStillConfused(self):
        """ Test that thePkmn is still confused when it isn't over """
        messages = []
        self.confusion.turns = self.turns
        self.user.secondaryEffects = [self.confusion]
        self.confusion.checkOver(self.user, messages)
        
        assert self.user.secondaryEffects == [self.confusion], "Should still be confused"

    def notOverTurnsDecremented(self):
        """ Test that the Turns is decremented when it isn't over """
        messages = []
        self.confusion.turns = self.turns
        self.confusion.checkOver(self.user, messages)
        
        assert self.confusion.turns == self.turns-1, "Should have turns decremented"

    def notOverMessage(self):
        """ Test that the Message is correct when it isn't over """
        messages = []
        self.confusion.turns = self.turns
        message = self.user.getHeader() + Confusion.start
        self.confusion.checkOver(self.user, messages)
        
        assert len(messages) == 1, "Should receive one message"
        assert messages[0] == message, "Should receive a message that the Pkmn is still confusion"
コード例 #5
0
class checkCharging(unittest.TestCase):
    """ Test cases of checkCharging """
    
    def  setUp(self):
        """ Build the Pkmn and Precondition Checker for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.environment = BattleEnvironment()
        
        self.attack = AttackFactory.getAttackAsNew("DIG")
        self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack)
        
        attack2 = AttackFactory.getAttackAsNew("TACKLE")
        self.preconditionChecker2 = PreconditionChecker(self.user, self.target, self.environment, attack2)
        
    def charging(self):
        """ Test that check charging returns correctly when the user is charging  """
        stop, messages = self.preconditionChecker.checkCharging()
        
        message = [self.user.getHeader() + self.attack.effectDelegates[0].message]
        
        assert stop, "Should stop if the user is charging"
        assert messages == message, "Should have charging message"
        
    def notCharging(self):
        """ Test that check charging returns correctly when the user is not charging """
        stop, messages = self.preconditionChecker2.checkCharging()
        
        assert not stop, "Should not stop if the user isn't charging"
        assert messages == [], "Should not receive any messages"
コード例 #6
0
class checkFlinch(unittest.TestCase):
    """ Test cases of checkFlinch """
    
    def  setUp(self):
        """ Build the Pkmn and Precondition Checker for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.environment = BattleEnvironment()
        
        attack = AttackFactory.getAttackAsNew("TACKLE")
        self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, attack)
        
    def flinching(self):
        """ Test that check flinch returns correctly when the user has is flinching """
        self.user.flinching = True
        stop, messages = self.preconditionChecker.checkFlinch()
        
        message = [self.user.getHeader() + " flinched."]
        
        assert stop, "Should stop if the user flinches"
        assert messages == message, "Should have flinching message"
        
    def notFlinching(self):
        """ Test that check flinch returns correctly when the user is not flinching """
        self.user.flinching = False
        stop, messages = self.preconditionChecker.checkLock()
        
        assert not stop, "Should not stop if the user isn't flinching"
        assert messages == [], "Should not receive any messages"
コード例 #7
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    def setUp(self):
        """ Build the Effect and Pkmn for the test """
        self.stat1 = "ATK"
        self.stat2 = "DEF"

        self.val1 = 50
        self.val2 = 20

        self.user = BuildPokemonBattleWrapper()
        self.delegate = SwapStatDelegate(self.stat1, self.stat2)

    def swapped(self):
        """ Test that the stats are swapped """
        self.user.setStat(self.stat1, self.val1)
        self.user.setStat(self.stat2, self.val2)
        self.delegate.applyEffect(self.user, None, None)

        assert self.user.getStat(
            self.stat1) == self.val2, "Stat 1 should get Stat 2's value"
        assert self.user.getStat(
            self.stat2) == self.val1, "Stat 2 should get Stat 1's value"

    def message(self):
        """ Test that the message is returned correctly """
        messages = self.delegate.applyEffect(self.user, None, None)

        message = SwapStatDelegate.message % (self.user.getHeader(),
                                              self.stat1, self.stat2)
        assert messages == [
            message
        ], "Message should say the user had its two stats swapped"
コード例 #8
0
class applyEffect(unittest.TestCase):
    """ Test that isCharging returns the correct values """
    def setUp(self):
        """ Grabs the message dictionary from StatModDelegate """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
        self.delegate = SwapStatModsDelegate()
        
        self.statMods1 = {"ATK":1, "DEF":0, "SPD":0, "SATK":0, "SDEF":0, 
                                "ACC":0, "EVAS":0, "CRT":1}
        self.user.statMods = self.statMods1
                                
        self.statMods2 = {"ATK":0, "DEF":0, "SPD":1, "SATK":1, "SDEF":1, 
                                "ACC":0, "EVAS":0, "CRT":0}
        self.target.statMods = self.statMods2
        
    def statModsSwitched(self):
        """ Tests if ithe stat mods are swapped """
        self.delegate.applyEffect(self.user, self.target, None)
        assert self.user.statMods == self.statMods2, "Pkmn 1 should have stats from Pkmn 2"
        assert self.target.statMods == self.statMods1, "Pkmn 2 should have stats from Pkmn 1"
        
    def message(self):
        """ Test the message returned is correct """
        messages = self.delegate.applyEffect(self.user, self.target, None)
        message = self.user.getHeader() + SwapStatModsDelegate.message
        assert len(messages) == 1, "Should get 1 message"
        assert messages[0] == message, "Should be Pkmn's header and the Delegate's message"
コード例 #9
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    
    def  setUp(self):
        """ Build the Effect and Pkmn for the test """
        self.stat1 = "ATK"
        self.stat2 = "DEF"
        
        self.val1 = 50
        self.val2 = 20
        
        self.user = BuildPokemonBattleWrapper()
        self.delegate = SwapStatDelegate(self.stat1, self.stat2)
        
    def swapped(self):
        """ Test that the stats are swapped """
        self.user.setStat(self.stat1, self.val1)
        self.user.setStat(self.stat2, self.val2)
        self.delegate.applyEffect(self.user, None, None)
        
        assert self.user.getStat(self.stat1) == self.val2, "Stat 1 should get Stat 2's value"
        assert self.user.getStat(self.stat2) == self.val1, "Stat 2 should get Stat 1's value"
        
    def message(self):
        """ Test that the message is returned correctly """
        messages = self.delegate.applyEffect(self.user, None, None)
        
        message = SwapStatDelegate.message % (self.user.getHeader(), self.stat1, self.stat2)
        assert messages == [message], "Message should say the user had its two stats swapped"
コード例 #10
0
class checkLock(unittest.TestCase):
    """ Test cases of checkLock """
    
    def  setUp(self):
        """ Build the Pkmn, Lock, and Precondition Checker for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.environment = BattleEnvironment()
        
        self.actionLock = BuildActionLock(user = self.user)
        self.attack = AttackFactory.getAttackAsNew("TACKLE")
        self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack)
        
    def hasLock(self):
        """ Test that check lock returns correctly when the user has a lock  """
        self.user.actionLock = self.actionLock
        stop, messages = self.preconditionChecker.checkLock()
        
        message = "{0} USED {1}".format(self.user.getHeader(), self.actionLock.action.attack.name)
        
        assert stop, "Should stop if the user has a lock"
        assert len(messages) > 0,  "Should receive the messages for the actual attack"
        assert messages[0] == message, "Should use the actionLock attack"
        
    def usingLock(self):
        """ Test that check lock returns correctly when the user is using its lock attack  """
        self.preconditionChecker.attack = self.actionLock.action.attack
        self.user.actionLock = self.actionLock
        stop, messages = self.preconditionChecker.checkLock()
        
        message = "{0} USED {1}".format(self.user.getHeader(), self.actionLock.action.attack.name)
        
        assert not stop, "Should not stop if the user is using its lock"
        assert messages == [], "Should not receive any messages"
        
    def noLock(self):
        """ Test that check lock returns correctly when the user has no lock """
        self.user.actionLock = None
        stop, messages = self.preconditionChecker.checkLock()
        
        assert not stop, "Should not stop if the user has no lock"
        assert messages == [], "Should not receive any messages"
コード例 #11
0
ファイル: crash_test.py プロジェクト: cloew/Pokemon-Project
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"
コード例 #12
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"
コード例 #13
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"
コード例 #14
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"
コード例 #15
0
ファイル: leech_test.py プロジェクト: TimChau/Pokemon-Project
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."
コード例 #16
0
ファイル: sleep_test.py プロジェクト: cloew/Pokemon-Project
class immobilized(unittest.TestCase):
    """ Test that immobilized performs correctly """
    
    def setUp(self):
        """ Builds the Sleep status"""
        self.status = Sleep()
        self.pkmn = BuildPokemonBattleWrapper()
        self.pkmn.setStatus(self.status)
        self.turns = 1
    
    def notDone(self):
        """ Test if immobilized returns correctly when it is not done """
        self.status.turns = self.turns
        
        immobilized, messages = self.status.immobilized(self.pkmn)
        
        assert immobilized, "Should be immobilized"
        assert messages == [self.pkmn.getHeader() + Sleep.intermittent],\
                "Should return Sleep's intermittent message"
        assert self.status.turns == self.turns - 1, "Turns should be decremented"
        
    def done(self):
        """ Test if immobilized returns correctly when it is done """
        self.status.turns = 0
        
        assert self.pkmn.getStatus() == self.status, "Should have status to start"
        
        immobilized, messages = self.status.immobilized(self.pkmn)
        
        assert not immobilized, "Should not be immobilized"
        assert len(messages) == 2, "Should have two messages"
        
        assert messages[0] == self.pkmn.getHeader() + Sleep.intermittent,\
                "Should return Sleep's intermittent message"
        assert messages[1] == self.pkmn.getHeader() + Sleep.done,\
                "Should return Sleep's done message"
                
        assert self.pkmn.getStatus() != self.status, "Status should be removed"
コード例 #17
0
ファイル: sleep_test.py プロジェクト: TimChau/Pokemon-Project
class immobilized(unittest.TestCase):
    """ Test that immobilized performs correctly """
    def setUp(self):
        """ Builds the Sleep status"""
        self.status = Sleep()
        self.pkmn = BuildPokemonBattleWrapper()
        self.pkmn.setStatus(self.status)
        self.turns = 1

    def notDone(self):
        """ Test if immobilized returns correctly when it is not done """
        self.status.turns = self.turns

        immobilized, messages = self.status.immobilized(self.pkmn)

        assert immobilized, "Should be immobilized"
        assert messages == [self.pkmn.getHeader() + Sleep.intermittent],\
                "Should return Sleep's intermittent message"
        assert self.status.turns == self.turns - 1, "Turns should be decremented"

    def done(self):
        """ Test if immobilized returns correctly when it is done """
        self.status.turns = 0

        assert self.pkmn.getStatus(
        ) == self.status, "Should have status to start"

        immobilized, messages = self.status.immobilized(self.pkmn)

        assert not immobilized, "Should not be immobilized"
        assert len(messages) == 2, "Should have two messages"

        assert messages[0] == self.pkmn.getHeader() + Sleep.intermittent,\
                "Should return Sleep's intermittent message"
        assert messages[1] == self.pkmn.getHeader() + Sleep.done,\
                "Should return Sleep's done message"

        assert self.pkmn.getStatus() != self.status, "Status should be removed"
コード例 #18
0
class afterTurn(unittest.TestCase):
    """ Test that afterTurn returns correctly """
    
    def setUp(self):
        """ Build the Pkmn and Heal """
        self.pkmn = BuildPokemonBattleWrapper()
        
        self.message = " hurt."
        self.heal = PeriodicHeal(self.message)
        
    def message(self):
        """ Test the message is correct """
        message = self.heal.afterTurn(self.pkmn)
        assert message == [self.pkmn.getHeader() + self.message], "Message should be the pokemon's name and the message given to the Heal."
コード例 #19
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    def setUp(self):
        """ Build the Pkmn and Delegate for the test """
        self.pkmn = BuildPokemonBattleWrapper()
        self.delegate = HealByRatioDelegate(2)

    def message(self):
        """ Test that the message is returned properly """
        messages = self.delegate.applyEffect(self.pkmn, None, None)

        message = self.pkmn.getHeader() + HealByRatioDelegate.message
        assert len(messages) == 1, "Should receive one message"
        assert messages[
            0] == message, "Should be the Pokmn's header and the Delegates message"
コード例 #20
0
class afterTurn(unittest.TestCase):
    """ Test that afterTurn returns correctly """
    def setUp(self):
        """ Build the Pkmn and Heal """
        self.pkmn = BuildPokemonBattleWrapper()

        self.message = " hurt."
        self.heal = PeriodicHeal(self.message)

    def message(self):
        """ Test the message is correct """
        message = self.heal.afterTurn(self.pkmn)
        assert message == [
            self.pkmn.getHeader() + self.message
        ], "Message should be the pokemon's name and the message given to the Heal."
コード例 #21
0
ファイル: leech_test.py プロジェクト: cloew/Pokemon-Project
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."
コード例 #22
0
class applyEffect(unittest.TestCase):
    """ Test cases of applyEffect """
    
    def  setUp(self):
        """ Build the Pkmn and Delegate for the test """
        self.pkmn = BuildPokemonBattleWrapper()
        self.delegate = HealByRatioDelegate(2)
        
    def message(self):
        """ Test that the message is returned properly """
        messages = self.delegate.applyEffect(self.pkmn, None, None) 
        
        message = self.pkmn.getHeader() + HealByRatioDelegate.message
        assert len(messages) == 1, "Should receive one message"
        assert messages[0] == message, "Should be the Pokmn's header and the Delegates message"
コード例 #23
0
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"
コード例 #24
0
ファイル: burn_test.py プロジェクト: cloew/Pokemon-Project
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"
コード例 #25
0
class stopAttack(unittest.TestCase):
    """ Test cases of stopAttack """
    
    def  setUp(self):
        """ Build the Ability and Pkmn for the test """
        self.ability = SkipTurnAbility(None)
        self.pkmn = BuildPokemonBattleWrapper()
        
    def stop(self):
        """ Test that the ability returns correctly when it should stop """
        self.ability.stop = 0
        stop, messages = self.ability.stopAttack(self.pkmn)
        
        assert stop, "Should stop"
        assert messages == [self.pkmn.getHeader() + SkipTurnAbility.message], "Should receive message that the Pkmn is loafing"
        
    def noStop(self):
        """ Test that the ability returns correctly when it should not stop """
        self.ability.stop = 1
        stop, messages = self.ability.stopAttack(self.pkmn)
        
        assert not stop, "Should not stop"
        assert messages == [], "Should not receive any messages"
コード例 #26
0
ファイル: burn_test.py プロジェクト: TimChau/Pokemon-Project
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"
コード例 #27
0
class stopAttack(unittest.TestCase):
    """ Test cases of stopAttack """
    def setUp(self):
        """ Build the Ability and Pkmn for the test """
        self.ability = SkipTurnAbility(None)
        self.pkmn = BuildPokemonBattleWrapper()

    def stop(self):
        """ Test that the ability returns correctly when it should stop """
        self.ability.stop = 0
        stop, messages = self.ability.stopAttack(self.pkmn)

        assert stop, "Should stop"
        assert messages == [
            self.pkmn.getHeader() + SkipTurnAbility.message
        ], "Should receive message that the Pkmn is loafing"

    def noStop(self):
        """ Test that the ability returns correctly when it should not stop """
        self.ability.stop = 1
        stop, messages = self.ability.stopAttack(self.pkmn)

        assert not stop, "Should not stop"
        assert messages == [], "Should not receive any messages"
コード例 #28
0
class checkEncore(unittest.TestCase):
    """ Test cases of checkEncore """
    
    def  setUp(self):
        """ Build the Pkmn and Precondition Checker for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.environment = BattleEnvironment()
        
        self.attack = AttackFactory.getAttackAsNew("DIG")
        self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack)
        
        attack2 = AttackFactory.getAttackAsNew("TACKLE")
        self.preconditionChecker2 = PreconditionChecker(self.user, self.target, self.environment, attack2)
        
    def encore(self):
        """ Test that check encore returns correctly when the user has an encore  """
        encoreCount = 1
        self.user.encore = encoreCount
        stop, messages = self.preconditionChecker.checkEncore()
        
        message = [self.user.getHeader() + self.attack.effectDelegates[0].message]
        
        assert self.user.encore == encoreCount-1, "Encore should be decremented" 
        assert not stop, "Should never stop if have an encore"
        assert messages == [], "Should not receive any messages"
        
    def noEncore(self):
        """ Test that check encore returns correctly when the user has no encore """
        encoreCount = 0
        self.user.encore = encoreCount
        stop, messages = self.preconditionChecker2.checkEncore()
        
        assert self.user.encore == encoreCount, "Encore should not decrement when there is no encore"
        assert not stop, "Should never stop if have an encore"
        assert messages == [], "Should not receive any messages"
コード例 #29
0
ファイル: trap_test.py プロジェクト: cloew/Pokemon-Project
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."