Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laws failure for Order[FiniteDuration] #3762

Closed
TimWSpence opened this issue Feb 1, 2021 · 2 comments
Closed

Laws failure for Order[FiniteDuration] #3762

TimWSpence opened this issue Feb 1, 2021 · 2 comments

Comments

@TimWSpence
Copy link
Member

TimWSpence commented Feb 1, 2021

I got hit by this on #3747 (as certain as I can be that it's unrelated)

failing seed for order.antisymmetry eq is Ue31ofRHQVK9wcbnhBqISNebQdvZZhUREH6EgJBgjHB=
==> X cats.kernel.laws.Tests.Order[Duration]: order.antisymmetry eq 0.041s munit.FailException: /home/runner/work/cats/cats/kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala:200
199: checkAll("Order[BigInt]", OrderTests[BigInt].order)
200: checkAll("Order[Duration]", OrderTests[Duration].order)
201: checkAll("Order[FiniteDuration]", OrderTests[FiniteDuration].order)

Failing seed: hzeHOUHfb3_7x_2BxKaJnuLQt8g8rW9F_NIqhIjY5eA=
You can reproduce this failure by adding the following override to your suite:

override val scalaCheckInitialSeed = "hzeHOUHfb3_7x_2BxKaJnuLQt8g8rW9F_NIqhIjY5eA="

Falsified after 93 passed tests.

Labels of failing property:
Expected: true
Received: false
ARG_0: 1224 hours
ARG_1: 51 days
ARG_2: org.scalacheck.GenArities$$Lambda$495/0x0000000800dcd108@aaedf00
at munit.Assertions.fail(Assertions.scala:261)
at munit.Assertions.fail$(Assertions.scala:255)
at munit.FunSuite.fail(FunSuite.scala:11)
at munit.ScalaCheckSuite.$anonfun$propToTry$4(ScalaCheckSuite.scala:104)
at scala.util.Try$.apply(Try.scala:213)
at munit.ScalaCheckSuite.propToTry(ScalaCheckSuite.scala:104)
at munit.ScalaCheckSuite.$anonfun$scalaCheckPropTransform$3(ScalaCheckSuite.scala:46)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
at munit.Suite$$anon$1.execute(Suite.scala:26)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:72)
at scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete(Promise.scala:372)
at scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete$(Promise.scala:371)
at scala.concurrent.impl.Promise$KeptPromise$Successful.onComplete(Promise.scala:379)
at scala.concurrent.impl.Promise.transform(Promise.scala:33)
at scala.concurrent.impl.Promise.transform$(Promise.scala:31)
at scala.concurrent.impl.Promise$KeptPromise$Successful.transform(Promise.scala:379)
at munit.internal.FutureCompat$ExtensionFuture.transformCompat(FutureCompat.scala:16)
at munit.ScalaCheckSuite.$anonfun$scalaCheckPropTransform$2(ScalaCheckSuite.scala:48)
at munit.GenericTest.$anonfun$withBodyMap$1(GenericTest.scala:33)
at munit.MUnitRunner.$anonfun$runTestBody$1(MUnitRunner.scala:296)

@TimWSpence
Copy link
Member Author

TimWSpence commented Feb 4, 2021

Actually I see this has been discussed previously in #3353.

I'm a bit confused by the law actually - it seems to me that it need not hold in general

type Cogen[A] = (A, Seed) => Seed //essentially

def antiSymmetryEq(x: A, y: A, f: A => A): IsEq[Boolean] =
   (!E.eqv(x, y) || E.eqv(f(x), f(y))) <-> true

This law relies upon the function f being well-defined (x == y => f x == f y), where equality is determined by Eq. But of course in Scala we can easily write ill-defined functions eg when pattern matching. And in fact the functions generated by the Cogen instance are exactly that - they will take too equivalent FiniteDurations (eg 51 days and 1224 hours) and generate different values. The alternative Cogen implementation in Scalacheck looks like the only correct definition to me

@larsrh
Copy link
Contributor

larsrh commented Feb 6, 2021

Seems to be a duplicate of #3734.

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

No branches or pull requests

2 participants