Class DefaultMoveTestContext<Solution_>
java.lang.Object
ai.timefold.solver.core.impl.move.DefaultMoveTestContext<Solution_>
- All Implemented Interfaces:
MoveTestContext<Solution_>
@NullMarked
public final class DefaultMoveTestContext<Solution_>
extends Object
implements MoveTestContext<Solution_>
-
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes the given move permanently on the bound solution.voidexecuteTemporarily(Move<Solution_> move, Consumer<SolutionView<Solution_>> callback) Executes the given move temporarily on the bound solution, runs assertions, then automatically undoes the move.
-
Method Details
-
execute
Description copied from interface:MoveTestContextExecutes the given move permanently on the bound solution.Changes made by the move persist after this method returns. Shadow variables are automatically updated via the solver's existing mechanisms.
If the move throws an exception, the exception propagates to the caller and the solution state may be only partially modified. In this case, the caller must discard the solution instance and get a new instance of this class via
MoveTester.using(Object).- Specified by:
executein interfaceMoveTestContext<Solution_>- Parameters:
move- the move to execute
-
executeTemporarily
Description copied from interface:MoveTestContextExecutes the given move temporarily on the bound solution, runs assertions, then automatically undoes the move.The move is executed, modifying the solution state. The assertions callback is then invoked, allowing the caller to verify the modified state. Finally, the move is automatically undone, restoring the solution to its exact pre-execution state.
Important constraints:
- Nesting executeTemporarily() calls is not supported and results in undefined behavior
- Do not modify the solution state directly within the assertions callback; doing so results in undefined behavior with unpredictable undo results
- If an exception occurs during move execution, the callback, or undo operation,
the solution state is undefined and no restoration is attempted.
The caller must discard the solution instance
and get a new instance of this class via
MoveTester.using(Object).
- Specified by:
executeTemporarilyin interfaceMoveTestContext<Solution_>- Parameters:
move- the move to execute temporarilycallback- to verify the modified solution state before it is undone; receives aSolutionViewfor read-only access
-
getScoreDirector
-