Skip to content

Constraint testing: score generated by a single contraint #2007

@niekvanderkooy

Description

@niekvanderkooy

Is your feature request related to a problem? Please describe.
I am trying to unit test that a constraint in situation X generates a (better/worse/different) penalty than in situation Y. I would prefer not to hard code expected penalty values, since these may change, just that two situations are different.
However, a SingleConstraintVerification only provides methods to compare with known values: penalizes(long times), penalizedBy(long matchWeightTotal), penalizesByMoreThan(String s, long l), etc.

Describe the solution you'd like
There are two possible solutions I can think of, which would both work for me:

Comparing two solutions through the constraintVerifier
constraintVerifier.verifyThat(someConstraint).givenSolution(Solution_ someSolution).penalizesByMoreThan(Solution_ someOtherSolution)

Being able to obtain a score through the constraint verifier
Although I realise the API might be a little confusing in my example below (getting a score from a ConstraintVerifier ) something like constraintVerifier.verifyThat(someConstraint).givenSolution(Solution_ someSolution).score() would allow me to write the assertion myself:

HardSoftScore score1 = constraintVerifier.verifyThat(someConstraint).givenSolution(Solution_ someSolution).score()
HardSoftScore score2 = constraintVerifier.verifyThat(someConstraint).givenSolution(Solution_ otherSolution).score()

assertTrue(score1.compareTo(score2) > 0)

Describe alternatives you've considered
I am currently working through the SolutionManager with solutionManager.analyse(solution) and comparing those scores. However, this includes all constraints not just the one I'm trying to test, so this feels more fragile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    process/needs triageRequires initial assessment of validity, priority etc.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions