コード例 #1
0
 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")
コード例 #2
0
 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')
コード例 #3
0
 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")
コード例 #4
0
 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")
コード例 #5
0
ファイル: tests.py プロジェクト: arunalotla/cs61a-ants
 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')
コード例 #6
0
 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')
コード例 #7
0
 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")