コード例 #1
0
 def test_water_deadliness(self):
     error_msg = 'Water does not kill non-watersafe Insects'
     test_ant = ants.HarvesterAnt()
     test_water = ants.Water('water_TestProblemA4_0')
     test_water.add_insect(test_ant)
     self.assertIsNot(test_ant, test_water.ant, msg=error_msg)
     self.assertIs(0, test_ant.armor, msg=error_msg)
コード例 #2
0
 def test_scuba(self):
     error_msg = "ScubaThrower sank"
     water = ants.Water("water")
     ant = ants.ScubaThrower()
     water.add_insect(ant)
     self.assertIs(water, ant.place, error_msg)
     self.assertEqual(1, ant.armor, error_msg)
コード例 #3
0
 def test_scuba(self):
     error_msg = 'ScubaThrower sank'
     water = ants.Water('water')
     ant = ants.ScubaThrower()
     water.add_insect(ant)
     self.assertIs(water, ant.place, error_msg)
     self.assertIs(1, ant.armor, error_msg)
コード例 #4
0
ファイル: tests.py プロジェクト: arunalotla/cs61a-ants
 def test_water_deadliness_2(self):
     error_msg = 'Water does not kill non-watersafe Insects'
     test_ants = [ants.Bee(1000000), ants.HarvesterAnt(), ants.Ant(), ants.ThrowerAnt()]
     test_ants[0].watersafe = False #Make the bee non-watersafe
     test_water = ants.Water('water_TestProblemA4_0')
     for test_ant in test_ants:
         test_water.add_insect(test_ant)
         self.assertIsNot(test_ant, test_water.ant, msg=error_msg)
         self.assertIs(0, test_ant.armor, msg=error_msg)
コード例 #5
0
 def test_scuba_in_water(self):
     water = ants.Water("water")
     water.entrance = self.colony.places["tunnel_0_1"]
     target = self.colony.places["tunnel_0_4"]
     ant = ants.ScubaThrower()
     bee = ants.Bee(3)
     water.add_insect(ant)
     target.add_insect(bee)
     ant.action(self.colony)
     self.assertIs(2, bee.armor, "ScubaThrower doesn't throw in water")
コード例 #6
0
 def test_water_deadliness_with_big_soggy_bee(self):
     error_msg = "Water does not hurt all non-watersafe Insects"
     test_ants = [
         ants.Bee(1000000),
         ants.HarvesterAnt(),
         ants.Ant(),
         ants.ThrowerAnt()
     ]
     test_ants[0].watersafe = False  # Make the Bee non-watersafe
     test_water = ants.Water("water_TestProblemA4_0")
     for test_ant in test_ants:
         test_water.add_insect(test_ant)
         self.assertIsNot(test_ant, test_water.ant, msg=error_msg)
         self.assertIs(0, test_ant.armor, msg=error_msg)
コード例 #7
0
    def test_scuba_in_water(self):
        #Create water
        water = ants.Water('water')
        #Link water up to a tunnel
        water.entrance = self.colony.places['tunnel_0_1']
        target = self.colony.places['tunnel_0_4']
        #Set up ant/bee
        ant = ants.ScubaThrower()
        bee = ants.Bee(3)
        water.add_insect(ant)
        target.add_insect(bee)

        ant.action(self.colony)
        self.assertIs(2, bee.armor, "ScubaThrower doesn't throw in water")
コード例 #8
0
 def test_water_inheritance_ant(self):
     error_msg = "Make sure to place the ant before killing it!"
     old_add_insect = ants.Place.add_insect
     def new_add_insect(self, insect):
         raise NotImplementedError()
     ants.Place.add_insect = new_add_insect
     test_ant = ants.HarvesterAnt()
     test_water = ants.Water('water_testProblemA4_0')
     failed = True
     try:
         test_water.add_insect(test_ant)
     except NotImplementedError:
         failed = False
     finally:
         ants.Place.add_insect = old_add_insect
     if failed:
         self.fail(msg=error_msg)
コード例 #9
0
 def test_water_inheritance(self):
     error_msg = "It seems Water.add_insect is not using inheritance!"
     old_add_insect = ants.Place.add_insect
     def new_add_insect(self, insect):
         raise NotImplementedError()
     ants.Place.add_insect = new_add_insect
     test_bee = ants.Bee(1)
     test_water = ants.Water('water_testProblemA4_0')
     failed = True
     try:
         test_water.add_insect(test_bee)
     except NotImplementedError:
         failed = False
     finally:
         ants.Place.add_insect = old_add_insect
     if failed:
         self.fail(msg=error_msg)
コード例 #10
0
ファイル: tests.py プロジェクト: arunalotla/cs61a-ants
 def test_inheritance(self):
     """This test assumes that you have passed test_water_safety.
     This test may or may not cause... unusual behavior in other tests.
     Comment it out if you're worried.
     """
     error_msg = "Water does not inherit Place behavior"
     place_ai_method = ants.Place.add_insect #Save Place.add_insect method
     #Replace with fake method
     def fake_ai_method(self, insect):
         insect.reduce_armor(2)
     ants.Place.add_insect = fake_ai_method
     #Test putting bee in water
     test_bee = ants.Bee(10)
     test_water = ants.Water('water_TestProblemA4_0')
     test_water.add_insect(test_bee)
     #Should activate fake method, reduce armor
     self.assertIs(8, test_bee.armor, error_msg)
     #Restore method
     ants.Place.add_insect = place_ai_method
コード例 #11
0
 def test_water_safety(self):
     error_msg = 'Water kills watersafe Insects'
     test_bee = ants.Bee(1)
     test_water = ants.Water('water_testProblemA4_0')
     test_water.add_insect(test_bee)
     self.assertIn(test_bee, test_water.bees, msg=error_msg)