Reputation: 33
I am currently working with dynamic weights configured in a ConstraintConfiguration class. But the class doesn't seem to be used while executing my tests that I wrote. It is however used while actually executing the solver.
For example: one of the weights in the configuration class is 16. While testing for a score of 1, it will not be multiplied with the weight and the result will be 1. But while actually solving, it will use it and it will be 16 as expected.
I am guessing that I'm missing something in my testing class. Do you have to tell the ConstraintVerifier or the testing methods in the testing class that there is a ConstraintConfiguration? Or am I missing something else?
Thanks in advance.
My current constraintverifier:
ConstraintVerifier<ExamScheduleConstraintProvider, ExamSchedule> constraintVerifier = ConstraintVerifier.build(
new ExamScheduleConstraintProvider(), ExamSchedule.class, Exam.class);
Example of test code that won't pass:
constraintVerifier.verifyThat(ExamScheduleConstraintProvider::TestConstraint)
.given(firstExam, secondExam)
.penalizesBy(16);
Upvotes: 3
Views: 251
Reputation: 5702
In addition to Radovan's response, I will provide some rationale for why ConstraintVerifier
works the way it does.
For individual constraints, it does not take ConstraintConfiguration
into account. That is because ConstraintConfiguration
is solution-specific, and we want to be able to test consraints individually and independently. In this case, we only test match weights; match weights exist regardless of the solution, and regardless of constraint configuration. This would be your typical unit test. (If you prefer another way of thinking about this, consider the fact that constraint configuration is optional and most do not, in fact, use it.)
For integration testing, we support testing an entire solution. And when you test all the constraints as a whole, that is where we take your ConstraintConfiguration
into account.
Upvotes: 2
Reputation: 1029
The ConstraintVerifier
offers two verification methods:
verifyThat(constraintFunction)
accepts a method reference to an individual constraint and verifies that the constraint, given certain entities and facts or an entire solution, penalizes or rewards by the expected match weight. Important to note, this verifier ignores constraint weight completely.
verifyThat()
does not accept any argument and checks the score impact (including constraint weight coming from ConstraintConfiguration
) of all the constraints defined in the ConstraintProvider
implementation for the provided entities and facts or an entire solution.
Upvotes: 2