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
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)