Beispiel #1
0
    def setup(self):
        spes_geogr_1 = """\
                       OOOO
                       OOJO
                       OOOO"""

        self.spes_geogr_2 = """\
                               OOOO
                               OJJO
                               OOOO"""
        self.spes_island = Island(spes_geogr_1)
        self.i = Island()
        self.loc = (0, 0)
        stnd_herb = Herbivore(island=self.i, loc=self.loc)
        stnd_carn = Carnivore(island=self.i, loc=self.loc)
        self.stnd_a_list = [stnd_herb, stnd_carn]

        self.herb_w_0 = Herbivore(island=self.i, loc=self.loc, weight=0)
        self.herb_w_5 = Herbivore(island=self.i, loc=self.loc, weight=5)
        self.herb_w_200 = Herbivore(island=self.i, loc=self.loc, weight=200)

        self.carn_w_0 = Carnivore(island=self.i, loc=self.loc, weight=0)
        self.carn_w_5 = Carnivore(island=self.i, loc=self.loc, weight=5)
        self.carn_w_7 = Carnivore(island=self.i, loc=self.loc, weight=7)

        self.a_list_w_0 = [self.herb_w_0, self.carn_w_0]
        self.a_list_w_5 = [self.herb_w_5, self.carn_w_5]
 def test_get_fodder_on_loc(self):
     """Tests if get fodder on loc method retrieves fodder attribute of cell on location.
     """
     i = Island()
     j_loc = (2, 7)
     fodder_on_loc = i.island_dict[j_loc].fodder
     assert i.get_fodder_on_loc(j_loc) == fodder_on_loc
 def test_get_cell_type(self):
     """Tests if the get cell type method returns Jungle on a known
        jungle location.
        """
     i = Island()
     jungle_loc = (2, 7)
     assert i.get_cell_type(jungle_loc) == "Jungle"
Beispiel #4
0
 def test_relative_abundance_gives_output_herb(self):
     """Test to show that relative_abundance returns output for herb
     """
     i = Island()
     jungle_loc = (2, 7)
     h = Herbivore(i, jungle_loc)
     self_calculated_abundance = 40
     assert h.relative_abundance(jungle_loc) == self_calculated_abundance
Beispiel #5
0
    def test_can_birth_occur_with_1_herbivore(self):
        """Test to see that birth will not occur for only 1 animal
        """
        loc = (2, 7)
        i_sim = Island()
        a_sim = Herbivore(i_sim, loc)
        i_sim.add_pop_on_loc(loc, a_sim)

        assert not a_sim.can_birth_occur()
Beispiel #6
0
    def test_get_num_same_species_carn(self):
        """Test to show that get_num_same_species
        return is number of same species(carn)
        """
        i = Island()
        h_1 = Carnivore(i, self.loc)
        h_2 = Carnivore(i, self.loc)

        assert h_1.get_num_same_species(self.loc) == 2
Beispiel #7
0
    def test_propensity_return_value_desert(self):
        """Test to show that propensity returns a value based on a formula
         when placed in desert
         """
        i = Island()
        des_loc = (5, 9)
        h = Herbivore(i, des_loc)

        assert h.propensity(des_loc) == 1
Beispiel #8
0
 def test_relative_abundance_gives_output_carn(self):
     """Test to show that relative_abundance returns output for herb
     """
     i = Island()
     jungle_loc = (2, 7)
     h = Herbivore(i, jungle_loc, weight=50)
     c = Carnivore(i, jungle_loc)
     self_calculated_abundance = 0.5
     assert c.relative_abundance(jungle_loc) == self_calculated_abundance
Beispiel #9
0
    def test_get_num_same_species_herb(self):
        """Test to show that get_num_same_species
        return is number of same species(herb)
        """
        i = Island()
        h_1 = Herbivore(i, self.loc)
        h_2 = Herbivore(i, self.loc)

        assert h_1.get_num_same_species(self.loc) == 2
Beispiel #10
0
    def test_fodder_eaten_only_eat_available_fodder(self):
        """Test to show that fodder_eaten only returns the available
        fodder if the location contains less fodder than optimal fodder
        """
        jungle_loc = (2, 7)
        Island._param_changer("J", {"f_max": 5})
        i_sim = Island()
        s_1 = Herbivore(i_sim, jungle_loc)

        assert s_1.fodder_eaten() == 5
Beispiel #11
0
    def test_death_occurs_if_fitness_is_0(self):
        """Test to show that animal will die if fitness is 0
        """
        loc = (2, 7)
        i = Island()
        h_sim = Herbivore(i, loc, weight=0)
        c_sim = Carnivore(i, loc, weight=0)

        assert h_sim.death()
        assert c_sim.death()
Beispiel #12
0
    def test_kill_herb_false_if_fitness_too_low(self):
        """Test to show that kill_herb returns False if the Carnivore-fitness
        is too low
        """
        i = Island()
        loc = (2, 7)
        c = Carnivore(i, loc, weight=0)
        h = Herbivore(i, loc, weight=100)

        assert not c.kill_herb(h)
Beispiel #13
0
    def test_get_relevant_fodder_carn(self):
        """Test to show that get_relevant_fodder returns fodder for carn,
        which is equal to the herb_weight
        """
        i = Island()
        c = Carnivore(i, self.loc)
        herb_weight = 50
        h = Herbivore(i, self.loc, weight=herb_weight)

        assert c.get_relevant_fodder(self.loc) == herb_weight
 def test_param_changer(self):
     """Tests that the parameter changer method in the Island class changes the parameters in
        the Landscape class.
     """
     i = Island()
     new_param = {"f_max": 700}
     landscape = "J"
     i._param_changer(landscape, new_param)
     assert i.island_dict[(
         0, 0)].landscape_parameters[landscape]["f_max"] == 700
Beispiel #15
0
    def test_eaten_removes_herb(self):
        """Test to show that eaten removes dead herb from location
        """
        i = Island()
        loc = (2, 7)
        a = Herbivore(i, loc)
        ini_pop = a.get_num_same_species(loc)
        a.eaten()
        new_pop = a.get_num_same_species(loc)

        assert ini_pop != new_pop
Beispiel #16
0
    def test_feed_raises_fitness(self):
        """Test to show that feed makes changes to fitness
        """
        loc = (2, 7)
        i = Island()
        h = Herbivore(i, loc)
        old_fitness = h.fitness
        h.feed()
        new_fitness = h.fitness

        assert old_fitness < new_fitness
Beispiel #17
0
    def test_probabilities_returns_prob_list(self):
        """Test to show that probabilities returns probability_list based
        on formula
        """
        i = Island()
        loc = (3, 7)
        c = Carnivore(i, loc)
        loc_list = c.get_potential_coordinates()
        prob_list = [0.25, 0.25, 0.25, 0.25]

        assert c.probabilities(loc_list) == prob_list
Beispiel #18
0
    def test_propensity_0_if_mountain_or_ocean(self):
        """Test to show that propensity returns 0 if cell_type is mountain
        or ocean
        """
        ocean_loc = (0, 0)
        mountain_loc = (1, 9)
        i = Island()
        h = Herbivore(i, mountain_loc)

        assert h.propensity(ocean_loc) == 0
        assert h.propensity(mountain_loc) == 0
Beispiel #19
0
    def test_kill_herb_true_if_DeltaPhiMax_is_low(self):
        """Test to show that kill_herb returns True if DeltaPhiMax
        is set to 0.
        """
        i = Island()
        loc = (2, 7)
        c = Carnivore(i, loc, weight=100)
        h = Herbivore(i, loc, weight=0)
        c.param_changer({"DeltaPhiMax": 0})

        assert c.kill_herb(h)
Beispiel #20
0
    def test_kill_herb_true_if_prob_1(self, mocker):
        """Test to show that kill_herb returns True if the mocker return
        value is set to lowest
        """
        mocker.patch('random.random', return_value=0)
        i = Island()
        loc = (2, 7)
        c = Carnivore(i, loc, weight=100)
        h = Herbivore(i, loc, weight=0)

        assert c.kill_herb(h)
    def test_get_herb_list_on_loc(self):
        """Tests if get herb list on loc method retrieves herb list attribute of
           cell on locatrion.
           """
        i = Island()
        loc = (1, 8)
        for _ in range(3):
            Herbivore(i, loc)

        herb_list_manually = i.island_dict[loc].herb_pop_list
        assert i.get_herb_list_on_loc(loc) == herb_list_manually
