

def test_halt_function(self):
    '\n        Ensures that the halt function is called for all subsequent yields\n        after yielding the starting population.\n        '
    start_pop = [1, 2, 3]

    def fitness(genome):
        '\n            For illustrative purposes.\n            '
        return genome

    def halt(population, generation_count):
        '\n            Halts the algorithm after ten populations.\n            '
        return (generation_count == 10)

    class Generate(object):
        '\n            As simple as possible. See generate related test below.\n            '

        def __init__(self, parents):
            pass

        def __iter__(self):
            return self

        def next(self):
            raise StopIteration()
    ga = genetic_algorithm(start_pop, fitness, Generate, halt)
    result = [p for p in ga]
    actual = len(result)
    expected = 10
    self.assertEqual(actual, expected, ('Actual: %r Expected: %r' % (actual, expected)))

dataset/ETHPy150Open ntoll/foox/test/test_ga.py TestGeneticAlgorithm.test_halt_function/original