@Override public int compareTo(HardSoftScore other) { // A direct implementation (instead of CompareToBuilder) to avoid dependencies if (initScore != other.getInitScore()) { return initScore < other.getInitScore() ? -1 : 1; } else if (hardScore != other.getHardScore()) { return hardScore < other.getHardScore() ? -1 : 1; } else { return Integer.compare(softScore, other.getSoftScore()); } }
@Override public boolean equals(Object o) { // A direct implementation (instead of EqualsBuilder) to avoid dependencies if (this == o) { return true; } else if (o instanceof HardSoftScore) { HardSoftScore other = (HardSoftScore) o; return initScore == other.getInitScore() && hardScore == other.getHardScore() && softScore == other.getSoftScore(); } else { return false; } }
@Override public HardSoftScore add(HardSoftScore augment) { return new HardSoftScore( initScore + augment.getInitScore(), hardScore + augment.getHardScore(), softScore + augment.getSoftScore()); }
@Override public HardSoftScore subtract(HardSoftScore subtrahend) { return new HardSoftScore( initScore - subtrahend.getInitScore(), hardScore - subtrahend.getHardScore(), softScore - subtrahend.getSoftScore()); }
@Test public void buildOptimisticBoundOnlyDown() { HardSoftScoreDefinition scoreDefinition = new HardSoftScoreDefinition(); HardSoftScore optimisticBound = scoreDefinition.buildOptimisticBound( InitializingScoreTrend.buildUniformTrend(InitializingScoreTrendLevel.ONLY_DOWN, 2), HardSoftScore.of(-1, -2)); assertEquals(0, optimisticBound.getInitScore()); assertEquals(-1, optimisticBound.getHardScore()); assertEquals(-2, optimisticBound.getSoftScore()); }
@Test public void serializeAndDeserialize() { PlannerTestUtils.serializeAndDeserializeWithAll( HardSoftScore.of(-12, 3400), output -> { assertEquals(0, output.getInitScore()); assertEquals(-12, output.getHardScore()); assertEquals(3400, output.getSoftScore()); } ); PlannerTestUtils.serializeAndDeserializeWithAll( HardSoftScore.ofUninitialized(-7, -12, 3400), output -> { assertEquals(-7, output.getInitScore()); assertEquals(-12, output.getHardScore()); assertEquals(3400, output.getSoftScore()); } ); }
@Test public void buildOptimisticBoundOnlyUp() { HardSoftScoreDefinition scoreDefinition = new HardSoftScoreDefinition(); HardSoftScore optimisticBound = scoreDefinition.buildOptimisticBound( InitializingScoreTrend.buildUniformTrend(InitializingScoreTrendLevel.ONLY_UP, 2), HardSoftScore.of(-1, -2)); assertEquals(0, optimisticBound.getInitScore()); assertEquals(Integer.MAX_VALUE, optimisticBound.getHardScore()); assertEquals(Integer.MAX_VALUE, optimisticBound.getSoftScore()); }
@Test public void buildPessimisticBoundOnlyUp() { HardSoftScoreDefinition scoreDefinition = new HardSoftScoreDefinition(); HardSoftScore pessimisticBound = scoreDefinition.buildPessimisticBound( InitializingScoreTrend.buildUniformTrend(InitializingScoreTrendLevel.ONLY_UP, 2), HardSoftScore.of(-1, -2)); assertEquals(0, pessimisticBound.getInitScore()); assertEquals(-1, pessimisticBound.getHardScore()); assertEquals(-2, pessimisticBound.getSoftScore()); }
@Test public void buildPessimisticBoundOnlyDown() { HardSoftScoreDefinition scoreDefinition = new HardSoftScoreDefinition(); HardSoftScore pessimisticBound = scoreDefinition.buildPessimisticBound( InitializingScoreTrend.buildUniformTrend(InitializingScoreTrendLevel.ONLY_DOWN, 2), HardSoftScore.of(-1, -2)); assertEquals(0, pessimisticBound.getInitScore()); assertEquals(Integer.MIN_VALUE, pessimisticBound.getHardScore()); assertEquals(Integer.MIN_VALUE, pessimisticBound.getSoftScore()); }