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
15 changes: 14 additions & 1 deletion jvm/src/test/scala/org/scalacheck/GenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,20 @@ object GenSpecification extends Properties("Gen") {

import Double.{MinValue, MaxValue}
property("choose-large-double") = forAll(choose(MinValue, MaxValue)) { x =>
MinValue <= x && x <= MaxValue
MinValue <= x && x <= MaxValue && !x.isNaN
}

import Double.{NegativeInfinity, PositiveInfinity}
property("choose-infinite-double") = {
forAll(Gen.choose(NegativeInfinity, PositiveInfinity)) { x =>
NegativeInfinity <= x && x <= PositiveInfinity && !x.isNaN
}
}

property("choose-infinite-double-fix-zero-defect-379") = {
Prop.forAllNoShrink(listOfN(3, choose(NegativeInfinity, PositiveInfinity))) { xs =>
xs.exists(_ != 0d)
}
}

property("choose-xmap") = {
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ object Gen extends GenArities{
new Choose[Double] {
def choose(low: Double, high: Double) =
if (low > high) throw new IllegalBoundsError(low, high)
else if (low == Double.NegativeInfinity)
frequency(1 -> const(Double.NegativeInfinity),
9 -> choose(Double.MinValue, high))
else if (high == Double.PositiveInfinity)
frequency(1 -> const(Double.PositiveInfinity),
9 -> choose(low, Double.MaxValue))
else gen(chDbl(low,high))
}

Expand Down