Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLANNER-2932 fix impact assertion in constraint verifier #2947

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ private void assertImpact(ScoreImpactType scoreImpactType, Number matchWeightTot
if (actualScoreImpactType == ScoreImpactType.MIXED) {
// Impact means we need to check for expected impact type and actual impact match.
switch (scoreImpactType) {
case REWARD:
case PENALTY:
Number negatedImpact = deducedImpacts.getValue();
if (equalityPredicate.test(matchWeightTotal, negatedImpact)) {
return;
}
break;
case PENALTY:
case REWARD:
if (equalityPredicate.test(matchWeightTotal, impact)) {
return;
}
Expand Down Expand Up @@ -235,9 +235,9 @@ private long determineMatchCount(ScoreImpactType scoreImpactType) {
if (actualImpactType == ScoreImpactType.MIXED) {
boolean isImpactPositive = constraintMatchTotal.getScore().compareTo(zeroScore) > 0;
boolean isImpactNegative = constraintMatchTotal.getScore().compareTo(zeroScore) < 0;
if (isImpactPositive && scoreImpactType == ScoreImpactType.PENALTY) {
if (isImpactPositive && scoreImpactType == ScoreImpactType.REWARD) {
return constraintMatchTotal.getConstraintMatchSet().size();
} else if (isImpactNegative && scoreImpactType == ScoreImpactType.REWARD) {
} else if (isImpactNegative && scoreImpactType == ScoreImpactType.PENALTY) {
return constraintMatchTotal.getConstraintMatchSet().size();
} else {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ void impacts() {
.penalizes(0, "There should be no penalties"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizes(0, "There should be no penalties"))
.hasMessageContaining("There should be no penalties")
.hasMessageContaining("Expected penalty");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizes(1, "There should be penalties"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizes(2, "There should only be one penalty"))
.hasMessageContaining("There should only be one penalty")
.hasMessageContaining("Expected penalty");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.rewards(1, "There should not be rewards"))
.hasMessageContaining("There should not be rewards")
.hasMessageContaining("Expected reward");
Expand All @@ -96,21 +96,21 @@ void impacts() {
.rewards(0, "There should be no rewards"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewards(0, "There should be no rewards"))
.hasMessageContaining("There should be no rewards")
.hasMessageContaining("Expected reward");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewards(1, "There should be rewards"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewards(2, "There should only be one reward"))
.hasMessageContaining("There should only be one reward")
.hasMessageContaining("Expected reward");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.penalizes(1, "There should not be penalties"))
.hasMessageContaining("There should not be penalties")
.hasMessageContaining("Expected penalty");
Expand All @@ -123,21 +123,21 @@ void impactsBy() {
.penalizesBy(0, "There should no penalties"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizesBy(0, "There should be no penalties"))
.hasMessageContaining("There should be no penalties")
.hasMessageContaining("Expected penalty");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizesBy(1, "There should be penalties"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.penalizesBy(2, "There should only be one penalty"))
.hasMessageContaining("There should only be one penalty")
.hasMessageContaining("Expected penalty");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("A", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("PENALIZE", new TestdataValue()))
.rewardsWith(1, "There should not be rewards"))
.hasMessageContaining("There should not be rewards")
.hasMessageContaining("Expected reward");
Expand All @@ -147,21 +147,21 @@ void impactsBy() {
.rewardsWith(0, "There should no rewards"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewardsWith(0, "There should be no rewards"))
.hasMessageContaining("There should be no rewards")
.hasMessageContaining("Expected reward");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewardsWith(1, "There should be rewards"))
.doesNotThrowAnyException();
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.rewardsWith(2, "There should only be one reward"))
.hasMessageContaining("There should only be one reward")
.hasMessageContaining("Expected reward");
assertThatCode(() -> constraintVerifier.verifyThat(TestdataConstraintVerifierConstraintProvider::impactEveryEntity)
.given(new TestdataConstraintVerifierFirstEntity("B", new TestdataValue()))
.given(new TestdataConstraintVerifierFirstEntity("REWARD", new TestdataValue()))
.penalizesBy(1, "There should not be penalties"))
.hasMessageContaining("There should not be penalties")
.hasMessageContaining("Expected penalty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Constraint rewardEveryEntity(ConstraintFactory constraintFactory) {
public Constraint impactEveryEntity(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(TestdataConstraintVerifierFirstEntity.class)
.impact(HardSoftScore.ofHard(4),
entity -> Objects.equals(entity.getCode(), "A") ? 1 : -1)
entity -> Objects.equals(entity.getCode(), "REWARD") ? 1 : -1)
.asConstraint("Impact every standard entity");
}

Expand Down
Loading