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

Fix Gen.pick when used with Gen[_] arguments. #695

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

non
Copy link
Contributor

@non non commented Nov 2, 2020

Previously, when called with generators Gen.pick could return collections of
any length, when the API promises that they are length n.

// should only generate Seq(0,1), Seq(0,2), or Seq(1,2).
val g = Gen.pick(2, Gen.const(0), Gen.const(1), Gen.const(2))

We didn't have a test for this variant of Gen, which explains why we didn't
detect this breakage.

Previously, when called with generators Gen.pick could return collections of
any length, when the API promises that they are length `n`.

    // should only generate Seq(0,1), Seq(0,2), or Seq(1,2).
    val g = Gen.pick(2, Gen.const(0), Gen.const(1), Gen.const(2))

We didn't have a test for this variant of Gen, which explains why we didn't
detect this breakage.
@non
Copy link
Contributor Author

non commented Nov 2, 2020

(I'm not sure how widely this variant of pick is used but I think it's worth considering releasing 1.15.1 fairly quickly.)

val gs = rest.map(Gen.const)
Try(pick(n, Gen.const(x), Gen.const(y), gs: _*)) match {
case Success(g) =>
forAll(g) { m => m.length == n && m.forall(lst.contains) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this assertion need to be m.forall(x :: y :: lst.contains)?

Copy link
Contributor

Choose a reason for hiding this comment

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

That has a syntax error, but hopefully you catch my drift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because val lst = x :: y :: rest.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it is. I read lst as rest.

@non non merged commit 05efa9e into typelevel:master Nov 2, 2020
@non non deleted the topic/fix-gen-pick branch November 2, 2020 22:50
@ashawley ashawley added this to the 1.15.1 milestone Nov 3, 2020
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.

3 participants