Skip to content

Commit

Permalink
Multiple changes for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Kocian authored and ge0ffrey committed Jul 11, 2019
1 parent f864e91 commit 92ef299
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GreatDelugeAcceptor extends AbstractAcceptor {
private Score initialLevel = null;

private Double rainSpeed = null;
private Double rainSpeedRatio = null;
private Double rainSpeedRatio = DEFAULT_RAIN_SPEED_RATIO;

private int levelsLength = -1;
private double[] initialLevelScoreLevels;
Expand All @@ -28,7 +28,10 @@ public class GreatDelugeAcceptor extends AbstractAcceptor {

public Score getInitialLevels() { return this.initialLevel; }

public void setRainSpeed(Double rainSpeed) { this.rainSpeed = rainSpeed; }
public void setRainSpeed(Double rainSpeed) {
this.rainSpeed = rainSpeed;
this.rainSpeedRatio = null;
}

public Double getRainSpeed() { return this.rainSpeed; }

Expand All @@ -53,16 +56,13 @@ public void phaseStarted(LocalSearchPhaseScope phaseScope) {
} else {
double[] initialLevelScoreLevelsNegative;
initialLevelScoreLevelsNegative = ScoreUtils.extractLevelDoubles(phaseScope.getBestScore());
logger.info("{}", phaseScope.getBestScore().toShortString());
levelScoreLevels = initialLevelScoreLevelsNegative;

for (int i = 0; i < levelScoreLevels.length; i++) {
if (Math.abs(levelScoreLevels[i]) < THRESHOLD) {
logger.info("{}", Double.toString(levelScoreLevels[i]));
continue;
}
levelScoreLevels[i] = -levelScoreLevels[i];
logger.info("{}", Double.toString(levelScoreLevels[i]));
}
}
levelsLength = levelScoreLevels.length;
Expand All @@ -85,11 +85,16 @@ public boolean isAccepted(LocalSearchMoveScope moveScope) {
double moveScoreLevel = moveScoreLevels[i];
double levelScoreLevel = levelScoreLevels[i];

double isZeroIfEqual = Math.abs(moveScoreLevel + levelScoreLevel);

if (moveScoreLevel > -levelScoreLevel) {
// Checks if given score is better than water level, if so, move is accepted.
return true;
} else if (!(Math.abs(moveScoreLevel + levelScoreLevel) < THRESHOLD)) {
} else if (!(isZeroIfEqual < THRESHOLD)) {
// Returns false when above condition is not met and, new score and water level are not equal.
return false;
} else if (i == levelsLength -1){
} else if (i == levelsLength - 1){
// Returns true when new score and water level are equal and it is last iteration of cycle.
return true;
}
}
Expand All @@ -104,8 +109,6 @@ public void stepStarted(LocalSearchStepScope stepScope) {
levelScoreLevels[i] = levelScoreLevels[i] - rainSpeed;
} else if (rainSpeedRatio != null) {
levelScoreLevels[i] = levelScoreLevels[i] * rainSpeedRatio;
} else {
levelScoreLevels[i] = levelScoreLevels[i] * DEFAULT_RAIN_SPEED_RATIO;
}
if (levelScoreLevels[i] < levelMinimum) {
levelScoreLevels[i] = levelMinimum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions;


public class GreatDelugeAcceptorTest extends AbstractAcceptorTest {
Expand Down Expand Up @@ -195,8 +194,7 @@ public void negativeWaterLevelSingleScore() {
acceptor.setInitialLevels(SimpleScore.of(-100));
try {
acceptor.phaseStarted(null);
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
assertEquals("The initial level (" + acceptor.getInitialLevels()
+ ") cannot have negative level (" + "-100.0" + ").", e.getMessage());
}
Expand All @@ -208,8 +206,7 @@ public void negativeWaterLevelMultipleScore() {
acceptor.setInitialLevels(HardMediumSoftScore.parseScore("1hard/-1medium/2soft"));
try {
acceptor.phaseStarted(null);
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
assertEquals("The initial level (" + acceptor.getInitialLevels()
+ ") cannot have negative level (" + "-1.0" + ").", e.getMessage());
}
Expand All @@ -223,7 +220,7 @@ public void parsingLevelScoreLevelsFromInitialLevelSingleScore() {
double[] actualScore = {150};
acceptor.phaseStarted(null);

assertEquals(true, Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
assertTrue(Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
}

@Test
Expand All @@ -234,7 +231,7 @@ public void parsingLevelScoreLevelsFromInitialLevelMultipleScore() {
double[] actualScore = {1, 15, 24};
acceptor.phaseStarted(null);

assertEquals(true, Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
assertTrue(Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
}

@Test
Expand All @@ -252,7 +249,7 @@ public void parsingLevelScoreLevelsFromPhaseBestScoreSingleScore() {
acceptor.phaseStarted(phaseScope);
double[] actualScore = {66};

assertEquals(true, Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
assertTrue(Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
}

@Test
Expand All @@ -270,6 +267,6 @@ public void parsingLevelScoreLevelsFromPhaseBestScoreMultipleScore() {
acceptor.phaseStarted(phaseScope);
double[] actualScore = {5, 0, 24};

assertEquals(true, Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
assertTrue(Arrays.equals(actualScore, acceptor.getLevelScoreLevels()));
}
}

0 comments on commit 92ef299

Please sign in to comment.