def test_correct_fitness_calculated(self, example_properties_w_20): """ Checks that find_fitness method calculates correct value of fitness. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.fitness == approx(0.9983411986)
def test_correct_prob_death(self, example_properties_w_20): """ Asserts that prob_death calculates the correct probability of dying. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.prob_death() == approx(0.0014929212599999687)
def test_fitness_between_zero_and_one(self, example_properties_w_20): """ Checks that find_fitness method calculates a fitness between 0 and 1. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert 0 <= animal.fitness <= 1
def test_true_if_birth_prob_one(self, example_properties_w_40): """ Tests the will_birth_take_place method by checking if True is returned when the probability of giving birth is 1. """ animal = Animal(example_properties_w_40) animal.find_fitness() assert animal.will_birth_take_place(num_animals=6) is True
def test_correct_prob_of_birth(self, example_properties_w_40): """ Asserts that prob_give_birth calculates the correct probability of giving birth. """ animal = Animal(example_properties_w_40) animal.find_fitness() assert animal.prob_give_birth(num_animals=6) == 1
def test_correct_prob_of_moving(self, example_properties_w_20): """ Asserts that prob_of_animal_moving calculates the correct probability of moving. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.prob_of_animal_moving() == approx(0.3993364794)
def test_not_true_if_death_prob_is_one(self, example_properties_w_20): """ Assert that will_animal_live does not return True if probability of dying is one. """ animal = Animal(example_properties_w_20) animal.weight = 0 animal.find_fitness() assert animal.will_animal_live() is not True
def test_fitness_zero_if_weight_zero(self, example_properties_w_20): """ Checks that find_fitness method calculates a fitness of zero if weight of the animal is zero. """ animal = Animal(example_properties_w_20) animal.weight = 0 animal.find_fitness() assert animal.fitness == 0
def test_prob_of_birth_if_weight_less_than_limit(self, example_properties_w_20): """ Asserts that prob_give_birth returns a probability of zero if the mothers weight is less than the given limit. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.prob_give_birth(num_animals=6) == 0
def test_prob_of_birth_with_one_animal_in_cell(self, example_properties_w_20): """ Asserts that if there is only one animal in the cell, then the prob_give_birth method returns a probability of zero. """ animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.prob_give_birth(num_animals=1) == 0
def test_prob_death_is_one_if_fitness_zero(self, example_properties_w_20): """ Asserts that the probability calculated from prob_death is one if fitness equals zero. """ animal = Animal(example_properties_w_20) animal.weight = 0 animal.find_fitness() assert animal.prob_death() == 1
def test_false_if_rand_num_more_than_birth_prob(self, mocker): """ Tests will_birth_take_place method by checking if False is returned when a random number larger than a specific probability is drawn. """ test_properties_prob = {"species": "animal", "age": 63, "weight": 30} mocker.patch('numpy.random.random', return_value=0.95) animal = Animal(test_properties_prob) animal.find_fitness() assert animal.will_birth_take_place(num_animals=6) is not True
def test_no_birth_if_baby_weight_is_zero(self, example_properties_w_40, mocker): """ Tests birth_process method. Asserts that no baby is born if the baby's birth weight is equal to zero. """ mocker.patch('numpy.random.normal', return_value=0) animal = Animal(example_properties_w_40) animal.find_fitness() assert animal.birth_process(num_animals=6) is None
def test_no_birth_when_mothers_weight_small(self, example_properties_w_40, mocker): """ Asserts that no baby is born from running birth_process when mother's weight is less than xi times baby's weight. """ mocker.patch('numpy.random.normal', return_value=50) animal = Animal(example_properties_w_40) animal.find_fitness() baby_weight = animal.birth_process(num_animals=6) assert baby_weight is None
def test_true_if_rand_num_more_than_death_prob(self, example_properties_w_20, mocker): """ Asserts that will_animal_live returns True if the random number is larger than the death probability. """ mocker.patch('numpy.random.random', return_value=0.5) animal = Animal(example_properties_w_20) animal.find_fitness() assert animal.will_animal_live() is True
def test_baby_weight_returned_when_mothers_weight_large_enough( self, example_properties_w_40, mocker): """ After running birth_process, we check that a birth took place by testing if baby's weight is a float of given value and that the baby's weight times xi was smaller than the mother's weight. """ mocker.patch('numpy.random.normal', return_value=5.5) animal = Animal(example_properties_w_40) animal.find_fitness() baby_weight = animal.birth_process(num_animals=6) assert type(baby_weight) is float assert baby_weight == 5.5 assert animal.weight > baby_weight * animal.params['xi']
def test_true_if_rand_num_less_than_birth_prob(self, mocker): """ Tests will_birth_take_place method. Checks if True is returned when random number less than a specific probability is drawn. """ test_properties_num_less = { "species": "animal", "age": 63, "weight": 30 } mocker.patch('numpy.random.random', return_value=0.8) animal = Animal(test_properties_num_less) animal.find_fitness() assert animal.will_birth_take_place(num_animals=6) is True
def test_mother_loses_weight_after_birth(self, example_properties_w_40, mocker): """ Test birth_process method. Asserts that mother loses weight equal to xi * baby's weight after giving birth. """ mocker.patch('numpy.random.normal', return_value=5.5) animal = Animal(example_properties_w_40) animal.find_fitness() initial_weight = animal.weight birth_weight = animal.birth_process(num_animals=6) assert animal.weight == initial_weight - \ (animal.params['xi'] * birth_weight)