Skip to content

Commit

Permalink
fixed tests that broke on merge
Browse files Browse the repository at this point in the history
  • Loading branch information
gbomarito committed Nov 14, 2022
1 parent 052d958 commit 873472a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
27 changes: 20 additions & 7 deletions bingo/evolutionary_algorithms/generalized_crowding.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,29 @@ class GeneralizedCrowdingEA(EvolutionaryAlgorithm):
diagnostics : `bingo.evolutionary_algorithms.ea_diagnostics.EaDiagnostics`
Public to the EA diagnostics
"""
def __init__(self, evaluation, crossover, mutation, crossover_probability,
mutation_probability, selection=None):

def __init__(
self,
evaluation,
crossover,
mutation,
crossover_probability,
mutation_probability,
selection=None,
):
if selection is None:
selection = DeterministicCrowding()

super().__init__(variation=VarAnd(crossover, mutation,
crossover_probability,
mutation_probability),
evaluation=evaluation,
selection=selection)
super().__init__(
variation=VarAnd(
crossover,
mutation,
crossover_probability,
mutation_probability,
),
evaluation=evaluation,
selection=selection,
)

def generational_step(self, population):
"""Performs selection on individuals.
Expand Down
40 changes: 34 additions & 6 deletions tests/unit/evolutionary_algorithms/test_generalized_crowding_ea.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ def test_all_phases_occur_in_correct_order(mocker):
mocked_variation = mocker.Mock(return_value=dummy_offspring)
mocked_evaluation = mocker.Mock()
mocked_selection = mocker.Mock(return_value=dummy_next_gen)
mocker.patch(
"bingo.evolutionary_algorithms."
"evolutionary_algorithm.EaDiagnostics",
autospec=True,
)
mocked_ead = mocker.Mock()
mocker.patch(
"bingo.evolutionary_algorithms." "generalized_crowding.VarAnd",
autospec=True,
Expand All @@ -33,6 +29,11 @@ def test_all_phases_occur_in_correct_order(mocker):
autospec=True,
return_value=mocked_selection,
)
mocker.patch(
"bingo.evolutionary_algorithms.evolutionary_algorithm.EaDiagnostics",
autospec=True,
return_value=mocked_ead,
)

evo_alg = GeneralizedCrowdingEA(
mocked_evaluation,
Expand All @@ -53,7 +54,7 @@ def test_all_phases_occur_in_correct_order(mocker):
assert (
mocked_selection.call_args[0][0] == dummy_population + dummy_offspring
)
ead.update.assert_called_once_with(
mocked_ead.update.assert_called_once_with(
dummy_population,
dummy_offspring,
mocked_variation.offspring_parents,
Expand Down Expand Up @@ -89,3 +90,30 @@ def test_creates_var_and(mocker):
mocked_crossover, mocked_mutation, 0.5, 0.3
)
generalized_crowding.DeterministicCrowding.assert_called_once()


def test_creates_ea_diagnostics(mocker):
mocked_crossover = mocker.Mock()
mocked_mutation = mocker.Mock()
mocked_evaluation = mocker.Mock()
mocked_variation = mocker.Mock()
mocker.patch(
"bingo.evolutionary_algorithms.generalized_crowding.VarAnd",
return_value=mocked_variation,
)
ead = mocker.patch(
"bingo.evolutionary_algorithms.evolutionary_algorithm.EaDiagnostics",
autospec=True,
)

_ = GeneralizedCrowdingEA(
mocked_evaluation,
mocked_crossover,
mocked_mutation,
crossover_probability=0.5,
mutation_probability=0.3,
)

ead.assert_called_once_with(
mocked_variation.crossover_types, mocked_variation.mutation_types
)

0 comments on commit 873472a

Please sign in to comment.