コード例 #1
0
    def test_birth_does_not_add_new_baby_if_weight_too_low(self, mocker):
        """Test to show that if birth weight is too low, a new baby will not
        be born"""
        a_sim_1 = Herbivore(self.i, self.loc, weight=1)
        mocker.return_value = True
        a_sim_2 = Herbivore(self.i, self.loc, weight=1)
        old_pop = a_sim_1.get_num_same_species(self.loc)
        a_sim_1.birth()
        new_pop = a_sim_1.get_num_same_species(self.loc)

        assert old_pop == new_pop
コード例 #2
0
    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
コード例 #3
0
    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