コード例 #1
0
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"
コード例 #2
0
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"
コード例 #3
0
class checkFaint(unittest.TestCase):
    """ Test cases of checkFaint """
    
    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 fainted(self):
        """ Test that check faint returns correctly when the user has fainted  """
        self.user.faint()
        stop, messages = self.preconditionChecker.checkFaint()
        
        assert stop, "Should stop if the user is fainted"
        assert messages == [],  "Should receive the messages for the actual attack"
        
    def notFainted(self):
        """ Test that check faint returns correctly when the user has not fainted  """
        stop, messages = self.preconditionChecker.checkFaint()
        
        assert not stop, "Should not stop if the user is using its lock"
        assert messages == [], "Should not receive any messages"
コード例 #4
0
class tryToApplyEffect(unittest.TestCase):
    """ Test cases of tryToApplyEffect """
    
    def  setUp(self):
        """ Build the Pkmn and Effect for the test """
        self.delegate = EffectDelegate()
        self.delegate.faintHandler = BuildFaintHandler("EITHER")
        
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
    def userFainted(self):
        """ Test that if the user is fainted the effect does nothing """
        self.user.faint()
        messages = self.delegate.tryToApplyEffect(self.user, self.target, None)
        assert messages == [], "Effect should do nothing if the user has fainted"
        
    def targetFainted(self):
        """ Test that if the target is fainted the effect does nothing """
        self.target.faint()
        messages = self.delegate.tryToApplyEffect(self.user, self.target, None)
        assert messages == [], "Effect should do nothing if the target has fainted"
        
    def applyEffectCalled(self):
        """ Test that applyEffect is called otherwise """
        messages = self.delegate.tryToApplyEffect(self.user, self.target, None)
        assert messages == [EffectDelegate.message], "Effect should call applyEffect"
コード例 #5
0
class cantHandle(unittest.TestCase):
    """ Test cases of cantHandle """
    def setUp(self):
        """ Build the FaintDelegate for the test """
        self.handler = EitherFaintDelegate()
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()

    def user(self):
        """ Test that it can handle the user fainting """
        self.user.faint()
        cantHandle = self.handler.cantHandle(user=self.user,
                                             target=self.target)
        assert cantHandle, "Shouldn't handle when the user faints"

    def target(self):
        """ Test that it can't handle the target fainting """
        self.target.faint()
        cantHandle = self.handler.cantHandle(user=self.user,
                                             target=self.target)
        assert cantHandle, "Shouldn't handle when the target faints"

    def both(self):
        """ Test that it can't handle both pkmn fainting """
        self.user.faint()
        self.target.faint()
        cantHandle = self.handler.cantHandle(user=self.user,
                                             target=self.target)
        assert cantHandle, "Shouldn't handle when both pkmn faints"

    def neither(self):
        """ Test that it can handle neither pkmn fainting """
        cantHandle = self.handler.cantHandle(user=self.user,
                                             target=self.target)
        assert not cantHandle, "Should handle when neither faints"
コード例 #6
0
class cantHandle(unittest.TestCase):
    """ Test cases of cantHandle """
    
    def  setUp(self):
        """ Build the FaintDelegate for the test """
        self.handler = EitherFaintDelegate()
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
    def user(self):
        """ Test that it can handle the user fainting """
        self.user.faint()
        cantHandle = self.handler.cantHandle(user = self.user, target = self.target)
        assert cantHandle, "Shouldn't handle when the user faints"
        
    def target(self):
        """ Test that it can't handle the target fainting """
        self.target.faint()
        cantHandle = self.handler.cantHandle(user = self.user, target = self.target)
        assert cantHandle, "Shouldn't handle when the target faints"
        
    def both(self):
        """ Test that it can't handle both pkmn fainting """
        self.user.faint()
        self.target.faint()
        cantHandle = self.handler.cantHandle(user = self.user, target = self.target)
        assert cantHandle, "Shouldn't handle when both pkmn faints"
        
    def neither(self):
        """ Test that it can handle neither pkmn fainting """
        cantHandle = self.handler.cantHandle(user = self.user, target = self.target)
        assert not cantHandle, "Should handle when neither faints"
コード例 #7
0
class cantHandle(unittest.TestCase):
    """ Test cases of cantHandle """
    def setUp(self):
        """ Build the FaintDelegate for the test """
        self.handler = UserFaintDelegate()
        self.user = BuildPokemonBattleWrapper()

    def userFainted(self):
        """ Test that it can't handle the user fainting """
        self.user.faint()
        cantHandle = self.handler.cantHandle(user=self.user)
        assert cantHandle, "Shouldn't handle when the user is fainted"

    def userNotFainted(self):
        """ Test that it can handle when the user is not fainted """
        cantHandle = self.handler.cantHandle(user=self.user)
        assert not cantHandle, "Should handle when the user is not fainted"
コード例 #8
0
class cantHandle(unittest.TestCase):
    """ Test cases of cantHandle """
    
    def  setUp(self):
        """ Build the FaintDelegate for the test """
        self.handler = UserFaintDelegate()
        self.user = BuildPokemonBattleWrapper()
        
    def userFainted(self):
        """ Test that it can't handle the user fainting """
        self.user.faint()
        cantHandle = self.handler.cantHandle(user = self.user)
        assert cantHandle, "Shouldn't handle when the user is fainted"
        
    def userNotFainted(self):
        """ Test that it can handle when the user is not fainted """
        cantHandle = self.handler.cantHandle(user = self.user)
        assert not cantHandle, "Should handle when the user is not fainted"
