Timefold: How to unit test a variable listener?

41 views Asked by At

I've been experimenting with the food packaging example, and I've added custom logic to my start time variable listener to skip weekends. I want to add a unit test to test that the variable listener is correctly assigning the start time to jobs by skipping weekends.

However, I'm unsure of exactly how to do so, and it doesn't seem like there are any quickstart examples of unit testing the variable listeners themselves. I've tried creating my own unit test, but I got lost when trying to trigger the variable listener, since I don't know how to correctly instantiate the VariableListener and ScoreDirector, if that even makes sense. How do I unit test a variable listener, or is unit testing unnecessary for variable listeners?

1

There are 1 answers

0
Geoffrey De Smet On

See what Lukas commented.

That being said, SolutionManager.update() can help you unit test a from scratch calculation.

For incremental calculations, a poor man's solution is to run the solver for CH + 100 steps of LS with FULL_ASSERT. That will verify that the incremental calculation equals the from scratch calculation. We do this in our "turtle tests", but we don't show how to do it yet on our quickstarts.