Beispiel #22
0
    def test_feed_changes_fitness(self):
        """Test feed changes fitness
        """
        loc = (2, 1)
        i = Island()
        i_sim = Herbivore(i, loc)
        start_fitness = i_sim.fitness
        i_sim.feed()
        changed_fitness = i_sim.fitness

        assert start_fitness != changed_fitness
 def test_herb_eats_fodder_on_loc(self):
     """Tests if the fodder before eating is equal to the fodder after eating
        in addition to the amount eaten.
     """
     i = Island()
     j_loc = (2, 7)
     herb_amount = 10
     fodder_pre_eating = i.island_dict[j_loc].fodder
     i.herb_eats_fodder_on_loc(j_loc, herb_amount)
     fodder_post_eating = i.island_dict[j_loc].fodder
     assert fodder_pre_eating == fodder_post_eating + herb_amount
    def test_get_carn_list_on_loc(self):
        """Tests if get carn list on loc method retrieves carn list attribute of
        cell on locatrion.
        """
        i = Island()
        loc = (1, 8)
        for _ in range(3):
            Carnivore(i, loc)

        carn_list_manually = i.island_dict[loc].carn_pop_list
        assert i.get_carn_list_on_loc(loc) == carn_list_manually
Beispiel #25
0
 def test_destination_gives_coordinate(self, mocker):
     """Test to show that destination returns destination when mocked
     to a probability of 100% at different indexes
     """
     mocker.return_value = [1, 0, 0, 0]
     i = Island()
     loc = (2, 8)
     h = Herbivore(i, loc)
     loc_list = h.get_potential_coordinates()
     assert h.destination(loc_list) == loc_list[0]
     mocker.return_value = [0, 1, 0, 0]
     assert h.destination(loc_list) == loc_list[1]
Beispiel #26
0
    def test_annual_weight_loss_decreases_weight(self):
        """Test to show that annual_weight_loss decreases the
        weight of the animal
        """
        loc = (2, 7)
        i = Island()
        a_sim = Herbivore(i, loc)
        initial_weight = a_sim.weight
        a_sim.annual_weight_loss()
        new_weight = a_sim.weight

        assert initial_weight > new_weight
Beispiel #27
0
    def test_death_occurs_if_prob_is_1(self, mocker):
        """Test to show that death will occur if we mock the probability to
        lowest return value
        """
        mocker.patch('random.random', return_value=0)
        loc = (2, 7)
        i_sim = Island()
        h_sim = Herbivore(i_sim, loc)
        c_sim = Carnivore(i_sim, loc)

        assert h_sim.death()
        assert c_sim.death()
Beispiel #28
0
    def test_death_does_not_occur_if_prob_is_0(self, mocker):
        """Test to show that death will not occur if we mock the probability to
        highest return value
        """
        mocker.patch('random.random', return_value=1)
        loc = (2, 7)
        i_sim = Island()
        h_sim = Herbivore(i_sim, loc)
        c_sim = Carnivore(i_sim, loc)

        assert not h_sim.death()
        assert not c_sim.death()
    def test_get_total_herb_weight_on_loc(self):
        """Tests if the get total herbivore weight on location method returns the same
           weight as the weight of the herbivores times their number.
           """
        i = Island()
        herb_weight = 50
        num_herb = 5
        loc = (2, 7)
        for _ in range(num_herb):
            Herbivore(i, loc, weight=herb_weight)

        assert i.get_total_herb_weight_on_loc(loc) == herb_weight * num_herb
Beispiel #30
0
    def test_param_changer_changes(self):
        """Test param_changer changes the parameter list
        """
        i = Island()
        loc = (1, 1)
        s = Herbivore(i, loc)
        old_param = s.parameters["F"]
        s.param_changer({"F": 20})
        new_param = s.parameters["F"]

        assert old_param != new_param
        s.param_changer({"F": 10})