Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-1929

SingleConstraintAssertion doesn't assert total match weight

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 7.36.0.Final
    • None
    • optaplanner-test
    • None

      To reproduce on NQueens, add a dummy matchWeigher:

      NQueensConstraintProvider.java
      public class NQueensConstraintProvider implements ConstraintProvider {
          Constraint horizontalConflict(ConstraintFactory factory) {
              return factory
                      .fromUniquePair(Queen.class, equal(Queen::getRowIndex))
                      // ------------------------------------------------------------------v
                      .penalize("Horizontal conflict", SimpleScore.ONE, (queen, queen2) -> 2);
          }
      }
      

      Update test:

      NQueensConstraintProviderTest.java
      public class NQueensConstraintProviderTest {
      
          @Test
          public void horizontalConflictWithTwoQueens() {
              Queen queen1 = new Queen(0, row1, column1);
              Queen queen2 = new Queen(1, row1, column2);
              constraintVerifier.verifyThat(constraintProvider::horizontalConflict)
                      .given(queen1, queen2)
                      .penalizesBy(2);
              // ------------------^
          }
      }
      

      The test should pass but it fails:

      java.lang.AssertionError: Broken expectation.
              Constraint: org.optaplanner.examples.nqueens.domain/Horizontal conflict
        Expected penalty: 2 (class java.lang.Integer)
          Actual penalty: 1 (class java.lang.Integer)
      

              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              jlocker Jiří Locker (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: