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.
This turns out to be a regression in scalacheck 1.13.3, as discussed in the project's gitter channel. An issue was opened.