def test_select_parents_tournament(): population = list(unsorted_population) population = sort_population('min', population) ga = StandardGA(fitness_test_sin_func, optim='min', selection='tournament', tournament_size=len(population)) parent1, parent2 = ga._select_parents(population) assert (parent1.fitness_val, parent2.fitness_val) == (1, 2)
def test_select_parents_tournament(): population = list(unsorted_population) population = sort_population('min', population) ga = StandardGA(fitness_test_sin_func, optim='min', selection='tournament', tournament_size=len(population)) parent1, parent2 = ga._select_parents(population) assert (parent1.fitness_val, parent2.fitness_val) == (1, 2)
def test_select_parents_unknown_type(): ga = StandardGA(fitness_test_sin_func) ga.selection = 'unknown' with pytest.raises(ValueError): ga._select_parents([])
def test_select_parents_wheel_sum(selection, wheel_sum): ga = StandardGA(fitness_test_sin_func, selection=selection) with pytest.raises(ValueError): ga._select_parents([], wheel_sum)
def test_select_parents_unknown_type(): ga = StandardGA(fitness_test_sin_func) ga.selection = 'unknown' with pytest.raises(ValueError): ga._select_parents([])
def test_select_parents_wheel_sum(selection, wheel_sum): ga = StandardGA(fitness_test_sin_func, selection=selection) with pytest.raises(ValueError): ga._select_parents([], wheel_sum)