-
Notifications
You must be signed in to change notification settings - Fork 23
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
someOf/pick utilities #178
Comments
@dwijnand That would definitely be useful! I already added def pick[A](n: Int, as: Seq[A]): Gen[Seq[A]] = {
if (n >= as.length) {
Gen.constant(as)
} else {
def go(m: Int, bs: Set[Int], cs: Set[Int]): Gen[Set[Int]] =
if (m == 0)
Gen.constant(cs)
else
Gen.element(bs.head, bs.tail.toList).flatMap(a => go(m - 1, bs - a, cs + a))
go(n, as.indices.toSet, Set())
.map(is => as.zipWithIndex.flatMap(a => if (is(a._2)) Seq(a._1) else Seq()))
}
} Just on your version, I would definitely avoid relying on value equality, seems like a source of strange bugs and I think you can/should avoid. Definitely take my version with scepticism, there might be a much better/cleaner way. |
The other consideration if the shrinking, it's one of those functions that the library version could possibly do a better job than what you get, but that requires a little more thought. |
Looking at it again/now, the heavy use of
|
Having noticed it was missing, I implemented it forgetting the (I also noticed there's no support for recursive definitions, IIRC. If I find the workaround I put together I'll open a separate issue on it.) |
I developed these in order to port some ScalaCheck code. I think they would be handy to have:
The text was updated successfully, but these errors were encountered: