-
Notifications
You must be signed in to change notification settings - Fork 408
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
Force posNum and negNum generators to always return values #569
Force posNum and negNum generators to always return values #569
Conversation
Without this, posNum and negNum will return None about 1% of the time, as they throw out zeros.
This looks good. Would you be willing to add one other change? I think unless our def posNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] = {
import num._
num match {
case _: Fractional[_] =>
sized(n => c.choose(zero, max(fromInt(n), one)).suchThat(_ != zero))
case _ =>
sized(n => c.choose(one, max(fromInt(n), one))
}
} The reason this might be better is that if |
Yes, that makes sense. I'm playing with it now and I'll push tonight. |
While I'm staring at this, is there a reason that negNum is not just def negNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] =
posNum[T].map(num.negate(_)) |
Also, just derive negNum from posNum
@zakpatterson Using negation on negative numbers can be dangerous (since This looks good. Thanks! 👍 |
Thanks for the review @non, I learned something. |
I think the build failure was transient, I'm retrying now. |
Fixes (part of) #568.