Skip to content

Commit

Permalink
fix and clarify SingleConstraintAssertion test
Browse files Browse the repository at this point in the history
  • Loading branch information
RobJohansen committed Sep 8, 2023
1 parent 623d913 commit d9a6cf3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
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

0 comments on commit d9a6cf3

Please sign in to comment.