Skip to content

Commit 4559da1

Browse files
committed
Fix Gen.choose for Double infinity
1 parent 63d204c commit 4559da1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ object GenSpecification extends Properties("Gen") {
121121
MinValue <= x && x <= MaxValue
122122
}
123123

124+
import Double.{NegativeInfinity, PositiveInfinity}
125+
property("choose-infinite-double") = {
126+
Prop.forAllNoShrink(listOfN(3, choose(NegativeInfinity, PositiveInfinity))) { xs =>
127+
xs.exists(_ != 0d)
128+
}
129+
}
130+
124131
property("choose-xmap") = {
125132
implicit val chooseDate: Choose[Date] =
126133
Choose.xmap[Long, Date](new Date(_), _.getTime)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ 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)
380384
} else if (d > Double.MaxValue) {
381385
val (x, seed2) = seed.long
382386
if (x < 0) chDbl(l, 0d)(p, seed2) else chDbl(0d, h)(p, seed2)

0 commit comments

Comments
 (0)