Skip to content

Commit ddec639

Browse files
committed
Add Double infinities to Gen.choose
1 parent 1a790ea commit ddec639

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

jvm/src/test/scala/org/scalacheck/GenSpecification.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ object GenSpecification extends Properties("Gen") {
123123

124124
import Double.{NegativeInfinity, PositiveInfinity}
125125
property("choose-infinite-double") = {
126+
forAll(Gen.choose(NegativeInfinity, PositiveInfinity)) { x =>
127+
NegativeInfinity <= x && x <= PositiveInfinity && !x.isNaN
128+
}
129+
}
130+
131+
property("choose-infinite-double-fix-zero-defect-379") = {
126132
Prop.forAllNoShrink(listOfN(3, choose(NegativeInfinity, PositiveInfinity))) { xs =>
127133
xs.exists(_ != 0d)
128134
}

src/main/scala/org/scalacheck/Gen.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ object Gen extends GenArities{
377377
val d = h - l
378378
if (d < 0) {
379379
throw new IllegalBoundsError(l, h)
380-
} else if (l == Double.NegativeInfinity) {
381-
chDbl(Double.MinValue, h)(p, seed)
382-
} else if (h == Double.PositiveInfinity) {
383-
chDbl(l, Double.MaxValue)(p, seed)
384380
} else if (d > Double.MaxValue) {
385381
val (x, seed2) = seed.long
386382
if (x < 0) chDbl(l, 0d)(p, seed2) else chDbl(0d, h)(p, seed2)
@@ -414,6 +410,12 @@ object Gen extends GenArities{
414410
new Choose[Double] {
415411
def choose(low: Double, high: Double) =
416412
if (low > high) throw new IllegalBoundsError(low, high)
413+
else if (low == Double.NegativeInfinity)
414+
frequency(1 -> Double.NegativeInfinity,
415+
9 -> choose(Double.MinValue, high))
416+
else if (high == Double.PositiveInfinity)
417+
frequency(1 -> Double.PositiveInfinity,
418+
9 -> choose(low, Double.MaxValue))
417419
else gen(chDbl(low,high))
418420
}
419421

0 commit comments

Comments
 (0)