def test_topo_remove_carnivore():
    """Tests that an emigrating animal can be removed from its old cells
     animal list"""
    cell = topo.Topography()
    testcarni = animals.Carnivores()
    testlist = [animals.Carnivores() for _ in range(10)]
    cell.herbivore_list = testlist
    cell.add_animal(testcarni)
    cell.remove_animal(testcarni)
    assert testcarni not in cell.herbivore_list
def test_annual_death_0_fitness_random_cells(test_map):
    """Tests that the method annual_death works in a random accessible cell"""
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=99, weight=0))
    test_map.raster_model[(11, 8)].add_animal(ani.Carnivores(age=99, weight=0))
    test_map._annual_death_all_cells()
    assert test_map.raster_model[(3, 4)].herbivore_list == []
    assert test_map.raster_model[(11, 8)].carnivore_list == []
def test_fitness_level_is_zero_when_weight_is_zero():
    """Tests that the fitness level is zero, when the weight is zero"""
    herbivore = ani.Herbivores()
    carnivore = ani.Carnivores()
    herbivore.weight = 0
    carnivore.weight = 0
    assert herbivore.fitness == 0
    assert carnivore.fitness == 0
def test_breed_certain_probability_all_in_cell():
    """Tests that all animals breed, when the breeding-probability = 1"""
    cell = topo.Jungle()
    for _ in range(100):
        cell.add_animal(animals.Herbivores(age=10, weight=100))
        cell.add_animal(animals.Carnivores(age=10, weight=100))
    cell.breed_all_animals_in_cell()
    assert len(cell.herbivore_list) == 200
    assert len(cell.carnivore_list) == 200
def test_population_age_groups(test_map):
    """Tests that the method population_age_groups returns two arrays and two
    lists"""
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=1, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=4, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=9, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=14, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=50, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=1, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=4, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=9, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=14, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=50, weight=10))
    herb_list, carn_list, herb_mean_w_list, carn_mean_w_list = \
        test_map.population_biomass_age_groups()
    assert herb_list == [1, 1, 1, 1, 1]
    assert carn_list == [-1, -1, -1, -1, -1]
    assert herb_mean_w_list == [10, 10, 10, 10, 10]
    assert carn_mean_w_list == [-10, -10, -10, -10, -10]
def strong_vs_weak():
    """Creates a test herbivore and carnivore instance"""
    cell = topo.Desert()
    herbivore = ani.Herbivores()
    carnivore = ani.Carnivores()
    herbivore.weight, herbivore.age = 1, 100
    carnivore.weight, carnivore.age = 15, 52
    cell.add_animal(herbivore)
    cell.add_animal(carnivore)
    return herbivore, carnivore, cell
def test_set_parameters(bad_parameters):
    """Test if the non allowed parameters raises a value error. """
    carnivore = ani.Carnivores()
    herbivore = ani.Herbivores()
    with pytest.raises(ValueError):
        carnivore.set_parameters(bad_parameters)
    with pytest.raises(ValueError):
        herbivore.set_parameters(bad_parameters)
    carnivore.set_parameters({"w_birth": 6.0})
    assert carnivore.parameters["w_birth"] == 6.0
def test_feeding_carnivores_in_a_cell():
    """Tests if the most fit herbivore kills the least fit herbivore etc"""
    animals.Carnivores.set_parameters({"DeltaPhiMax": 0.1})
    jungle_cell = topo.Jungle()
    [jungle_cell.add_animal(animals.Herbivores()) for _ in range(10)]
    [jungle_cell.add_animal(animals.Carnivores(weight=80)) for _ in range(10)]
    assert jungle_cell.biomass_carnivores() == 800
    pre_feeding_herbi_biomass = jungle_cell.biomass_herbivores()
    jungle_cell.feed_carnivores_in_cell()
    assert pre_feeding_herbi_biomass > jungle_cell.biomass_herbivores()
