예제 #1
0
    def test_animal_death_removes_all_dead_animals(self, mocker):
        """Test to show that death removes all dead animals from all locations
        """
        mocker.patch('random.random', return_value=0)
        i = Island()
        cycle = AnnualCycle(i)
        loc_1 = (2, 7)
        loc_2 = (2, 8)
        c_1 = Carnivore(i, loc_1, weight=100)
        h_1 = Herbivore(i, loc_2, weight=100)
        old_herb_count = i.get_num_herb_on_loc(loc_2)
        old_carn_count = i.get_num_carn_on_loc(loc_1)
        cycle.animal_death()

        assert i.get_num_herb_on_loc(loc_2) < old_herb_count
        assert i.get_num_carn_on_loc(loc_1) < old_carn_count
예제 #2
0
    def test_procreation_herb_adds_herb_pop(self, mocker):
        """Test to show that procreation_herb adds a Herbivore instance
        for every location needed.
        """
        mocker.patch('random.random', return_value=0)
        i = Island()
        cycle = AnnualCycle(i)
        loc_1 = (2, 7)
        loc_2 = (2, 8)
        h_1 = Herbivore(i, loc_1, weight=100)
        h_2 = Herbivore(i, loc_1, weight=100)
        h_3 = Herbivore(i, loc_2, weight=100)
        h_4 = Herbivore(i, loc_2, weight=100)
        old_num_loc_1 = i.get_num_herb_on_loc(loc_1)
        old_num_loc_2 = i.get_num_herb_on_loc(loc_2)
        cycle.procreation_herb()
        new_num_loc_1 = i.get_num_herb_on_loc(loc_1)
        new_num_loc_2 = i.get_num_herb_on_loc(loc_2)

        assert old_num_loc_1 < new_num_loc_1
        assert old_num_loc_2 < new_num_loc_2
예제 #3
0
    def test_procreation_all_adds_all_pop(self, mocker):
        """Test to show that procreation_all adds instances of both
        Carnivore and Herbivore for all locations.
        """
        mocker.patch('random.random', return_value=0)
        i = Island()
        cycle = AnnualCycle(i)
        loc_1 = (2, 7)
        loc_2 = (2, 8)
        h_1 = Carnivore(i, loc_1, weight=100)
        h_2 = Carnivore(i, loc_1, weight=100)
        h_3 = Herbivore(i, loc_2, weight=100)
        h_4 = Herbivore(i, loc_2, weight=100)
        old_num_loc_1 = i.get_num_carn_on_loc(loc_1)
        old_num_loc_2 = i.get_num_herb_on_loc(loc_2)
        cycle.procreation_all()
        new_num_loc_1 = i.get_num_carn_on_loc(loc_1)
        new_num_loc_2 = i.get_num_herb_on_loc(loc_2)

        assert old_num_loc_1 < new_num_loc_1
        assert old_num_loc_2 < new_num_loc_2