3

I'm running in an odd issue with scalacheck 1.13.3: arbitrary instances of A => java.util.Date generate different values depending on the time they are called.

Here's a concrete, reproducible example:

import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import java.util.Date
import org.scalacheck._

class Repr extends FunSuite with GeneratorDrivenPropertyChecks {
  implicit val cogenDate: Cogen[Date] = Cogen(_.getTime)

  test("reproduce") {
    forAll { (s: String, g: String => Date) =>
      val d1 = g(s)
      Thread.sleep(100)
      val d2 = g(s)

      assert(d1 === d2)
    }
  }
}

This fails. Printing the actual values of d1 and d2 shows that the dates are indeed different, with a difference of between 100 and 103 ms.

I would guess that the problem comes from my Cogen instance, but I must admit I don't understand why.

Nicolas Rinaudo
  • 6,068
  • 28
  • 41
  • 1
    What are you asking? You generate two time stamps 100 milliseconds apart, and the results are ... 100 milliseconds apart? You may need to redefine equality so that two values are equal within your epsilon. – Bob Dalgleish Oct 31 '16 at 18:28
  • 1
    @BobDalgleish I might be missing the point entirely, but I thought I was generating a pure function that, for a given `String`, would always generate the same `Date` value. This is what I'm testing - calling `g`, an arbitrary pure `String => Date`, on the same string value at different times generate different values. – Nicolas Rinaudo Oct 31 '16 at 18:34

1 Answers1

5

This turns out to be a regression in scalacheck 1.13.3, as discussed in the project's gitter channel. An issue was opened.

Nicolas Rinaudo
  • 6,068
  • 28
  • 41