Ejemplo n.º 1
0
def species_from_config(config):
    attributes = config['attributes']

    species = Species()
    species.name = config['name']
    species.life_span = attributes['life_span']
    species.monthly_food_consumption = attributes['monthly_food_consumption']
    species.monthly_water_consumption = attributes['monthly_water_consumption']
    species.minimum_temperature = attributes['minimum_temperature']
    species.maximum_temperature = attributes['maximum_temperature']
    species.gestation_months = attributes['gestation_period']
    species.minimum_breeding_age = attributes['minimum_breeding_age']

    return species
Ejemplo n.º 2
0
    def test_starvation(self):
        animal = Animal()

        # Males cannot reproduce, so we can use them to test if they will die
        # correctly.
        simulation_step = SimulationStep()
        simulation_step.month = 3
        simulation_step.animals = [animal]

        species = Species()
        species.life_span = 100
        species.monthly_food_consumption = 1

        habitat = Habitat()
        habitat.monthly_food = 0

        next_step = advance(simulation_step, species, habitat)
        self.assertEqual(0, len(next_step.animals))
        self.assertIn(DEATH_STARVATION, next_step.deaths)
Ejemplo n.º 3
0
    def test_feed(self):
        animals = [Animal(), Animal()]

        # Males cannot reproduce, so we can use them to test if they will die
        # correctly.
        simulation_step = SimulationStep()
        simulation_step.month = 4
        simulation_step.animals = animals

        species = Species()
        species.life_span = 1
        species.monthly_food_consumption = 1

        habitat = Habitat()
        habitat.monthly_food = 1

        next_step = advance(simulation_step, species, habitat)
        # One animal should have died due to starvation from not enough food
        self.assertEqual(1, len(next_step.animals))
        self.assertIn(DEATH_STARVATION, next_step.deaths)