Exemple #1
0
 def test_fitness_function_returns_float(self):
     """
     Makes sure the generated fitness function returns a fitness score as a
     float.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
 def test_fitness_function_returns_float(self):
     """
     Makes sure the generated fitness function returns a fitness score as a
     float.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Exemple #4
0
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
 def test_fitness_function_sets_fitness_on_genome(self):
     """
     Ensures the fitness score is set in the genome's fitness attribute and
     is the same as the returned fitness score.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
Exemple #6
0
 def test_fitness_function_sets_fitness_on_genome(self):
     """
     Ensures the fitness score is set in the genome's fitness attribute and
     is the same as the returned fitness score.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(CANTUS_FIRMUS)
     self.assertTrue(callable(result))
Exemple #8
0
 mutation_rate = 0.4
 if species == 1:
     population_size = first.DEFAULT_POPULATION_SIZE
     mutation_range = first.DEFAULT_MUTATION_RANGE
     mutation_rate = first.DEFAULT_MUTATION_RATE
     start_population = first.create_population(population_size, cf)
     fitness_function = first.make_fitness_function(cf)
     generate_function = first.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = first.halt
 elif species == 2:
     population_size = second.DEFAULT_POPULATION_SIZE
     mutation_range = second.DEFAULT_MUTATION_RANGE
     mutation_rate = second.DEFAULT_MUTATION_RATE
     start_population = second.create_population(population_size, cf)
     fitness_function = second.make_fitness_function(cf)
     generate_function = first.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = second.make_halt_function(cf)
 elif species == 3:
     population_size = third.DEFAULT_POPULATION_SIZE
     mutation_range = third.DEFAULT_MUTATION_RANGE
     mutation_rate = third.DEFAULT_MUTATION_RATE
     start_population = third.create_population(population_size, cf)
     fitness_function = third.make_fitness_function(cf)
     generate_function = third.make_generate_function(mutation_range,
         mutation_rate, cf)
     halt_function = third.make_halt_function(cf)
 elif species == 4:
     population_size = fourth.DEFAULT_POPULATION_SIZE
     mutation_range = fourth.DEFAULT_MUTATION_RANGE
Exemple #9
0
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(CANTUS_FIRMUS)
     self.assertTrue(callable(result))