-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Shrink.suchThat #484
Add Shrink.suchThat #484
Conversation
c7e19b5
to
becc20d
Compare
This is a nice contribution. I don't have any objection. It helps improve a correspondence in the APIs of generators and shrinks. If we can just fix the strange commits to the README, this looks good to me. |
|
||
/** Shrink a list, maintaining even length */ | ||
val shrinkEvenList: Shrink[List[Int]] = | ||
implicitly[Shrink[List[Int]]].suchThat(_.length % 2 == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make shrinkEvenList
implicit? Even if I make it lazy, I get an infinite loop when I use it in a property test.
In your test, you use the explicit shrink version of forAll
. Unfortunately, that only works for single arity forAll
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review #644 when you get a chance, thanks.
When using
Gen.suchThat
or generators that maintain invariants by construction, shrinking can break those invariants. AddShrink.suchThat
to ensure no invalid values are shrunk to.