def test_hungry_delay(self): # Add very hungry caterpi- um, ant very_hungry = ants.HungryAnt() very_hungry.time_to_digest = 0 place = self.colony.places["tunnel_0_0"] place.add_insect(very_hungry) # Eat all the bees! for _ in range(100): place.add_insect(ants.Bee(3)) for _ in range(100): very_hungry.action(self.colony) self.assertIs(0, len(place.bees), "Digestion time not looked up on the instance")
def test_hungry_eats_and_digests(self): hungry = ants.HungryAnt() super_bee, super_pal = ants.Bee(1000), ants.Bee(1) place = self.colony.places['tunnel_0_0'] place.add_insect(hungry) place.add_insect(super_bee) hungry.action(self.colony) self.assertIs(0, super_bee.armor, 'HungryAnt didn\'t eat') place.add_insect(super_pal) for _ in range(3): hungry.action(self.colony) self.assertIs(1, super_pal.armor, 'HungryAnt didn\'t digest') hungry.action(self.colony) self.assertIs(0, super_pal.armor, 'HungryAnt didn\'t eat again')
def test_hungry_eats_and_digests(self): hungry = ants.HungryAnt() super_bee, super_pal = ants.Bee(1000), ants.Bee(1) place = self.colony.places["tunnel_0_0"] place.add_insect(hungry) place.add_insect(super_bee) hungry.action(self.colony) self.assertEqual(0, super_bee.armor, "HungryAnt didn't eat") place.add_insect(super_pal) for _ in range(3): hungry.action(self.colony) self.assertEqual(1, super_pal.armor, "HungryAnt didn't digest") hungry.action(self.colony) self.assertEqual(0, super_pal.armor, "HungryAnt didn't eat again")
def test_hungry_waits(self): """If you get an IndexError (not an AssertionError) when running this test, it"s possible that your HungryAnt is trying to eat a bee when no bee is available. """ hungry = ants.HungryAnt() place = self.colony.places["tunnel_0_0"] place.add_insect(hungry) # Wait a few turns before adding Bee for _ in range(5): hungry.action(self.colony) bee = ants.Bee(3) place.add_insect(bee) hungry.action(self.colony) self.assertIs(0, bee.armor, "HungryAnt didn't eat")
def test_hungry_delay(self): #Add very hungry cater- um, ant very_hungry = ants.HungryAnt() very_hungry.time_to_digest = 0 place = self.colony.places['tunnel_0_0'] place.add_insect(very_hungry) #Add many bees for _ in range(100): place.add_insect(ants.Bee(3)) #Eat many bees for _ in range(100): very_hungry.action(self.colony) self.assertIs(0, len(place.bees), 'Digestion time should not be static')
def test_hungry_parameters(self): hungry = ants.HungryAnt() self.assertIs(4, ants.HungryAnt.food_cost, 'HungryAnt has wrong cost') self.assertIs(1, hungry.armor, 'HungryAnt has wrong armor')
def test_hungry_parameters(self): hungry = ants.HungryAnt() self.assertEqual(4, ants.HungryAnt.food_cost, "HungryAnt has wrong cost") self.assertEqual(1, hungry.armor, "HungryAnt has wrong armor")