def test_minimal(): # sample fitness function def eval_fitness(population): for individual in population: individual.fitness = 1.0 # creates the population local_dir = os.path.dirname(__file__) config = Config(os.path.join(local_dir, 'test_configuration')) pop = Population(config) # run the simulation for up to 20 generations pop.run(eval_fitness, 20) # get statistics avg_fitness = pop.statistics.get_average_fitness() assert len(avg_fitness) == 1 assert all(f == 1 for f in avg_fitness) # Change fitness threshold and do another run. config.max_fitness_threshold = 1.1 pop = Population(config) # runs the simulation for 20 generations pop.run(eval_fitness, 20) # get statistics avg_fitness = pop.statistics.get_average_fitness() assert len(avg_fitness) == 20 assert all(f == 1 for f in avg_fitness)