def test_each_wobble(self, name, catch_rates, expected_wobbles, expected_msg, mock_ball): mock_ball.Ultra.catch_modifier = 100 for catch_rate in catch_rates: pokemon = Pokemon(catch_rate=catch_rate) wobbles, msg = pokemon.animate(mock_ball.Ultra) self.assertEqual(wobbles, expected_wobbles) self.assertEqual(msg, expected_msg)
def test_status(self): # Should default to normal test_pokemon1 = Pokemon() self.assertEqual(test_pokemon1.status, Status.NORMAL) # Should use whatever's passed in test_pokemon1 = Pokemon(status=Status.BURNED) self.assertEqual(test_pokemon1.status, Status.BURNED)
def test_hpcheck(self, ballcheck, hpcheck, mock_rand): """An HP check greater than the random value wil catch.""" ballcheck.return_value = 10 hpcheck.return_value = 75 mock_rand.return_value = 70 self.assertTrue(Pokemon(catch_rate=35).catch(Ball.POKE)) # Equal values should catch hpcheck.return_value = 70 self.assertTrue(Pokemon(catch_rate=35).catch(Ball.POKE))
def test_pokeball(self, mock_rand): mock_rand.return_value = 35 test_pokemon = Pokemon(status=Status.BURNED) # This should simply be the random result minus the status effect self.assertEqual(test_pokemon._catch_ballcheck(Ball.POKE), 23) # Random should be called with the pokeball's range mock_rand.assert_called_with(0, 255) # A frozen status should lower check value test_pokemon.status = Status.FROZEN self.assertEqual(test_pokemon._catch_ballcheck(Ball.POKE), 10)
def test_get_hp_ivs(self, mock_ivs): """Test that we only call get_hpi_ivs when no hp_ivs are passed in.""" # Create a new pokemon while passing IVs test_pokemon1 = Pokemon(hp_ivs=10) self.assertFalse(mock_ivs.called) self.assertEqual(test_pokemon1._hp_ivs, 10) # Passing no IVs will cause get_hp_ivs to be called mock_ivs.return_value = 999 test_pokemon2 = Pokemon() self.assertTrue(mock_ivs.called) self.assertEqual(test_pokemon2._hp_ivs, 999)
def test_randoms(self): for i in range(1000): # Technically this could miss a case where it generates outside # But the idea is to hopefully catch any obvious failures. # Testing random is hard. hp_ivs = Pokemon.get_hp_ivs() self.assertGreaterEqual(hp_ivs, 0) self.assertLessEqual(hp_ivs, 15)
def test_same_values(self, mock_rand): """Test that odd and even values return either 0 or 15.""" for i in range(16): mock_rand.return_value = i if i % 2 == 0: expected = 0 else: expected = 15 self.assertEqual(Pokemon.get_hp_ivs(), expected)
def test_full_hp(self): test_pokemon = Pokemon() test_pokemon.max_hp = 100 test_pokemon.current_hp = 100 self.assertEqual(test_pokemon._catch_hpcheck(Ball.POKE), 85) # Great ball is a good test because it performs integer rounding self.assertEqual(test_pokemon._catch_hpcheck(Ball.GREAT), 127)
def test_low_hp(self): # Low hp values should be higher than the high hp values test_pokemon = Pokemon() test_pokemon.max_hp = 10 test_pokemon.current_hp = 2 self.assertEqual(test_pokemon._catch_hpcheck(Ball.POKE), 212) self.assertEqual(test_pokemon._catch_hpcheck(Ball.GREAT), 255)
def test_ghost_marowak(self): """Test ghost marowak is uncatchable.""" test_pokemon = Pokemon(is_ghost_marowak=True) self.assertFalse(test_pokemon.catch(Ball.MASTER))
def test_bit_combination(self, name, rand_vals, expected, mock_rand): mock_rand.side_effect = rand_vals self.assertEqual(Pokemon.get_hp_ivs(), expected)
def test_negative_check(self, mock_rand): mock_rand.return_value = 0 test_pokemon = Pokemon(status=Status.BURNED) # Simply testing that negative values are possible self.assertEqual(test_pokemon._catch_ballcheck(Ball.POKE), -12)
def test_fail_all(self, ballcheck, hpcheck, mock_rand): """When all checks fail, catching will fail.""" ballcheck.return_value = 10 hpcheck.return_value = 75 mock_rand.return_value = 80 self.assertFalse(Pokemon(catch_rate=35).catch(Ball.POKE))
def test_ballcheck_catchrate(self, ballcheck): """A ballcheck higher than the pokemon's catchrate will always fail.""" ballcheck.return_value = 70 self.assertFalse(Pokemon(catch_rate=35).catch(Ball.POKE))
def test_max_hp(self, mock_calc_hp): """Max HP should simply be set as the result of calculate_hp.""" mock_calc_hp.return_value = 99999 test_pokemon = Pokemon() self.assertEqual(test_pokemon.max_hp, 99999)
def test_name(self): self.assertEqual(Pokemon().name, "Pokemon") # Name should just pass through self.assertEqual(Pokemon(name="Scyther").name, "Scyther")
def test_minimum(self): """Test impossible minimum case.""" self.assertEqual(Pokemon.calculate_hp(0, 0, 1), 11)
def test_pokemon_values(self, name, base_hp, hp_ivs, level, expected): """Test real world values.""" self.assertEqual(Pokemon.calculate_hp(base_hp, hp_ivs, level), expected)
def test_masterball(self): """Test masterballs always catch.""" self.assertTrue(Pokemon().catch(Ball.MASTER))
def test_negative_ballcheck(self, ballcheck): """Test a negative ballcheck higher will always catch.""" ballcheck.return_value = -10 self.assertTrue(Pokemon().catch(Ball.POKE))
""" import time import ipdb from scyther.ball import Ball from scyther.pokemon import Pokemon from scyther.status import Status # Create a scyther to play around with SCYTHER = Pokemon( base_hp=70, hp_ivs=None, level=25, catch_rate=45, status=Status.NORMAL, name="Scyther", is_ghost_marowak=False ) def emulate(ball=Ball.poke): if SCYTHER.catch(ball): wobbles = 4 message = "{} Caught successfully!".format(SCYTHER.name) else: wobbles, message = SCYTHER.animate(ball) for wobble in range(wobbles): print("Wobble...")