def test_no_birth_weight_to_low(): """Test that the birth function returns None if the weight of the animal is to low.""" herb = Herbivore(5, 15) carn = Carnivore(5, 15) nr_animals = 2 assert herb.birth(nr_animals) is None assert carn.birth(nr_animals) is None
def test_birth(mocker): """Test that the animals can't reproduce if only one animal is present regardless of random value.""" mocker.patch("numpy.random.random", return_value=0) herb = Herbivore(5, 35) carn = Carnivore(5, 30) nr_animals = 1 assert herb.birth(nr_animals) is None assert carn.birth(nr_animals) is None mocker.patch("numpy.random.random", return_value=1) herb = Herbivore(5, 35) carn = Carnivore(5, 30) nr_animals = 1 assert herb.birth(nr_animals) is None assert carn.birth(nr_animals) is None
def test_no_birth_probability(mocker): """Test that the animal should not give birth if the random value is higher than the birth probability.""" mocker.patch("numpy.random.random", return_value=1) herb = Herbivore(5, 35) carn = Carnivore(5, 30) nr_animals = 10 assert herb.birth(nr_animals) is None assert carn.birth(nr_animals) is None
def test_no_birth_baby_to_heavy(mocker): """Test that the animal doesn't give birth if the baby is heavier than the mother.""" mocker.patch("numpy.random.normal", return_value=50) mocker.patch("numpy.random.random", return_value=0) herb = Herbivore(5, 35) carn = Carnivore(5, 30) nr_animals = 10 assert herb.birth(nr_animals) is None assert carn.birth(nr_animals) is None
def test_mother_loose_weight(mocker): """Test that the mother looses weight according to the birth weight and sat parameters when giving birth.""" mocker.patch("numpy.random.normal", return_value=20) mocker.patch("numpy.random.random", return_value=0) herbivore = Herbivore(5, 35) carnivore = Carnivore(5, 30) nr_animals = 10 new_herb = herbivore.birth(nr_animals) new_carn = carnivore.birth(nr_animals) assert herbivore.weight == 11 assert carnivore.weight == 8 assert new_herb.age == 0, "New baby should be age zero" assert new_carn.age == 0, "New baby should be age zero"