Skip to content
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

Merged
merged 6 commits into from
Mar 11, 2020
Merged

Conversation

koterpillar
Copy link
Contributor

When using Gen.suchThat or generators that maintain invariants by construction, shrinking can break those invariants. Add Shrink.suchThat to ensure no invalid values are shrunk to.

@ashawley ashawley added this to the 1.15.0 milestone Feb 5, 2020
@ashawley
Copy link
Contributor

ashawley commented Mar 2, 2020

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.

@ashawley ashawley merged commit 665b330 into typelevel:master Mar 11, 2020

/** Shrink a list, maintaining even length */
val shrinkEvenList: Shrink[List[Int]] =
implicitly[Shrink[List[Int]]].suchThat(_.length % 2 == 0)
Copy link
Contributor

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.

Copy link
Contributor

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.

@koterpillar koterpillar deleted the shrink-such-that branch March 11, 2020 20:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants