def test_inheritance(self): """Tests to see if the ScubaThrower is actually using the inherited action from the ThrowerAnt. """ old_thrower_action = ants.ThrowerAnt.action def new_thrower_action(self, colony): raise NotImplementedError() old_throw_at = ants.ThrowerAnt.throw_at def new_throw_at(self, target): raise NotImplementedError() failed_scuba = 0 try: ants.ThrowerAnt.action = new_thrower_action test_scuba = ants.ScubaThrower() test_scuba.action(self.colony) except NotImplementedError: failed_scuba += 1 finally: ants.ThrowerAnt.action = old_thrower_action try: ants.ThrowerAnt.throw_at = new_throw_at test_scuba = ants.ScubaThrower() test_bee = ants.Bee(1) test_scuba.throw_at(test_bee) except NotImplementedError: failed_scuba += 1 finally: ants.ThrowerAnt.throw_at = old_throw_at if failed_scuba < 2: self.fail(msg="ScubaThrower is not using inheritance!")
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)
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)
def test_scuba_on_land(self): place1 = self.colony.places['tunnel_0_0'] place2 = self.colony.places['tunnel_0_4'] ant = ants.ScubaThrower() bee = ants.Bee(3) place1.add_insect(ant) place2.add_insect(bee) ant.action(self.colony) self.assertIs(2, bee.armor, 'ScubaThrower doesn\'t throw on land')
def test_scuba_on_land(self): place1 = self.colony.places["tunnel_0_0"] place2 = self.colony.places["tunnel_0_4"] ant = ants.ScubaThrower() bee = ants.Bee(3) place1.add_insect(ant) place2.add_insect(bee) ant.action(self.colony) self.assertEqual(2, bee.armor, "ScubaThrower doesn't throw on land")
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")
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")
def test_scuba_parameters(self): scuba = ants.ScubaThrower() self.assertIs(5, ants.ScubaThrower.food_cost, 'ScubaThrower has wrong cost') self.assertIs(1, scuba.armor, 'ScubaThrower has wrong armor')
def test_scuba_parameters(self): scuba = ants.ScubaThrower() self.assertEqual(5, ants.ScubaThrower.food_cost, "ScubaThrower has wrong cost") self.assertEqual(1, scuba.armor, "ScubaThrower has wrong armor")