diff --git a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderTest.java b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderTest.java index c4741a831b..0832cd7bdd 100644 --- a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderTest.java +++ b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderTest.java @@ -16,24 +16,33 @@ class ShiftScheduleConstraintProviderTest { ShiftSchedule.class, Shift.class); @Test - void atMostOneShiftPerDay() { + void whenTwoShiftsOnOneDay_thenPenalize() { Employee ann = new Employee("Ann", null); 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. .penalizesBy(2); + } + @Test + void whenTwoShiftsOnDifferentDays_thenDoNotPenalize() { + Employee ann = new Employee("Ann", null); constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::atMostOneShiftPerDay) .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), null, ann), new Shift(TUESDAY.atTime(14, 0), TUESDAY.atTime(22, 0), null, ann)) .penalizesBy(0); } @Test - void requiredSkill() { + void whenEmployeeLacksRequiredSkill_thenPenalize() { Employee ann = new Employee("Ann", Set.of("Waiter")); constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::requiredSkill) .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), "Cook", ann)) .penalizesBy(1); + } + + @Test + void whenEmployeeHasRequiredSkill_thenDoNotPenalize() { + Employee ann = new Employee("Ann", Set.of("Waiter")); constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::requiredSkill) .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), "Waiter", ann)) .penalizesBy(0);