示例#1
0
    def test_aging_adds_1_year_to_all_animals(self):
        """Test to show that aging adds a year to every animal on every
        location
        """
        i = Island()
        cycle = AnnualCycle(i)
        loc_1 = (2, 7)
        loc_2 = (2, 8)
        h_1 = Carnivore(i, loc_1, weight=100, age=0)
        h_2 = Carnivore(i, loc_1, weight=100, age=0)
        h_3 = Herbivore(i, loc_2, weight=100, age=0)
        h_4 = Herbivore(i, loc_2, weight=100, age=0)
        a_list = [h_1, h_2, h_3, h_4]
        cycle.aging()

        for animal in a_list:
            assert animal.age == 1
示例#2
0
    def test_migration_moves_all_animals(self, mocker_1, mocker_2):
        """Test to show that migration moves all animals for all locations
        """
        mocker_1.return_value = True
        mocker_2.return_value = True
        geogr = """\
                               OOOO
                               OJJO
                               OOOO"""
        i = Island(geogr)
        cycle = AnnualCycle(i)
        old_loc = (1, 1)
        new_loc = (1, 2)
        h = Herbivore(i, old_loc)
        c = Carnivore(i, old_loc)
        cycle.migration()

        assert h.get_loc() == new_loc
        assert c.get_loc() == new_loc
示例#3
0
    def test_carn_feeding_changes_weight_for_all_carns(self, mocker):
        """Test to show that carn_feeding changes weight for all Carnivores on
        all locations
        """
        mocker.patch('random.random', return_value=0)
        i = Island()
        cycle = AnnualCycle(i)
        loc_1 = (2, 7)
        loc_2 = (2, 9)
        c_1 = Carnivore(i, loc_1, weight=100)
        c_2 = Carnivore(i, loc_2, weight=100)
        h_1 = Herbivore(i, loc_1, weight=10)
        h_2 = Herbivore(i, loc_2, weight=10)
        old_weight_1 = c_1.weight
        old_weight_2 = c_2.weight
        cycle.carn_feeding()
        new_weight_1 = c_1.weight
        new_weight_2 = c_2.weight

        assert old_weight_1 < new_weight_1
        assert old_weight_2 < new_weight_2
示例#4
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
示例#5
0
    def test_procreation_carn_adds_carn_pop(self, mocker):
        """Test to show that procreation_carn adds a Carnivore 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 = Carnivore(i, loc_1, weight=100)
        h_2 = Carnivore(i, loc_1, weight=100)
        h_3 = Carnivore(i, loc_2, weight=100)
        h_4 = Carnivore(i, loc_2, weight=100)
        old_num_loc_1 = i.get_num_carn_on_loc(loc_1)
        old_num_loc_2 = i.get_num_carn_on_loc(loc_2)
        cycle.procreation_carn()
        new_num_loc_1 = i.get_num_carn_on_loc(loc_1)
        new_num_loc_2 = i.get_num_carn_on_loc(loc_2)

        assert old_num_loc_1 < new_num_loc_1
        assert old_num_loc_2 < new_num_loc_2
示例#6
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
示例#7
0
    def test_weight_loss_changes_for_all_animals(self, mocker):
        """Test to show that weight_loss changes weight for all animals
        on 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_weight_1 = c_1.weight
        old_weight_2 = h_1.weight
        cycle.weight_loss()

        assert c_1.weight < old_weight_1
        assert h_1.weight < old_weight_2