Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ScalaCheck CHANGELOG

### Fixed

* Ensure posNum and negNum always return values
[#568](https://github.com/typelevel/scalacheck/issues/568)

## 1.14.2 (2019-09-25)

* Binary compatible with 1.14.1 version of ScalaCheck.
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -863,15 +863,15 @@ object Gen extends GenArities with GenVersionSpecific {
* upper bound of the generation size parameter. */
def posNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] = {
import num._
sized(n => c.choose(zero, max(fromInt(n), one)).suchThat(_ != zero))
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)))
}
}

/** Generates negative numbers of uniform distribution, with an
* lower bound of the negated generation size parameter. */
def negNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] = {
import num._
sized(n => c.choose(min(-fromInt(n), -one), zero).suchThat(_ != zero))
}
def negNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] = posNum.map(num.negate _)

/** Generates numbers within the given inclusive range, with
* extra weight on zero, +/- unity, both extremities, and any special
Expand Down