def test_animal_should_die_if_power_equal_0(self): tiger = Predator(power=100, speed=70) self.jungle.add_animal(tiger) self.assertTrue(self.jungle.animals) tiger.current_power = 0 tiger.eat(self.jungle) self.assertFalse(self.jungle.animals)
def test_predator_try_to_hunt_someone_stronger(self): dog = Predator(power=10, speed=70) elephant = Herbivorous(power=100, speed=40) self.jungle.add_animal(elephant) dog.eat(self.jungle) self.assertEqual(dog.current_power, 7) self.assertEqual(elephant.current_power, 70)
def test_predator_try_to_hunt_someone_quicker(self): tiger = Predator(power=100, speed=70) horse = Herbivorous(power=100, speed=100) self.jungle.add_animal(horse) tiger.eat(self.jungle) self.assertEqual(tiger.current_power, 70) self.assertEqual(horse.current_power, 70)
def test_jungle_is_iterable(self): jungle = Jungle() animals = [Predator(power=10, speed=70), Predator(power=5, speed=40)] for animal in animals: jungle.add_animal(animal) try: animals_from_jungle = [a for a in jungle] self.assertEqual(animals, animals_from_jungle) except TypeError: self.assertTrue(False, "Jungle is not iterable")
def test__should_implement_all_abstract_methods(self): error_was_raised = False try: Predator(100, 100) except TypeError: error_was_raised = True self.assertFalse(error_was_raised)
def test_remove_animal(self): jungle = Jungle() dog = Predator(power=10, speed=70) jungle.add_animal(dog) self.assertDictEqual(jungle.animals, {dog.id: dog}) jungle.remove_animal(dog) self.assertDictEqual(jungle.animals, {})
def test_predator_catch_himself(self): tiger = Predator(power=100, speed=70) self.jungle.add_animal(tiger) tiger.eat(self.jungle) self.assertEqual(tiger.current_power, 70)