diff --git a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java index 3f68ef701e..fbe6ebccaf 100644 --- a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java +++ b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java @@ -21,7 +21,7 @@ class ShiftScheduleConstraintProviderUnitTest { constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::atMostOneShiftPerDay) .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), null, ann), new Shift(MONDAY.atTime(14, 0), MONDAY.atTime(22, 0), null, ann)) // Penalizes by 2 because both {shiftA, shiftB} and {shiftB, shiftA} match. - // To avoid that, use forEachUniquePair() in the constraint instead. + // To avoid that, use forEachUniquePair() in the constraint instead of forEach().join() in the implementation. .penalizesBy(2); } diff --git a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java index 45a84b40da..8b57fb42b6 100644 --- a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java +++ b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java @@ -1,5 +1,7 @@ package com.baeldung.timefoldsolver; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + import java.time.Duration; import java.time.LocalDate; import java.util.List; @@ -23,13 +25,17 @@ public class ShiftScheduleSolverUnitTest { SolverFactory solverFactory = SolverFactory.create(new SolverConfig().withSolutionClass(ShiftSchedule.class) .withEntityClasses(Shift.class) .withConstraintProviderClass(ShiftScheduleConstraintProvider.class) - // The solver runs only for 2 seconds on this tiny dataset. - // It's recommended to run for at least 5 minutes ("5m") on large datasets. - .withTerminationSpentLimit(Duration.ofSeconds(2))); + // For this dataset, we know the optimal score in advance (which is normally not the case). + // So we can use .withBestScoreLimit() instead of .withTerminationSpentLimit(). + .withTerminationConfig(new TerminationConfig().withBestScoreLimit("0hard/0soft"))); Solver solver = solverFactory.buildSolver(); ShiftSchedule problem = loadProblem(); ShiftSchedule solution = solver.solve(problem); + assertThat(solution.getShifts().size()).isNotZero(); + for (Shift shift : solution.getShifts()) { + assertThat(shift.getEmployee()).isNotNull(); + } printSolution(solution); }