Skip to content

Commit

Permalink
test: do not create a new entity in EnvironmentMode test
Browse files Browse the repository at this point in the history
When the test creates a new entity in its undo move and assigns it,
it increases the init score from 0 to 1, an impossible state that
should never occur in correctly implemented move(s). This could
result in a fail-fast in the future that is not related to the
EnvironmentMode being tested. Now the test use an existing but
different entity to achieve the desired corruption.
  • Loading branch information
Christopher-Chianelli authored and triceo committed Dec 14, 2023
1 parent aaa0ebc commit 02be447
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import ai.timefold.solver.core.impl.testdata.domain.TestdataValue;

public class TestdataCorruptedEntityUndoMove extends AbstractTestdataMove {
TestdataEntity undoEntity;

public TestdataCorruptedEntityUndoMove(TestdataEntity entity, TestdataValue toValue) {
public TestdataCorruptedEntityUndoMove(TestdataEntity entity, TestdataEntity undoEntity, TestdataValue toValue) {
super(entity, toValue);
this.undoEntity = undoEntity;
}

@Override
protected AbstractMove<TestdataSolution> createUndoMove(ScoreDirector<TestdataSolution> scoreDirector) {
// Corrupts the undo move by creating a new entity and not undo-ing the value
return new TestdataCorruptedEntityUndoMove(new TestdataEntity("corrupted"), toValue);
// Corrupts the undo move by using a different entity and not undo-ing the value
return new TestdataCorruptedEntityUndoMove(undoEntity, entity, toValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public TestdataCorruptedUndoMove(TestdataEntity entity, TestdataValue toValue) {
@Override
protected AbstractMove<TestdataSolution> createUndoMove(ScoreDirector<TestdataSolution> scoreDirector) {
// Corrupts the undo move by not undo-ing the value
return new TestdataCorruptedEntityUndoMove(entity, toValue);
return new TestdataCorruptedUndoMove(entity, toValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ public List<? extends Move<TestdataSolution>> createMoveList(TestdataSolution so
for (TestdataEntity entity : solution.getEntityList()) {
for (TestdataValue value : solution.getValueList()) {
if (corruptEntityAsWell) {
moveList.add(new TestdataCorruptedEntityUndoMove(entity, value));
for (TestdataEntity undoEntity : solution.getEntityList()) {
if (entity == undoEntity) {
continue;
}
moveList.add(new TestdataCorruptedEntityUndoMove(entity, undoEntity, value));
}
} else {
moveList.add(new TestdataCorruptedUndoMove(entity, value));
}
Expand Down

0 comments on commit 02be447

Please sign in to comment.