def test_ek_for_cell_9_herbs_carns_100_fodder(basic_jungle):
    """Tests that the ek formula for herbivores and carnivores are correct"""
    basic_jungle.fodder = 100
    for _ in range(9):
        basic_jungle.add_animal(animals.Herbivores(weight=10))
        basic_jungle.add_animal(animals.Carnivores())
    animals.Carnivores.parameters["F"] = 50
    ek_herbivores = basic_jungle.ek_for_cell("Herbivores")
    ek_carnivores = basic_jungle.ek_for_cell("Carnivores")
    assert ek_herbivores == 1
    assert ek_carnivores == 0.18
Ejemplo n.º 10
0
def test_biomass_food_chain(test_map):
    """Tests that the method biomass_food_chain returns a dictionary with the
    correct islands total biomass of fodder, herbivores and carnivores"""
    test_map.raster_model[(3, 4)].add_animal(ani.Herbivores(age=99, weight=10))
    test_map.raster_model[(3, 4)].add_animal(ani.Carnivores(age=1, weight=100))
    for cell in test_map.raster_model.values():
        if cell.is_accessible:
            cell.fodder = 0
    biomass_dict = test_map.biomass_food_chain()
    assert biomass_dict.get('biomass_fodder') == 0
    assert biomass_dict.get('biomass_herbs') == 10
    assert biomass_dict.get('biomass_carnivores') == 100
def test_remove_carnivore():
    """Test that a carnivore can be removed"""
    jungle_cell = topo.Jungle()
    test_carnivore = animals.Carnivores()
    jungle_cell.add_animal(test_carnivore)
    assert test_carnivore in animals.Animals.instances
    assert test_carnivore in jungle_cell.carnivore_list
    jungle_cell.remove_animal(test_carnivore)
    assert test_carnivore in animals.Animals.instances
    assert test_carnivore not in jungle_cell.carnivore_list
    animals.Animals.instances.remove(test_carnivore)
    assert test_carnivore not in animals.Animals.instances
def low_fitness_animals():
    """Creates some test instances with very low fitness"""
    jungle_cell = topo.Jungle()
    herbivore = animals.Herbivores()
    carnivore = animals.Carnivores()
    carnivore.weight, carnivore.age = 1, 1000
    herbivore.weight, herbivore.age = 1, 1000
    herbivore.parameters["omega"] = 1
    carnivore.parameters["omega"] = 1
    jungle_cell.add_animal(herbivore)
    jungle_cell.add_animal(carnivore)
    return jungle_cell
Ejemplo n.º 13
0
def test_breed_all_cells_certain_prob_random_cell(test_map):
    """Test that the method 'breed_all_cell' works in a random accessible
     cell"""
    for _ in range(100):
        test_map.raster_model[(3,
                               4)].add_animal(ani.Herbivores(age=0,
                                                             weight=100))
        test_map.raster_model[(11,
                               8)].add_animal(ani.Carnivores(age=0,
                                                             weight=100))
    test_map._breed_in_all_cells()
    assert len(test_map.raster_model[(3, 4)].herbivore_list) == 200
    assert len(test_map.raster_model[(11, 8)].carnivore_list) == 200
def test_what_cell_two_options_equal_probability():
    """Test that a carnivores chances to migrate to two cells with equal ek
    are 50-50"""
    testanimal = ani.Carnivores(age=0, weight=100)
    testanimal.parameters["mu"] = 10
    current_cell = (10, 10)
    mock_ek = {(11, 10): 1, (10, 11): 1}
    random.seed(2)
    decisionlist = [
        testanimal.what_cell_to_migrate_to(current_cell, mock_ek)
        for _ in range(1000)
    ]
    times_11_10_chosen = decisionlist.count((11, 10))
    assert 490 < times_11_10_chosen < 510
def test_topo_add_carnivore():
    """Tests that an immigrating animal can be added to the new cells
     animal list"""
    instance = topo.Topography()
    instance.add_animal(animals.Carnivores())
    assert len(instance.carnivore_list) == 1