-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing: ConstraintVerifier must support updating all shadow variables too #1430
Comments
This is not currently possible. |
The current state surely requires some extra work for tests - we've worked around this by extracting the Timefold-independent logic so it can be easily reused. IMO, that's not too bad, but having something like this still would be nice. Without knowing the internals here, would it be possible to have an overload of |
@greyhairredbear That is currently the only option I can see. |
FWIW, there is already an overload of |
@Christopher-Chianelli True, but that is used for a different purpose. That is used to test an entire solution, not individual constraints. |
@Christopher-Chianelli Thanks for pointing that out! Now you've mentioned it, I feel like I've come across this in the past :). So @triceo Out of curiosity: What is the difference in purpose here? Couldn't one test a single constraint using that? Again, without knowing the internals and just throwing an idea out there: Could it make sense to try and create a test instance of a planning solution and fill that with the provided facts when |
Actually both now! |
I have to backtrack, @Christopher-Chianelli is correct - my memory did me wrong. But I wonder... if you have to fill out an entire solution just to have the shadow vars triggered automatically, isn't that just replacing one boilerplate (filling in shadows) with another (creating an entire solution)? |
I guess to create a solution you only need to know your own API of how to create a solution and no Timefold-specific implementation details like setting shadow variables correctly. Also, I guess impossible to forget calling a constructor for an object you need while it's quite possible to forget to update your shadow variables. Mentioning this, it also occurs to me that it'd be possible for a user to forget calling |
When using shadow variables, and writing constraint tests, it's a huge pain to set all shadow variables correctly in the items given to
given()
.Allow keeping all shadow variables null and let the ConstraintVerifier do that for you.
This especially create a lot of DRY code: the VariableListener methods requires a ScoreDirector, so all that code needs to be rewritten without the ScoreDirector calls (think before/after etc), which is a maintenance problem.
Proposal A)
Figure it out alongside shadow streams and how to unit test those
Proposal B)
The text was updated successfully, but these errors were encountered: