def test_animal_death(self):
        lowland = Lowland()
        lowland.animals_allocate([{
            'species': 'Herbivore',
            'age': 5,
            'weight': 20
        } for _ in range(20)])
        lowland.animals_allocate([{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        } for _ in range(20)])

        carn_dying = lowland.present_carnivores[0]
        carn_dying.weight = 0

        herb_dying = lowland.present_herbivores[0]
        herb_dying.weight = 0

        lowland.animal_death()
        assert carn_dying not in lowland.present_carnivores
        assert herb_dying not in lowland.present_herbivores

        carn_not_dying = lowland.present_herbivores[4]
        carn_not_dying.weight = 10

        lowland.animal_death()
        assert carn_not_dying in lowland.present_herbivores
 def test_num_carnivores(self):
     lowland = Lowland()
     ini_animal = [{
         'species': 'Carnivore',
         'age': 5,
         'weight': 20
     } for _ in range(20)]
     lowland.animals_allocate(ini_animal)
     num_carn = lowland.num_carnivores
     assert num_carn > 0
    def test_procreation(self, mocker):
        mocker.patch('random.random', return_value=0.0)
        mocker.patch('random.gauss', return_value=5)
        lowland = Lowland()
        animals_carn = [{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        }, {
            'species': 'Carnivore',
            'age': 4,
            'weight': 15
        }, {
            'species': 'Carnivore',
            'age': 5,
            'weight': 25
        }]
        lowland.animals_allocate(animals_carn)
        num_carn = len(lowland.present_carnivores)
        for _ in range(100):
            lowland.procreation()

        num_carn_after_procreation = len(lowland.present_carnivores)

        assert num_carn < num_carn_after_procreation

        animals_herb = [{
            'species': 'Herbivore',
            'age': 5,
            'weight': 50
        }, {
            'species': 'Herbivore',
            'age': 3,
            'weight': 60
        }, {
            'species': 'Herbivore',
            'age': 5,
            'weight': 60
        }, {
            'species': 'Herbivore',
            'age': 10,
            'weight': 70
        }]
        lowland.animals_allocate(animals_herb)
        num_herb = len(lowland.present_herbivores)

        for _ in range(100):
            lowland.procreation()

        num_herb_after_procreation = len(lowland.present_herbivores)

        assert num_herb < num_herb_after_procreation
 def test_num_animals(self):
     lowland = Lowland()
     ini_herb = [{
         'species': 'Carnivore',
         'age': 5,
         'weight': 20
     } for _ in range(20)]
     ini_carn = [{
         'species': 'Carnivore',
         'age': 5,
         'weight': 20
     } for _ in range(20)]
     lowland.animals_allocate(ini_herb)
     lowland.animals_allocate(ini_carn)
     num_animals = lowland.num_animals
     assert num_animals > 0
    def test_feed_carn_with_herb(self):
        lowland = Lowland()

        lowland.animals_allocate([{
            'species': 'Herbivore',
            'age': 6,
            'weight': 20
        }, {
            'species': 'Herbivore',
            'age': 3,
            'weight': 7
        }, {
            'species': 'Herbivore',
            'age': 6,
            'weight': 6
        }, {
            'species': 'Herbivore',
            'age': 1,
            'weight': 3
        }])

        lowland.animals_allocate([{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        }, {
            'species': 'Carnivore',
            'age': 4,
            'weight': 15
        }, {
            'species': 'Carnivore',
            'age': 5,
            'weight': 25
        }])

        lowland.feed_carn_with_herb()
        sorted_phi_herb = [herb.phi for herb in lowland.present_herbivores]
        assert (sorted_phi_herb[0] < sorted_phi_herb[1] < sorted_phi_herb[2])

        available_herb = len(lowland.present_herbivores)
        for _ in range(100):
            lowland.feed_carn_with_herb()
        available_herb_after = len(lowland.present_herbivores)
        assert available_herb > available_herb_after

        sorted_phi_carn = [carn.phi for carn in lowland.present_carnivores]
        assert sorted_phi_carn[0] > sorted_phi_carn[1]
    def test_animal_allocates(self):
        lowland = Lowland()

        ini_animal = [{
            'species': 'Herbivore',
            'age': 5,
            'weight': 20
        } for _ in range(20)]
        lowland.animals_allocate(ini_animal)

        num_herb = len(lowland.present_herbivores)
        assert num_herb == 20

        add_new_herb = [{'species': 'Herbivore', 'age': 5, 'weight': 20}]
        lowland.animals_allocate(add_new_herb)
        assert len(lowland.present_herbivores) == 21

        ini_animal = [{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        } for _ in range(20)]
        lowland.animals_allocate(ini_animal)
        num_carn = len(lowland.present_carnivores)
        assert num_carn == 20

        ini_animal = {'species': 'Dog', 'age': 5, 'weight': 20}
        with pytest.raises(TypeError):
            SingleCell.animals_allocate(ini_animal)

        highland = Highland()
        add_herbs_to_island = [{
            'species': 'Herbivore',
            'age': 3,
            'weight': 10
        }, {
            'species': 'Herbivore',
            'age': 5,
            'weight': 14
        }, {
            'species': 'Herbivore',
            'age': 13,
            'weight': 23
        }]
        highland.animals_allocate(add_herbs_to_island)
        herbivore_0 = highland.present_herbivores[0]
        herbivore_1 = highland.present_herbivores[1]

        assert herbivore_0.age == add_herbs_to_island[0]['age']
        assert herbivore_0.weight == add_herbs_to_island[0]['weight']
        assert herbivore_1.age == add_herbs_to_island[1]['age']
        assert herbivore_1.weight == add_herbs_to_island[1]['weight']

        ini_animal = [{'species': 'Dog', 'age': 5, 'weight': 20}]
        with pytest.raises(TypeError):
            lowland.animals_allocate(ini_animal)
    def test_aging(self):
        lowland = Lowland()
        lowland.animals_allocate([{
            'species': 'Herbivore',
            'age': 5,
            'weight': 20
        } for _ in range(20)])
        lowland.animals_allocate([{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        } for _ in range(150)])

        herb = lowland.present_herbivores[0].age
        carn = lowland.present_carnivores[1].age

        lowland.aging()

        herb_aged = lowland.present_herbivores[0].age
        carn_aged = lowland.present_carnivores[1].age

        assert herb < herb_aged
        assert carn < carn_aged