コード例 #9
0
class attemptAfterTurn(unittest.TestCase):
    """ Test cases of attemptAfterTurn """
    
    def  setUp(self):
        """ Build the Pkmn and AfterTurnEffect for the test """
        self.effect = AfterTurnEffect()
        self.effect.faintHandler = BuildFaintHandler("USER")
        self.pkmn = BuildPokemonBattleWrapper()
        
    def fainted(self):
        """ Test that the Effect is not performed when the pkmn has fainted """
        self.pkmn.faint()
        messages = self.effect.attemptAfterTurn(self.pkmn)
        assert messages == [], "Should receive no messages since nothing was performed"
        
    def notFainted(self):
        """ Test that the Effect is performed when the pkmn has fainted """
        messages = self.effect.attemptAfterTurn(self.pkmn)
        assert messages == [AfterTurnEffect.message], "Should receive messages from afterTurn function"
コード例 #10
0
class attemptAfterTurn(unittest.TestCase):
    """ Test cases of attemptAfterTurn """
    def setUp(self):
        """ Build the Pkmn and AfterTurnEffect for the test """
        self.effect = AfterTurnEffect()
        self.effect.faintHandler = BuildFaintHandler("USER")
        self.pkmn = BuildPokemonBattleWrapper()

    def fainted(self):
        """ Test that the Effect is not performed when the pkmn has fainted """
        self.pkmn.faint()
        messages = self.effect.attemptAfterTurn(self.pkmn)
        assert messages == [], "Should receive no messages since nothing was performed"

    def notFainted(self):
        """ Test that the Effect is performed when the pkmn has fainted """
        messages = self.effect.attemptAfterTurn(self.pkmn)
        assert messages == [
            AfterTurnEffect.message
        ], "Should receive messages from afterTurn function"
コード例 #11
0
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"
コード例 #12
0
class cantHandle(unittest.TestCase):
    """ Test cases of cantHandle """
    
    def  setUp(self):
        """ Build the FaintDelegate for the test """
        self.handler = SourceFaintDelegate()
        self.source = BuildPokemonBattleWrapper()
        self.user = BuildPokemonBattleWrapper()
        self.effect = BuildEffectDelegate()
        
        self.effect.source = self.source
        self.user.secondaryEffects.append(self.effect)
        
    def userFainted(self):
        """ Test that it can't handle the user fainting """
        self.user.faint()
        cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect)
        assert cantHandle, "Shouldn't handle when the user is fainted"
        assert self.effect in self.user.secondaryEffects, "The effect shouldnot be removed from the user"
        
    def userNotFainted(self):
        """ Test that it can handle when the user is not fainted """
        cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect)
        assert not cantHandle, "Should handle when the user is not fainted"
        assert self.effect in self.user.secondaryEffects, "The effect should not be removed from the user"
        
    def sourceFainted(self):
        """ Test that it can't handle the source fainting """
        self.source.faint()
        cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect)
        assert cantHandle, "Shouldn't handle when the source is fainted"
        assert not self.effect in self.user.secondaryEffects, "The effect should be removed from the user"
        
    def sourceNotFainted(self):
        """ Test that it can handle when the user is not fainted """
        cantHandle = self.handler.cantHandle(user = self.user, effect = self.effect)
        assert not cantHandle, "Should handle when the source is not fainted"
        assert self.effect in self.user.secondaryEffects, "The effect should not be removed from the user"
コード例 #13
0
class diverge(unittest.TestCase):
    """ Test cases of diverge """
    def setUp(self):
        """ Build the Pkmn and Effects for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.divergeEffects = [BuildEffectDelegate(), BuildEffectDelegate()]
        self.normalEffects = [BuildEffectDelegate()]
        self.message = BuildEffectDelegate().message

        self.delegate = DivergeOnFaintDelegate(self.divergeEffects,
                                               self.normalEffects)

    def fainted(self):
        """ Test that the diverge effects are called when the target has fainted """
        self.target.faint()
        diverge = self.delegate.diverge(self.user, self.target)
        assert diverge, "Should diverge"

    def notFainted(self):
        """ Test that the regular effects are called when the target is not fainted """
        diverge = self.delegate.diverge(self.user, self.target)
        assert not diverge, "Should not diverge when the target is not fainted"
コード例 #14
0
class diverge(unittest.TestCase):
    """ Test cases of diverge """
    
    def  setUp(self):
        """ Build the Pkmn and Effects for the test """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        self.divergeEffects = [BuildEffectDelegate(), BuildEffectDelegate()]
        self.normalEffects = [BuildEffectDelegate()]
        self.message = BuildEffectDelegate().message
        
        self.delegate = DivergeOnFaintDelegate(self.divergeEffects, self.normalEffects)
        
    def fainted(self):
        """ Test that the diverge effects are called when the target has fainted """
        self.target.faint()
        diverge = self.delegate.diverge(self.user, self.target)
        assert diverge, "Should diverge"
        
    def notFainted(self):
        """ Test that the regular effects are called when the target is not fainted """
        diverge = self.delegate.diverge(self.user, self.target)
        assert not diverge, "Should not diverge when the target is not fainted"