Skip to content

Commit

Permalink
Support <forager><breakTieRandomly>false</></> to for QA testing purp…
Browse files Browse the repository at this point in the history
…oses
  • Loading branch information
ge0ffrey committed Jun 8, 2015
1 parent ca28a55 commit 113a9b3
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 34 deletions.
Expand Up @@ -21,8 +21,6 @@
import org.optaplanner.core.config.util.ConfigUtils; import org.optaplanner.core.config.util.ConfigUtils;
import org.optaplanner.core.impl.localsearch.decider.forager.AcceptedForager; import org.optaplanner.core.impl.localsearch.decider.forager.AcceptedForager;
import org.optaplanner.core.impl.localsearch.decider.forager.Forager; import org.optaplanner.core.impl.localsearch.decider.forager.Forager;
import org.optaplanner.core.impl.localsearch.decider.forager.finalist.FinalistPodium;
import org.optaplanner.core.impl.localsearch.decider.forager.finalist.HighestScoreFinalistPodium;


import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;


Expand All @@ -34,6 +32,7 @@ public class LocalSearchForagerConfig {
protected LocalSearchPickEarlyType pickEarlyType = null; protected LocalSearchPickEarlyType pickEarlyType = null;
protected Integer acceptedCountLimit = null; protected Integer acceptedCountLimit = null;
protected FinalistPodiumType finalistPodiumType = null; protected FinalistPodiumType finalistPodiumType = null;
protected Boolean breakTieRandomly = null;


public Class<? extends Forager> getForagerClass() { public Class<? extends Forager> getForagerClass() {
return foragerClass; return foragerClass;
Expand Down Expand Up @@ -67,6 +66,14 @@ public void setFinalistPodiumType(FinalistPodiumType finalistPodiumType) {
this.finalistPodiumType = finalistPodiumType; this.finalistPodiumType = finalistPodiumType;
} }


public Boolean getBreakTieRandomly() {
return breakTieRandomly;
}

public void setBreakTieRandomly(Boolean breakTieRandomly) {
this.breakTieRandomly = breakTieRandomly;
}

// ************************************************************************ // ************************************************************************
// Builder methods // Builder methods
// ************************************************************************ // ************************************************************************
Expand All @@ -84,7 +91,9 @@ public Forager buildForager(HeuristicConfigPolicy configPolicy) {
LocalSearchPickEarlyType pickEarlyType_ = defaultIfNull(pickEarlyType, LocalSearchPickEarlyType.NEVER); LocalSearchPickEarlyType pickEarlyType_ = defaultIfNull(pickEarlyType, LocalSearchPickEarlyType.NEVER);
int acceptedCountLimit_ = defaultIfNull(acceptedCountLimit, Integer.MAX_VALUE); int acceptedCountLimit_ = defaultIfNull(acceptedCountLimit, Integer.MAX_VALUE);
FinalistPodiumType finalistPodiumType_ = defaultIfNull(finalistPodiumType, FinalistPodiumType.HIGHEST_SCORE); FinalistPodiumType finalistPodiumType_ = defaultIfNull(finalistPodiumType, FinalistPodiumType.HIGHEST_SCORE);
return new AcceptedForager(finalistPodiumType_.buildFinalistPodium(), pickEarlyType_, acceptedCountLimit_); // Breaking ties randomly leads statistically to much better results
boolean breakTieRandomly_ = defaultIfNull(breakTieRandomly, true);
return new AcceptedForager(finalistPodiumType_.buildFinalistPodium(), pickEarlyType_, acceptedCountLimit_, breakTieRandomly_);
} }


public void inherit(LocalSearchForagerConfig inheritedConfig) { public void inherit(LocalSearchForagerConfig inheritedConfig) {
Expand All @@ -96,6 +105,8 @@ public void inherit(LocalSearchForagerConfig inheritedConfig) {
inheritedConfig.getAcceptedCountLimit()); inheritedConfig.getAcceptedCountLimit());
finalistPodiumType = ConfigUtils.inheritOverwritableProperty(finalistPodiumType, finalistPodiumType = ConfigUtils.inheritOverwritableProperty(finalistPodiumType,
inheritedConfig.getFinalistPodiumType()); inheritedConfig.getFinalistPodiumType());
breakTieRandomly = ConfigUtils.inheritOverwritableProperty(breakTieRandomly,
inheritedConfig.getBreakTieRandomly());
} }


} }
Expand Up @@ -16,6 +16,8 @@


package org.optaplanner.core.impl.localsearch.decider.forager; package org.optaplanner.core.impl.localsearch.decider.forager;


import java.util.List;

import org.optaplanner.core.api.score.Score; import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.config.localsearch.decider.forager.LocalSearchPickEarlyType; import org.optaplanner.core.config.localsearch.decider.forager.LocalSearchPickEarlyType;
import org.optaplanner.core.impl.localsearch.decider.acceptor.Acceptor; import org.optaplanner.core.impl.localsearch.decider.acceptor.Acceptor;
Expand All @@ -35,21 +37,23 @@ public class AcceptedForager extends AbstractForager {
protected final FinalistPodium finalistPodium; protected final FinalistPodium finalistPodium;
protected final LocalSearchPickEarlyType pickEarlyType; protected final LocalSearchPickEarlyType pickEarlyType;
protected final int acceptedCountLimit; protected final int acceptedCountLimit;
protected final boolean breakTieRandomly;


protected long selectedMoveCount; protected long selectedMoveCount;
protected long acceptedMoveCount; protected long acceptedMoveCount;


protected LocalSearchMoveScope earlyPickedMoveScope; protected LocalSearchMoveScope earlyPickedMoveScope;


public AcceptedForager(FinalistPodium finalistPodium, public AcceptedForager(FinalistPodium finalistPodium,
LocalSearchPickEarlyType pickEarlyType, int acceptedCountLimit) { LocalSearchPickEarlyType pickEarlyType, int acceptedCountLimit, boolean breakTieRandomly) {
this.finalistPodium = finalistPodium; this.finalistPodium = finalistPodium;
this.pickEarlyType = pickEarlyType; this.pickEarlyType = pickEarlyType;
this.acceptedCountLimit = acceptedCountLimit; this.acceptedCountLimit = acceptedCountLimit;
if (acceptedCountLimit < 1) { if (acceptedCountLimit < 1) {
throw new IllegalArgumentException("The acceptedCountLimit (" + acceptedCountLimit throw new IllegalArgumentException("The acceptedCountLimit (" + acceptedCountLimit
+ ") cannot be negative or zero."); + ") cannot be negative or zero.");
} }
this.breakTieRandomly = breakTieRandomly;
} }


// ************************************************************************ // ************************************************************************
Expand Down Expand Up @@ -123,7 +127,15 @@ public LocalSearchMoveScope pickMove(LocalSearchStepScope stepScope) {
if (earlyPickedMoveScope != null) { if (earlyPickedMoveScope != null) {
return earlyPickedMoveScope; return earlyPickedMoveScope;
} }
return finalistPodium.pickMove(stepScope); List<LocalSearchMoveScope> finalistList = finalistPodium.getFinalistList();
if (finalistList.isEmpty()) {
return null;
}
if (finalistList.size() == 1 || !breakTieRandomly) {
return finalistList.get(0);
}
int randomIndex = stepScope.getWorkingRandom().nextInt(finalistList.size());
return finalistList.get(randomIndex);
} }


@Override @Override
Expand Down
Expand Up @@ -44,15 +44,8 @@ public void stepStarted(LocalSearchStepScope stepScope) {
finalistList = new ArrayList<LocalSearchMoveScope>(1024); finalistList = new ArrayList<LocalSearchMoveScope>(1024);
} }


public LocalSearchMoveScope pickMove(LocalSearchStepScope stepScope) { public List<LocalSearchMoveScope> getFinalistList() {
if (finalistList.isEmpty()) { return finalistList;
return null;
}
if (finalistList.size() == 1) {
return finalistList.get(0);
}
int randomIndex = stepScope.getWorkingRandom().nextInt(finalistList.size());
return finalistList.get(randomIndex);
} }


