-
Notifications
You must be signed in to change notification settings - Fork 407
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
Discrepancy between Gen and Arbitrary for Option #401
Comments
cc @non |
I vote for 90% of the time Really, the |
Looking at the git history, it seems the current implementation for |
Currently #397 is tripping me up and preventing me from submitting a PR for this. |
It has been revealed that there was a use case of ScalaCheck for generating classes with recursive definitions using Here's an example of this use case: case class RecursiveOption(opt: Option[RecursiveOption])
implicit def arbRecursiveOption: Arbitrary[RecursiveOption] = Arbitrary {
Arbitrary.arbitrary[Option[RecursiveOption]]
.map(RecursiveOption(_))
} Weighting implicit def arbRecursiveOption: Arbitrary[RecursiveOption] = Arbitrary {
Gen.oneOf(
Gen.const(RecursiveOption(None)),
Gen.delay(Arbitrary.arbitrary[Option[RecursiveOption]] // !
.map(RecursiveOption(_))))
} There are arguments to be made for both biased weighting and for these recursive definitions, but we can't really satisfy both. I suppose we should just roll back to the old definition of equally weighting |
I don't believe there is a way. Indeed, the reasoning was good. However, this would not be a good change in a bug-fix release. |
I'm inclined to think that the higher Some weighting should be the long-term solution and that libraries that are htting stack overflows should use a depth tracker to avoid generating structures that are too deeply nested. I would imagine that they already have a chance to stack overflow, but it's just very small. Having said that, if this change has been too disruptive for a patch release, I have no strong objection to reverting it until the next minor version. Sorry to cause trouble. |
Yes, that is a good argument. The termination does seem accidental. It could be put back for a minor version release. We could document this change, as well. |
The
Gen
instance forOption
generates aSome
90% of the time (see #286).The
Arbitrary
instance forOption
doesn't delegate through to theGen
instance but instead uses thesize
as a factor for the frequency ofSome
.It seems to me like Scalacheck should settle on one of these two approaches for generating
Option
, have theGen
use it, and have theArbitrary
instance simply delegate to theGen
instance. The idea of using thesize
for the frequency ofSome
is an interesting one, though it's not immediately obvious to me whether one approach is better than the other. Also theArbitrary
instance is currently resizing the innerGen[A]
instance to half ofsize
which stumped me a little and appears to have done the same to @rickynils.I'm happy to contribute the change if someone suggests to me which of these approaches seems like the better option.
The text was updated successfully, but these errors were encountered: