def test_birth_does_not_happen_if_prob_0(self, mocker): """Test to show that birth method does not add new pop if birth does not occur """ mocker.patch('random.random', return_value=1) loc = (2, 7) i_sim = Island() a_sim_1 = Herbivore(i_sim, loc, weight=100) a_sim_2 = Herbivore(i_sim, loc, weight=100) a_sim_1.birth() assert i_sim.get_num_herb_on_loc(loc) == 2
def test_birth_adds_to_num_herb_on_loc(self, mocker): """Test to show that birth method adds new pop to herb_pop list when birth occurs """ mocker.patch('random.random', return_value=0) loc = (2, 7) i_sim = Island() a_sim_1 = Herbivore(i_sim, loc, weight=100) a_sim_2 = Herbivore(i_sim, loc, weight=100) a_sim_1.birth() assert i_sim.get_num_herb_on_loc(loc) == 3
def test_get_num_animals_on_loc(self): """Tests if the get animals on location method can return the number of animals placed out on the map. """ i = Island() num_herb = 4 num_carn = 3 loc = (2, 7) for _ in range(num_herb): Herbivore(i, loc) for _ in range(num_carn): Carnivore(i, loc) assert i.get_num_herb_on_loc(loc) == num_herb assert i.get_num_carn_on_loc(loc) == num_carn
def test_migration_removes_pop_from_loc_and_adds_to_odder(self, mocker): """Test to show that migration removes population from initial loc to the chosen destination when the mocked value for will_move is set to True """ mocker.return_value = True loc_with_one_place_to_move = (1, 1) i = Island(self.spes_geogr_2) h = Herbivore(i, loc_with_one_place_to_move) old_loc = h.get_loc() h.migrate() new_loc = h.get_loc() assert i.get_num_herb_on_loc(old_loc) == 0 assert i.get_num_herb_on_loc(new_loc) == 1 assert old_loc != new_loc