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_old_age(self):
        animal = Animal()

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

        species = Species()
        species.life_span = 1

        habitat = Habitat()

        next_step = advance(simulation_step, species, habitat)
        self.assertEqual(0, len(next_step.animals))
        self.assertIn(DEATH_OLD_AGE, next_step.deaths)
Ejemplo n.º 3
0
    def test_thirst(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_water_consumption = 1

        habitat = Habitat()
        habitat.monthly_water = 0

        next_step = advance(simulation_step, species, habitat)
        self.assertEqual(0, len(next_step.animals))
        self.assertIn(DEATH_THIRST, next_step.deaths)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def test_too_cold(self):
        animal = Animal()
        animal.consecutive_cold_months = 1

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

        species = Species()
        species.life_span = 100
        species.minimum_temperature = 100
        species.maximum_temperature = 200

        habitat = Habitat()
        habitat.monthly_food = 1
        habitat.monthly_water = 1
        habitat.average_temperatures[SEASON_SPRING] = -1000

        next_step = advance(simulation_step, species, habitat)
        self.assertEqual(0, len(next_step.animals))
        self.assertIn(DEATH_TOO_COLD, next_step.deaths)