Turn into a unit test to avoid main()
This commit is contained in:
parent
5df3c5711a
commit
2e60ba5007
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>timefold-solver</artifactId>
|
||||
<name>timefold-solver</name>
|
||||
|
|
|
@ -24,6 +24,7 @@ class ShiftScheduleConstraintProviderUnitTest {
|
|||
// To avoid that, use forEachUniquePair() in the constraint instead.
|
||||
.penalizesBy(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenTwoShiftsOnDifferentDays_thenDoNotPenalize() {
|
||||
Employee ann = new Employee("Ann", null);
|
||||
|
|
|
@ -5,18 +5,21 @@ import java.time.LocalDate;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ai.timefold.solver.core.api.solver.Solver;
|
||||
import ai.timefold.solver.core.api.solver.SolverFactory;
|
||||
import ai.timefold.solver.core.config.solver.SolverConfig;
|
||||
import ai.timefold.solver.core.config.solver.termination.TerminationConfig;
|
||||
|
||||
public class ShiftScheduleApp {
|
||||
public class ShiftScheduleSolverUnitTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShiftScheduleApp.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShiftScheduleSolverUnitTest.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
@Test
|
||||
public void solve() {
|
||||
SolverFactory<ShiftSchedule> solverFactory = SolverFactory.create(new SolverConfig().withSolutionClass(ShiftSchedule.class)
|
||||
.withEntityClasses(Shift.class)
|
||||
.withConstraintProviderClass(ShiftScheduleConstraintProvider.class)
|
||||
|
@ -30,7 +33,7 @@ public class ShiftScheduleApp {
|
|||
printSolution(solution);
|
||||
}
|
||||
|
||||
private static ShiftSchedule loadProblem() {
|
||||
private ShiftSchedule loadProblem() {
|
||||
LocalDate monday = LocalDate.of(2030, 4, 1);
|
||||
LocalDate tuesday = LocalDate.of(2030, 4, 2);
|
||||
return new ShiftSchedule(
|
||||
|
@ -40,7 +43,7 @@ public class ShiftScheduleApp {
|
|||
new Shift(tuesday.atTime(14, 0), tuesday.atTime(22, 0), "Bartender")));
|
||||
}
|
||||
|
||||
private static void printSolution(ShiftSchedule solution) {
|
||||
private void printSolution(ShiftSchedule solution) {
|
||||
logger.info("Shift assignments");
|
||||
for (Shift shift : solution.getShifts()) {
|
||||
logger.info(" " + shift.getStart()
|
Loading…
Reference in New Issue