@@ -1454,15 +1454,16 @@ void solveStaleDeclarativeShadows() {
14541454 }
14551455
14561456 @ Test
1457- void solveWhenIgnoringInconsistentSolutionsThrowsIfInitialSolutionInconsistent () {
1457+ void solveWhenIgnoringInconsistentSolutionsUnassignsIfInitialSolutionInconsistent () {
14581458 // Solver config
14591459 var solverConfig = PlannerTestUtils .buildSolverConfig (
14601460 TestdataDependencyNoInconsistentFieldSolution .class , TestdataDependencyNoInconsistentFieldEntity .class ,
14611461 TestdataDependencyNoInconsistentFieldValue .class )
14621462 .withEasyScoreCalculatorClass (null )
14631463 .withConstraintProviderClass (TestdataDependencyNoInconsistentFieldConstraintProvider .class )
14641464 .withPhases (new CustomPhaseConfig ()
1465- .withCustomPhaseCommands (command -> {}));
1465+ .withCustomPhaseCommands (command -> {
1466+ }));
14661467
14671468 var e1 = new TestdataDependencyNoInconsistentFieldEntity ("a" );
14681469 var e2 = new TestdataDependencyNoInconsistentFieldEntity ("b" );
@@ -1476,7 +1477,7 @@ void solveWhenIgnoringInconsistentSolutionsThrowsIfInitialSolutionInconsistent()
14761477 b2 .setDependencies (List .of (b1 ));
14771478
14781479 e1 .setValues (List .of (b2 , b1 ));
1479- e2 .setValues (List .of (a2 , a1 ));
1480+ e2 .setValues (List .of (a1 , a2 ));
14801481
14811482 var entities = List .of (e1 , e2 );
14821483 var values = List .of (a1 , a2 , b1 , b2 );
@@ -1487,19 +1488,21 @@ void solveWhenIgnoringInconsistentSolutionsThrowsIfInitialSolutionInconsistent()
14871488 problem .setValues (values );
14881489
14891490 var solution = PlannerTestUtils .solve (solverConfig , problem , false );
1490- assertThat (solution .getEntities ().getFirst ().getValues ().isEmpty ());
1491- assertThat (solution .getEntities ().getLast ().getValues ().isEmpty ());
1491+ assertThat (solution .getEntities ().getFirst ().getValues ()).isEmpty ();
1492+ assertThat (solution .getEntities ().getLast ().getValues ()).hasSize (2 );
1493+
1494+ var sE2 = solution .getEntities ().getLast ();
14921495
14931496 var sA1 = solution .getValues ().get (0 );
14941497 var sA2 = solution .getValues ().get (1 );
14951498 var sB1 = solution .getValues ().get (2 );
14961499 var sB2 = solution .getValues ().get (3 );
14971500
1498- assertThat (sA1 .getEntity ()).isNull ( );
1501+ assertThat (sA1 .getEntity ()).isEqualTo ( sE2 );
14991502 assertThat (sA1 .getPreviousValue ()).isNull ();
15001503
1501- assertThat (sA2 .getEntity ()).isNull ( );
1502- assertThat (sA2 .getPreviousValue ()).isNull ( );
1504+ assertThat (sA2 .getEntity ()).isEqualTo ( sE2 );
1505+ assertThat (sA2 .getPreviousValue ()).isEqualTo ( sA1 );
15031506
15041507 assertThat (sB1 .getEntity ()).isNull ();
15051508 assertThat (sB1 .getPreviousValue ()).isNull ();
@@ -1508,6 +1511,44 @@ void solveWhenIgnoringInconsistentSolutionsThrowsIfInitialSolutionInconsistent()
15081511 assertThat (sB2 .getPreviousValue ()).isNull ();
15091512 }
15101513
1514+ @ Test
1515+ void solveWhenIgnoringInconsistentSolutionsThrowsIfInconsistentEntityPinned () {
1516+ // Solver config
1517+ var solverConfig = PlannerTestUtils .buildSolverConfig (
1518+ TestdataDependencyNoInconsistentFieldSolution .class , TestdataDependencyNoInconsistentFieldEntity .class ,
1519+ TestdataDependencyNoInconsistentFieldValue .class )
1520+ .withEasyScoreCalculatorClass (null )
1521+ .withConstraintProviderClass (TestdataDependencyNoInconsistentFieldConstraintProvider .class );
1522+
1523+ var e1 = new TestdataDependencyNoInconsistentFieldEntity ("a" );
1524+ var e2 = new TestdataDependencyNoInconsistentFieldEntity ("b" );
1525+
1526+ var a1 = new TestdataDependencyNoInconsistentFieldValue ("a1" );
1527+ var a2 = new TestdataDependencyNoInconsistentFieldValue ("a2" );
1528+ var b1 = new TestdataDependencyNoInconsistentFieldValue ("b1" );
1529+ var b2 = new TestdataDependencyNoInconsistentFieldValue ("b2" );
1530+
1531+ a2 .setDependencies (List .of (a1 ));
1532+ b2 .setDependencies (List .of (b1 ));
1533+
1534+ e1 .setValues (List .of (b2 , b1 ));
1535+ e2 .setValues (List .of (a2 , a1 ));
1536+
1537+ var entities = List .of (e1 , e2 );
1538+ var values = List .of (a1 , a2 , b1 , b2 );
1539+
1540+ e1 .setPinnedToIndex (1 );
1541+
1542+ var problem = new TestdataDependencyNoInconsistentFieldSolution ();
1543+
1544+ problem .setEntities (entities );
1545+ problem .setValues (values );
1546+
1547+ assertThatCode (() -> PlannerTestUtils .solve (solverConfig , problem , false ))
1548+ .isInstanceOf (IllegalStateException .class )
1549+ .hasMessageContainingAll ("Entity" , "b2" , "is pinned but is involved in a dependency loop" );
1550+ }
1551+
15111552 @ Test
15121553 void solveIgnoreInconsistent () {
15131554 // Solver config
0 commit comments