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 Details

    • execute

      public void execute(Move<Solution_> move)
      Description copied from interface: MoveTestContext
      Executes 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:
      execute in interface MoveTestContext<Solution_>
      Parameters:
      move - the move to execute
    • executeTemporarily

      public void executeTemporarily(Move<Solution_> move, Consumer<SolutionView<Solution_>> callback)
      Description copied from interface: MoveTestContext
      Executes 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:
      executeTemporarily in interface MoveTestContext<Solution_>
      Parameters:
      move - the move to execute temporarily
      callback - to verify the modified solution state before it is undone; receives a SolutionView for read-only access
    • getScoreDirector

      public AbstractScoreDirector<Solution_,?,?> getScoreDirector()