diff --git a/jvm/src/test/scala/org/scalacheck/GenSpecification.scala b/jvm/src/test/scala/org/scalacheck/GenSpecification.scala index f9489804b..9ab5a913a 100644 --- a/jvm/src/test/scala/org/scalacheck/GenSpecification.scala +++ b/jvm/src/test/scala/org/scalacheck/GenSpecification.scala @@ -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") = { diff --git a/src/main/scala/org/scalacheck/Gen.scala b/src/main/scala/org/scalacheck/Gen.scala index 87a6ac55a..0f3e0202d 100644 --- a/src/main/scala/org/scalacheck/Gen.scala +++ b/src/main/scala/org/scalacheck/Gen.scala @@ -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)) }