Example #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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
Example #2
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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
Example #3
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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Example #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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Example #5
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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
Example #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(TARGET_WORD)
     genome = Genome(['c', 'a', 't'])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
Example #7
0
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(TARGET_WORD)
     self.assertTrue(callable(result))
Example #8
0
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(TARGET_WORD)
     self.assertTrue(callable(result))