Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,11 @@ object KernelCheck {
if (d == Duration.Inf) 3896691548866406746L
else if (d == Duration.MinusInf) 1844151880988859955L
else if (d == Duration.Undefined) -7917359255778781894L
else
d.length * (d.unit match {
case DAYS => -6307593037248227856L
case HOURS => -3527447467459552709L
case MINUTES => 5955657079535371609L
case SECONDS => 5314272869665647192L
case MILLISECONDS => -2025740217814855607L
case MICROSECONDS => -2965853209268633779L
case NANOSECONDS => 6128745701389500153L
})
else d.toNanos
}

implicit val cogenFiniteDuration: Cogen[FiniteDuration] =
Cogen[Long].contramap { d =>
d.length * (d.unit match {
case DAYS => -6307593037248227856L
case HOURS => -3527447467459552709L
case MINUTES => 5955657079535371609L
case SECONDS => 5314272869665647192L
case MILLISECONDS => -2025740217814855607L
case MICROSECONDS => -2965853209268633779L
case NANOSECONDS => 6128745701389500153L
})
}
Cogen[Long].contramap(_.toNanos)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsrh this is the same as the one defined in ScalaCheck currently, so maybe we should just delete it?

@larsrh larsrh Feb 7, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. I just checked and ScalaCheck has all combinations of {Arbitrary, Cogen} and {Duration, FiniteDuration}. Should I delete them too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

class TestsConfig extends ScalaCheckSuite {
Expand Down Expand Up @@ -522,3 +503,24 @@ class Tests extends TestsConfig with DisciplineSuite {
Cogen[A].contramap(_.a)
}
}

final class LongRunningTests extends ScalaCheckSuite with DisciplineSuite {
// This increases the number of successes to trigger the problem
// described here: https://github.com/typelevel/cats/issues/3734
// With this number of positive cases the problem is systematic
// or at least it happens very often.
final val PropMaxSize = if (Platform.isJs) 10 else 100
final val PropMinSuccessful = if (Platform.isJs) 10 else 400 * 1000
final val PropWorkers = if (Platform.isJvm) 2 else 1

implicit override def scalaCheckTestParameters: Parameters =
Parameters.default
.withMinSuccessfulTests(PropMinSuccessful)
.withMaxSize(PropMaxSize)
.withWorkers(PropWorkers)

import KernelCheck._

checkAll("Deeper test of Eq[Duration]", EqTests[Duration].eqv)
checkAll("Deeper test of Eq[FiniteDuration]", EqTests[FiniteDuration].eqv)
}