def test_conduct_tournament_population_part(optim):
    ga = StandardGA(fitness_test_sin_func, optim=optim)

    population = list(unsorted_population)
    population = sort_population(optim, population)
    size = 2

    best1, best2 = ga._conduct_tournament(population, size)

    if optim == 'max':
        assert population[best1].fitness_val >= population[best2].fitness_val
    else:
        assert population[best1].fitness_val <= population[best2].fitness_val
def test_conduct_tournament_population_part(optim):
    ga = StandardGA(fitness_test_sin_func, optim=optim)

    population = list(unsorted_population)
    population = sort_population(optim, population)
    size = 2

    best1, best2 = ga._conduct_tournament(population, size)

    if optim == 'max':
        assert population[best1].fitness_val >= population[best2].fitness_val
    else:
        assert population[best1].fitness_val <= population[best2].fitness_val
def test_conduct_tournament_whole_population(optim):
    ga = StandardGA(fitness_test_sin_func, optim=optim)

    population = list(unsorted_population)
    population = sort_population(optim, population)
    size = len(population)

    if optim == 'max':
        correct_out = (7, 6)
    else:
        correct_out = (1, 2)

    best1, best2 = ga._conduct_tournament(population, size)

    assert (population[best1].fitness_val, population[best2].fitness_val) == correct_out
def test_conduct_tournament_whole_population(optim):
    ga = StandardGA(fitness_test_sin_func, optim=optim)

    population = list(unsorted_population)
    population = sort_population(optim, population)
    size = len(population)

    if optim == 'max':
        correct_out = (7, 6)
    else:
        correct_out = (1, 2)

    best1, best2 = ga._conduct_tournament(population, size)

    assert (population[best1].fitness_val,
            population[best2].fitness_val) == correct_out
def test_invalid_conduct_tournament(population, size):
    ga = StandardGA(fitness_test_sin_func)

    with pytest.raises(ValueError):
        ga._conduct_tournament(population, size)
def test_invalid_conduct_tournament(population, size):
    ga = StandardGA(fitness_test_sin_func)

    with pytest.raises(ValueError):
        ga._conduct_tournament(population, size)