Skip to content

Conversation

@ashawley
Copy link
Contributor

@ashawley ashawley commented Jan 14, 2018

I was able to verify #379 with the following test that checks that there is at least one non-zero value in a sample of three:

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

Here it is failing currently:

[info] ! Gen.choose-infinite-double: Falsified after 0 passed tests.
[info] > ARG_0: List("0.0", "0.0", "0.0")

The test assumes that flipping a Double.MaxValue-sided coin and getting a zero three times in a row is impossible. Someone may need to check my math on that.

scala> 2 * math.pow(Long.MaxValue.toDouble, -3d)
res0: Double = 2.5489470578119236E-57

The fix here just substitutes Double.MinValue for Double.NegativeInfinity and Double.MaxValue for Double.PositiveInfinity in the internal function Gen.Choose.chDbl, and also adds the special constants Double.NegativeInfinity and Double.PositiveInfinity at a frequency of 10% (for both respectively).

Add an additional property check for original requester who asked that
Gen.choose support for Double.{NegativeInfinity, PositiveInfinity}.
@rickynils rickynils merged commit 295bba2 into typelevel:master Apr 21, 2018
@ashawley ashawley deleted the double-infinity branch April 22, 2018 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants