def test_mutate_length():
    test_pop = h.first_gen()
    for individual in test_pop:
        new = h.mutate(individual)
        assert len(new) - 1 == len(individual) or len(new) + 1 == len(
            individual) or len(new) == len(individual) or len(new) - 2 == len(
                individual)
def test_proper_breeding():
    test_pop = h.new_breeders(
        h.calculate_fitness_of_population(h.first_gen(),
                                          'Hello World!'))[0][:2]
    parent1, parent2 = test_pop
    test = h.breed(test_pop)
    for child in test:
        for i in range(len(child)):
            assert child[i] == parent1[0][i] or child[i] == parent2[0][i]
def test_breed_length():
    test_pop = h.new_breeders(
        h.calculate_fitness_of_population(h.first_gen(), 'Hello World!'))[0]
    test = h.breed(test_pop)
    assert len(test) == 100
def test_parents_are_good():
    test_pop = h.calculate_fitness_of_population(h.first_gen(), 'Hello World!')
    test = h.new_breeders(test_pop)[0]
    for i in range(24):
        assert h.fitness(test[i][0], 'Hello World!') >= h.fitness(
            test[i + 1][0], 'Hello World!')
def test_parent_length():
    test_pop = h.calculate_fitness_of_population(h.first_gen(), 'Hello World!')
    test = h.new_breeders(test_pop)[0]
    assert len(test) == 50
def test_fitness_calculation_is_accurate():
    test_pop = h.first_gen()
    test = h.calculate_fitness_of_population(test_pop, 'Hello World!')
    for i in test:
        assert i[1] == h.fitness(i[0], 'Hello World!')
def test_fitness_calculation_changes_format():
    test_pop = h.first_gen()
    test = h.calculate_fitness_of_population(test_pop, 'Hello World!')
    for i in test:
        assert len(i) == 2
def test_fitness_calculation_length():
    test_pop = h.first_gen()
    test = h.calculate_fitness_of_population(test_pop, 'Hello World!')
    assert len(test) == 100
def test_first_gen_randomness():
    test = h.first_gen()
    for i in range(99):
        assert test[i] != test[i + 1]
def test_first_gen_length():
    test = h.first_gen()
    assert len(test) == 100
def test_mutate_changes():
    test_pop = h.first_gen()
    for individual in test_pop:
        new = h.mutate(individual)
        assert new != individual