def test_fight(self): # Define the example for the test example_Predator = animal.Predator('example_Predator', 40, 30) for weight, speed, result in self.TestCase_fight: test_Predator = animal.Predator('test_Predator', weight, speed) res = test_Predator.fight(example_Predator) self.assertEqual(res, result)
def test_chase(self): # Define the example for the test example_Prey = animal.Prey('example_Prey', 40, 30) for weight, speed, result in self.TestCase_chase: test_Predator = animal.Predator('test_Predator', weight, speed) res = test_Predator.chase(example_Prey) self.assertEqual(res, result)
# predator will chase predator 2 print(name1 + " starts chasing") result = animal1.chase if result: print(name1 + " overpowered the " + name2) print(name1 + " ate " + name2) else: print("But " + name2 + " was too fast") print(name1 + " left emptyhanded") if isinstance(animal1, animal.Prey): if isinstance(animal2, animal.Predator): print(name1 + " starts running") result = animal1.run(animal2) if result: print(name1 + " gets to see another day") else: print(name1 + " got eaten by " + name2) if isinstance(animal2, animal.Prey): print( "The 2 animals greeted each other and moved on with their day") if __name__ == '__main__': # initialise a few animals wolf = animal.Predator('wolf', 30, 50) bear = animal.Predator('bear', 50, 30) encounter(wolf, bear) rabbit = animal.Prey('rabbit', 20, 50) encounter(wolf, rabbit) encounter(rabbit, rabbit)