class compareSpeed(unittest.TestCase): """ Test cases of compareSpeed """ def setUp(self): """ Build the Action for the test """ pkmn1 = BuildPokemonBattleWrapper() pkmn2 = BuildPokemonBattleWrapper() pkmn1.setStat("SPD", 30) pkmn2.setStat("SPD", 20) self.fastAction = BuildBattleAction(user = pkmn1) self.slowAction = BuildBattleAction(user = pkmn2) self.usedRandRange = False def less(self): """ Test that lower priorities return correctly """ cmp = self.slowAction.compareSpeed(self.fastAction) assert cmp == -1, "Should return -1 when the speed is less" def more(self): """ Test that higher priorities return correctly """ cmp = self.fastAction.compareSpeed(self.slowAction) assert cmp == 1, "Should return 1 when the speed is more" def tie(self): """ Test that higher priorities return correctly """ cmp = self.fastAction.compareSpeed(self.fastAction, random=self) assert self.usedRandRange, "Should have picked a random action to win" assert range(self.bottom, self.top, self.step) == [-1, 1], "Should have tried to pick valid random value" def randrange(self, bottom, top, step): self.bottom = bottom self.top = top self.step = step self.usedRandRange = True