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

Shrink all tuple sizes #744

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jonaskoelker
Copy link
Contributor

@jonaskoelker jonaskoelker commented Dec 30, 2020

This shrinks tuples of all sizes between 2 and 22, both inclusive. This implements issue #738.

Today I learned you do automatic code generation for various bits that are symmetric across many arities. That seems like a natural and good thing to use for tuple shrinking.

I added a few test cases. With the current tuple shrinking eqvTupleShrinks(xs, ys) could just return xs == ys. However, I think tuple shrinking might be better if we interleave rather than append the various single-component streams, and I'm pretty sure the .sorted equivalence holds if we make that change—that is, I'm deliberately testing something weaker than what I know to be true, in order to future-proof.

Would you like me to make the interleaving change? The advantage of doing e.g. a snake draft across all non-empty single-component shrink streams is that when you shrink component k of an n-tuple, in a situation where no shrunk values of the first k-1 components can provoke a test failure, the number of elements you need to look at before trying to shrink component k is k-1 rather than $sum_{i to k-1} number-of-shrinks-of-component-i$. Stated another way: relatively speaking it prioritizes earlier shrinks of later components rather than later shrinks of earlier components.

If you think there are advantages to prioritizing focusing on the first component, I'll be happy to hear about them. (One could also do a hybrid where you foldLeft a pairwise interleaving, such that the complete interleaving gives 2^-k of the attention to the k'th component.)

Base automatically changed from master to main March 26, 2021 18:56
@satorg
Copy link
Contributor

satorg commented Oct 20, 2024

@jonaskoelker , sorry for the long response. This PR slipped unnoticed somehow.
I feel however, it makes sense to have the proposed functionality included into the library.

Would you be open to actualize your PR against the current main please (i.e. resolve the conflicts and so on)?
Thank you in any case!

Comment on lines +28 to +35
"org.scalacheck.Shrink.shrinkTuple2",
"org.scalacheck.Shrink.shrinkTuple3",
"org.scalacheck.Shrink.shrinkTuple4",
"org.scalacheck.Shrink.shrinkTuple5",
"org.scalacheck.Shrink.shrinkTuple6",
"org.scalacheck.Shrink.shrinkTuple7",
"org.scalacheck.Shrink.shrinkTuple8",
"org.scalacheck.Shrink.shrinkTuple9"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes the new generated methods incompatible with the current ones, could you clarify please? At first glance, the generated method should be very similar to those that they are supposed to replace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants