def test_meat_for_carnivores(self): jungle = Jungle() jungle.add_animals([{ 'species': 'Herbivore', 'age': 10, 'weight': 100 }]) assert type(jungle.meat_for_carnivores) is float or \ type(jungle.meat_for_carnivores) is int assert jungle.meat_for_carnivores == 100
def test_die(self, jungle_many_animals, carnivore_list): num_animals = jungle_many_animals.num_animals jungle_many_animals.die() assert num_animals > jungle_many_animals.num_animals jungle = Jungle() jungle.add_animals(carnivore_list) carnivore0 = jungle.carnivores[0] carnivore0._fitness = 0 carnivore0._compute_fitness = False carnivore1 = jungle.carnivores[1] carnivore1._fitness = 1 carnivore1._compute_fitness = False jungle.die() assert carnivore0 not in jungle.carnivores assert carnivore1 in jungle.carnivores
def test_add_animals(self, animal_list): jungle = Jungle() jungle.add_animals(animal_list) assert jungle.num_herbivores == 2 assert jungle.num_carnivores == 1 assert jungle.num_animals == len(animal_list) herbivore0 = jungle.herbivores[0] herbivore1 = jungle.herbivores[1] carnivore0 = jungle.carnivores[0] assert herbivore0.age == animal_list[0]['age'] assert herbivore0.weight == animal_list[0]['weight'] assert herbivore1.age == animal_list[1]['age'] assert herbivore1.weight == animal_list[1]['weight'] assert carnivore0.age == animal_list[2]['age'] assert carnivore0.weight == animal_list[2]['weight'] animal_list_with_wrong_parameter = [{ 'species': 'Carnivore', 'age': 0.5, 'weight': 100 }] with pytest.raises(ValueError): jungle.add_animals(animal_list_with_wrong_parameter) animal_list_with_wrong_parameter = [{ 'species': 'Carnivore', 'age': 3, 'weight': -10 }] with pytest.raises(ValueError): jungle.add_animals(animal_list_with_wrong_parameter)