def test_inheritance(self): """Tests to see if the Long and Short Throwers are actually using the inherited action from the ThrowerAnt. """ old_thrower_action = ants.ThrowerAnt.action old_throw_at = ants.ThrowerAnt.throw_at def new_thrower_action(self, colony): raise NotImplementedError() def new_throw_at(self, target): raise NotImplementedError() failed_long = 0 try: # Test action ants.ThrowerAnt.action = new_thrower_action test_long = ants.LongThrower() test_long.action(self.colony) except NotImplementedError: failed_long += 1 finally: ants.ThrowerAnt.action = old_thrower_action try: # Test throw_at ants.ThrowerAnt.throw_at = new_throw_at test_long = ants.LongThrower() test_bee = ants.Bee(1) test_long.throw_at(test_bee) except NotImplementedError: failed_long += 1 finally: ants.ThrowerAnt.throw_at = old_throw_at if failed_long < 2: self.fail(msg="LongThrower is not using inheritance") failed_short = 0 try: # Test action ants.ThrowerAnt.action = new_thrower_action test_short = ants.ShortThrower() test_short.action(self.colony) except NotImplementedError: failed_short += 1 finally: ants.ThrowerAnt.action = old_thrower_action try: # Test throw_at ants.ThrowerAnt.throw_at = new_throw_at test_short = ants.ShortThrower() test_bee = ants.Bee(1) test_short.throw_at(test_bee) except NotImplementedError: failed_short += 1 finally: ants.ThrowerAnt.throw_at = old_throw_at if failed_short < 2: self.fail(msg="ShortThrower is not using inheritance")
def test_thrower_parameters(self): short_t = ants.ShortThrower() long_t = ants.LongThrower() self.assertEqual(3, ants.ShortThrower.food_cost, 'ShortThrower has wrong cost') self.assertEqual(3, ants.LongThrower.food_cost, 'LongThrower has wrong cost') self.assertEqual(1, short_t.armor, 'ShortThrower has wrong armor') self.assertEqual(1, long_t.armor, 'LongThrower has wrong armor')
def test_short(self): error_msg = 'ShortThrower has the wrong range' ant = ants.ShortThrower() self.colony.places['tunnel_0_0'].add_insect(ant) out_of_range, in_range = ants.Bee(2), ants.Bee(2) self.colony.places['tunnel_0_3'].add_insect(out_of_range) self.colony.places['tunnel_0_2'].add_insect(in_range) ant.action(self.colony) self.assertIs(in_range.armor, 1, error_msg) self.assertIs(out_of_range.armor, 2, error_msg)
def test_short(self): error_msg = "ShortThrower has the wrong range" ant = ants.ShortThrower() self.colony.places["tunnel_0_0"].add_insect(ant) out_of_range, in_range = ants.Bee(2), ants.Bee(2) self.colony.places["tunnel_0_3"].add_insect(out_of_range) self.colony.places["tunnel_0_2"].add_insect(in_range) ant.action(self.colony) self.assertEqual(in_range.armor, 1, error_msg) self.assertEqual(out_of_range.armor, 2, error_msg)
def test_instance_range(self): error_msg = "Range is not looked up on the instance" #Buff ant range ant = ants.ShortThrower() ant.max_range = 10 self.colony.places["tunnel_0_0"].add_insect(ant) #Place a bee out of normal range bee = ants.Bee(2) self.colony.places["tunnel_0_6"].add_insect(bee) ant.action(self.colony) self.assertIs(bee.armor, 1, error_msg)
def test_range(self): error_msg = 'Range should not be static' #Buff ant range ant = ants.ShortThrower() ant.max_range = 10 self.colony.places['tunnel_0_0'].add_insect(ant) #Place a bee out of normal range bee = ants.Bee(2) self.colony.places['tunnel_0_6'].add_insect(bee) ant.action(self.colony) self.assertIs(bee.armor, 1, error_msg)