@Override @Override
Expand Down
Expand Up @@ -16,6 +16,8 @@


package org.optaplanner.core.impl.localsearch.decider.forager.finalist; package org.optaplanner.core.impl.localsearch.decider.forager.finalist;


import java.util.List;

import org.optaplanner.core.impl.localsearch.decider.forager.Forager; import org.optaplanner.core.impl.localsearch.decider.forager.Forager;
import org.optaplanner.core.impl.localsearch.event.LocalSearchPhaseLifecycleListener; import org.optaplanner.core.impl.localsearch.event.LocalSearchPhaseLifecycleListener;
import org.optaplanner.core.impl.localsearch.scope.LocalSearchMoveScope; import org.optaplanner.core.impl.localsearch.scope.LocalSearchMoveScope;
Expand All @@ -35,10 +37,9 @@ public interface FinalistPodium extends LocalSearchPhaseLifecycleListener {
void addMove(LocalSearchMoveScope moveScope); void addMove(LocalSearchMoveScope moveScope);


/** /**
* See {@link Forager#pickMove(LocalSearchStepScope)}. *
* @param stepScope never null * @return never null, sometimes empty
* @return sometimes null, for example if no move is selected
*/ */
LocalSearchMoveScope pickMove(LocalSearchStepScope stepScope); List<LocalSearchMoveScope> getFinalistList();


} }
Expand Up @@ -41,7 +41,7 @@ public class AcceptedForagerTest {
public void pickMoveMaxScoreAccepted() { public void pickMoveMaxScoreAccepted() {
// Setup // Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(), Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.NEVER, Integer.MAX_VALUE); LocalSearchPickEarlyType.NEVER, Integer.MAX_VALUE, true);
LocalSearchPhaseScope phaseScope = createPhaseScope(); LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope); forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope); LocalSearchStepScope stepScope = createStepScope(phaseScope);
Expand Down Expand Up @@ -73,7 +73,7 @@ public void pickMoveMaxScoreAccepted() {
public void pickMoveMaxScoreUnaccepted() { public void pickMoveMaxScoreUnaccepted() {
// Setup // Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(), Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.NEVER, Integer.MAX_VALUE); LocalSearchPickEarlyType.NEVER, Integer.MAX_VALUE, true);
LocalSearchPhaseScope phaseScope = createPhaseScope(); LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope); forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope); LocalSearchStepScope stepScope = createStepScope(phaseScope);
Expand Down Expand Up @@ -105,7 +105,7 @@ public void pickMoveMaxScoreUnaccepted() {
public void pickMoveFirstBestScoreImproving() { public void pickMoveFirstBestScoreImproving() {
// Setup // Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(), Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.FIRST_BEST_SCORE_IMPROVING, Integer.MAX_VALUE); LocalSearchPickEarlyType.FIRST_BEST_SCORE_IMPROVING, Integer.MAX_VALUE, true);
LocalSearchPhaseScope phaseScope = createPhaseScope(); LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope); forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope); LocalSearchStepScope stepScope = createStepScope(phaseScope);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void pickMoveFirstBestScoreImproving() {
public void pickMoveFirstLastStepScoreImproving() { public void pickMoveFirstLastStepScoreImproving() {
// Setup // Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(), Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.FIRST_LAST_STEP_SCORE_IMPROVING, Integer.MAX_VALUE); LocalSearchPickEarlyType.FIRST_LAST_STEP_SCORE_IMPROVING, Integer.MAX_VALUE, true);
LocalSearchPhaseScope phaseScope = createPhaseScope(); LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope); forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope); LocalSearchStepScope stepScope = createStepScope(phaseScope);
Expand All @@ -160,10 +160,10 @@ public void pickMoveFirstLastStepScoreImproving() {
} }


@Test @Test
public void pickMoveAcceptedRandomly() { public void pickMoveAcceptedBreakTieRandomly() {
// Setup // Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(), Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.NEVER, 3); LocalSearchPickEarlyType.NEVER, 4, true);
LocalSearchPhaseScope phaseScope = createPhaseScope(); LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope); forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope); LocalSearchStepScope stepScope = createStepScope(phaseScope);
Expand All @@ -173,6 +173,7 @@ public void pickMoveAcceptedRandomly() {
LocalSearchMoveScope b = createMoveScope(stepScope, SimpleScore.valueOf(-1), true); LocalSearchMoveScope b = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
LocalSearchMoveScope c = createMoveScope(stepScope, SimpleScore.valueOf(-1), true); LocalSearchMoveScope c = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
LocalSearchMoveScope d = createMoveScope(stepScope, SimpleScore.valueOf(-20), true); LocalSearchMoveScope d = createMoveScope(stepScope, SimpleScore.valueOf(-20), true);
LocalSearchMoveScope e = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
// Do stuff // Do stuff
forager.addMove(a); forager.addMove(a);
assertFalse(forager.isQuitEarly()); assertFalse(forager.isQuitEarly());
Expand All @@ -181,6 +182,40 @@ public void pickMoveAcceptedRandomly() {
forager.addMove(c); forager.addMove(c);
assertFalse(forager.isQuitEarly()); assertFalse(forager.isQuitEarly());
forager.addMove(d); forager.addMove(d);
assertFalse(forager.isQuitEarly());
forager.addMove(e);
assertTrue(forager.isQuitEarly());
// Post conditions
LocalSearchMoveScope pickedScope = forager.pickMove(stepScope);
assertSame(c, pickedScope);
forager.phaseEnded(phaseScope);
}

@Test
public void pickMoveAcceptedBreakTieFirst() {
// Setup
Forager forager = new AcceptedForager(new HighestScoreFinalistPodium(),
LocalSearchPickEarlyType.NEVER, 4, false);
LocalSearchPhaseScope phaseScope = createPhaseScope();
forager.phaseStarted(phaseScope);
LocalSearchStepScope stepScope = createStepScope(phaseScope);
forager.stepStarted(stepScope);
// Pre conditions
LocalSearchMoveScope a = createMoveScope(stepScope, SimpleScore.valueOf(-20), false);
LocalSearchMoveScope b = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
LocalSearchMoveScope c = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
LocalSearchMoveScope d = createMoveScope(stepScope, SimpleScore.valueOf(-20), true);
LocalSearchMoveScope e = createMoveScope(stepScope, SimpleScore.valueOf(-1), true);
// Do stuff
forager.addMove(a);
assertFalse(forager.isQuitEarly());
forager.addMove(b);
assertFalse(forager.isQuitEarly());
forager.addMove(c);
assertFalse(forager.isQuitEarly());
forager.addMove(d);
assertFalse(forager.isQuitEarly());
forager.addMove(e);
assertTrue(forager.isQuitEarly()); assertTrue(forager.isQuitEarly());
// Post conditions // Post conditions
LocalSearchMoveScope pickedScope = forager.pickMove(stepScope); LocalSearchMoveScope pickedScope = forager.pickMove(stepScope);
Expand All @@ -196,7 +231,7 @@ private LocalSearchPhaseScope createPhaseScope() {
when(scoreDirector.getScoreDefinition()).thenReturn(new SimpleScoreDefinition()); when(scoreDirector.getScoreDefinition()).thenReturn(new SimpleScoreDefinition());
solverScope.setScoreDirector(scoreDirector); solverScope.setScoreDirector(scoreDirector);
Random workingRandom = mock(Random.class); Random workingRandom = mock(Random.class);
when(workingRandom.nextInt(2)).thenReturn(0); when(workingRandom.nextInt(3)).thenReturn(1);
solverScope.setWorkingRandom(workingRandom); solverScope.setWorkingRandom(workingRandom);
solverScope.setBestScore(SimpleScore.valueOf(-10)); solverScope.setBestScore(SimpleScore.valueOf(-10));
LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(phaseScope); LocalSearchStepScope lastLocalSearchStepScope = new LocalSearchStepScope(phaseScope);
Expand Down
Expand Up @@ -27,6 +27,7 @@


import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.optaplanner.core.impl.testdata.util.PlannerAssert.extractSingleton;


public class StrategicOscillationByLevelFinalistPodiumTest { public class StrategicOscillationByLevelFinalistPodiumTest {


Expand All @@ -49,7 +50,7 @@ public void referenceLastStepScore() {
finalistPodium.addMove(moveScope0); finalistPodium.addMove(moveScope0);
finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100)); finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100));
finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000)); finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000));
assertSame(moveScope0, finalistPodium.pickMove(stepScope0)); assertSame(moveScope0, extractSingleton(finalistPodium.getFinalistList()));
stepScope0.setScore(moveScope0.getScore()); stepScope0.setScore(moveScope0.getScore());
finalistPodium.stepEnded(stepScope0); finalistPodium.stepEnded(stepScope0);
phaseScope.setLastCompletedStepScope(stepScope0); phaseScope.setLastCompletedStepScope(stepScope0);
Expand All @@ -63,7 +64,7 @@ public void referenceLastStepScore() {
finalistPodium.addMove(moveScope1); finalistPodium.addMove(moveScope1);
finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000)); finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000));
finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000)); finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000));
assertSame(moveScope1, finalistPodium.pickMove(stepScope1)); assertSame(moveScope1, extractSingleton(finalistPodium.getFinalistList()));
stepScope1.setScore(moveScope1.getScore()); stepScope1.setScore(moveScope1.getScore());
finalistPodium.stepEnded(stepScope1); finalistPodium.stepEnded(stepScope1);
phaseScope.setLastCompletedStepScope(stepScope1); phaseScope.setLastCompletedStepScope(stepScope1);
Expand All @@ -77,7 +78,7 @@ public void referenceLastStepScore() {
finalistPodium.addMove(moveScope2); finalistPodium.addMove(moveScope2);
finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000)); finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000));
finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500)); finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500));
assertSame(moveScope2, finalistPodium.pickMove(stepScope2)); assertSame(moveScope2, extractSingleton(finalistPodium.getFinalistList()));
stepScope2.setScore(moveScope2.getScore()); stepScope2.setScore(moveScope2.getScore());
finalistPodium.stepEnded(stepScope2); finalistPodium.stepEnded(stepScope2);
phaseScope.setLastCompletedStepScope(stepScope2); phaseScope.setLastCompletedStepScope(stepScope2);
Expand All @@ -102,7 +103,7 @@ public void referenceBestScore() {
finalistPodium.addMove(moveScope0); finalistPodium.addMove(moveScope0);
finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100)); finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100));
finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000)); finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000));
assertSame(moveScope0, finalistPodium.pickMove(stepScope0)); assertSame(moveScope0, extractSingleton(finalistPodium.getFinalistList()));
stepScope0.setScore(moveScope0.getScore()); stepScope0.setScore(moveScope0.getScore());
finalistPodium.stepEnded(stepScope0); finalistPodium.stepEnded(stepScope0);
phaseScope.setLastCompletedStepScope(stepScope0); phaseScope.setLastCompletedStepScope(stepScope0);
Expand All @@ -117,7 +118,7 @@ public void referenceBestScore() {
finalistPodium.addMove(moveScope1); finalistPodium.addMove(moveScope1);
finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000)); finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000));
finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000)); finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000));
assertSame(moveScope1, finalistPodium.pickMove(stepScope1)); assertSame(moveScope1, extractSingleton(finalistPodium.getFinalistList()));
stepScope1.setScore(moveScope1.getScore()); stepScope1.setScore(moveScope1.getScore());
finalistPodium.stepEnded(stepScope1); finalistPodium.stepEnded(stepScope1);
phaseScope.setLastCompletedStepScope(stepScope1); phaseScope.setLastCompletedStepScope(stepScope1);
Expand All @@ -132,7 +133,7 @@ public void referenceBestScore() {
finalistPodium.addMove(moveScope2); finalistPodium.addMove(moveScope2);
finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000)); finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000));
finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500)); finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500));
assertSame(moveScope2, finalistPodium.pickMove(stepScope2)); assertSame(moveScope2, extractSingleton(finalistPodium.getFinalistList()));
stepScope2.setScore(moveScope2.getScore()); stepScope2.setScore(moveScope2.getScore());
finalistPodium.stepEnded(stepScope2); finalistPodium.stepEnded(stepScope2);
phaseScope.setLastCompletedStepScope(stepScope2); phaseScope.setLastCompletedStepScope(stepScope2);
Expand Down Expand Up @@ -167,7 +168,7 @@ public void referenceLastStepScore3Levels() {
finalistPodium.addMove(moveScope0); finalistPodium.addMove(moveScope0);
finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100, -5)); finalistPodium.addMove(buildMoveScope(stepScope0, -100, -7100, -5));
finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000, -10)); finalistPodium.addMove(buildMoveScope(stepScope0, -200, -1000, -10));
assertSame(moveScope0, finalistPodium.pickMove(stepScope0)); assertSame(moveScope0, extractSingleton(finalistPodium.getFinalistList()));
stepScope0.setScore(moveScope0.getScore()); stepScope0.setScore(moveScope0.getScore());
finalistPodium.stepEnded(stepScope0); finalistPodium.stepEnded(stepScope0);
phaseScope.setLastCompletedStepScope(stepScope0); phaseScope.setLastCompletedStepScope(stepScope0);
Expand All @@ -181,7 +182,7 @@ public void referenceLastStepScore3Levels() {
finalistPodium.addMove(moveScope1); finalistPodium.addMove(moveScope1);
finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000, -10)); finalistPodium.addMove(buildMoveScope(stepScope1, -150, -2000, -10));
finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000, -10)); finalistPodium.addMove(buildMoveScope(stepScope1, -200, -1000, -10));
assertSame(moveScope1, finalistPodium.pickMove(stepScope1)); assertSame(moveScope1, extractSingleton(finalistPodium.getFinalistList()));
stepScope1.setScore(moveScope1.getScore()); stepScope1.setScore(moveScope1.getScore());
finalistPodium.stepEnded(stepScope1); finalistPodium.stepEnded(stepScope1);
phaseScope.setLastCompletedStepScope(stepScope1); phaseScope.setLastCompletedStepScope(stepScope1);
Expand All @@ -195,7 +196,7 @@ public void referenceLastStepScore3Levels() {
finalistPodium.addMove(moveScope2); finalistPodium.addMove(moveScope2);
finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000, -10)); finalistPodium.addMove(buildMoveScope(stepScope2, -150, -2000, -10));
finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500, -10)); finalistPodium.addMove(buildMoveScope(stepScope2, -160, -500, -10));
assertSame(moveScope2, finalistPodium.pickMove(stepScope2)); assertSame(moveScope2, extractSingleton(finalistPodium.getFinalistList()));
stepScope2.setScore(moveScope2.getScore()); stepScope2.setScore(moveScope2.getScore());
finalistPodium.stepEnded(stepScope2); finalistPodium.stepEnded(stepScope2);
phaseScope.setLastCompletedStepScope(stepScope2); phaseScope.setLastCompletedStepScope(stepScope2);
Expand Down
Expand Up @@ -380,6 +380,11 @@ public static void assertAllCodesOfSubChainSelector(SubChainSelector subChainSel
} }
} }


public static <E> E extractSingleton(List<E> singletonList) {
assertEquals(1, singletonList.size());
return singletonList.get(0);
}

private PlannerAssert() { private PlannerAssert() {
} }


Expand Down

0 comments on commit 113a9b3

Please sign in to comment.