Exemplo n.º 1
0
def test_animal_migration_chances():
    """
    test the probability of migration is zero if
    fitness is zero
    """
    animal = Herbivore(10, 50)
    animal.fitness = 0
    assert not animal.will_migrate()
Exemplo n.º 2
0
def test_animal_death():
    """
    test that animal dies when fitness is 0 or with
    certain probability omega(1 - fitness)
    """
    animal = Herbivore(10, 50)
    animal.fitness = 0
    assert animal.will_die() is True
Exemplo n.º 3
0
def test_carnivore_kill(mocker):
    """
    Test that carnivore kills herbivore if
        1. carnivore fitness is greater than
        herbivore fitness
        2. the difference between carnivore
        fitness and herbivore fitness divided
        by DeltaPhiMax parameter is greater
        than random value.
    """
    mocker.patch('numpy.random.random', return_value=0.05)
    herbivore = Herbivore()
    carnivore = Carnivore()
    herbivore.fitness = 0.3
    carnivore.fitness = 0.9
    assert carnivore.will_kill(herbivore.fitness)