def test_halt_expected(self): """ Ensure the function returns true if we're in a halting state. """ g1 = Genome(['c', 'a', 't']) g1.fitness = len(TARGET_WORD) g2 = Genome(['d', 'o', 'g']) g2.fitness = 2 g3 = Genome(['f', 'o', 'o']) g3.fitness = 3 # Any fittest solution with fitness = length of the target word. population = [g1, g2, g3] result = halt(population, 1) self.assertTrue(result)
def test_halt_not(self): """ Ensures if the fittest genome has fitness < 4 then halt doesn't succeed. """ g1 = Genome(['c', 'a', 't']) g1.fitness = len(TARGET_WORD) - 1 g2 = Genome(['d', 'o', 'g']) g2.fitness = 2 g3 = Genome(['f', 'o', 'o']) g3.fitness = 3 # Any fittest solution with fitness < target word length means call a # halt. population = [g1, g2, g3] result = halt(population, 1) self.assertFalse(result)