From 5b12748875d6ba225e6f6371b159b82a09c7814a Mon Sep 17 00:00:00 2001 From: Tim Nielens Date: Sun, 28 Feb 2021 22:57:46 +0100 Subject: [PATCH] remove unnecessary Duration scalacheck instances --- .../scala/cats/kernel/laws/LawTests.scala | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala b/kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala index e7d2979eb0..fc469d53d3 100644 --- a/kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala +++ b/kernel-laws/shared/src/test/scala/cats/kernel/laws/LawTests.scala @@ -30,23 +30,6 @@ object KernelCheck { implicit val arbitraryUUID: Arbitrary[UUID] = Arbitrary(Gen.uuid) - implicit val arbitraryDuration: Arbitrary[Duration] = { - // max range is +/- 292 years, but we give ourselves some extra headroom - // to ensure that we can add these things up. they crash on overflow. - val n = (292L * 365) / 500 - Arbitrary( - Gen.oneOf( - Gen.choose(-n, n).map(Duration(_, DAYS)), - Gen.choose(-n * 24L, n * 24L).map(Duration(_, HOURS)), - Gen.choose(-n * 1440L, n * 1440L).map(Duration(_, MINUTES)), - Gen.choose(-n * 86400L, n * 86400L).map(Duration(_, SECONDS)), - Gen.choose(-n * 86400000L, n * 86400000L).map(Duration(_, MILLISECONDS)), - Gen.choose(-n * 86400000000L, n * 86400000000L).map(Duration(_, MICROSECONDS)), - Gen.choose(-n * 86400000000000L, n * 86400000000000L).map(Duration(_, NANOSECONDS)) - ) - ) - } - implicit val arbitraryFiniteDuration: Arbitrary[FiniteDuration] = { // max range is +/- 292 years, but we give ourselves some extra headroom // to ensure that we can add these things up. they crash on overflow. @@ -64,6 +47,10 @@ object KernelCheck { ) } + // `Duration.Undefined`, `Duration.Inf` and `Duration.MinusInf` break the tests + implicit val arbitraryDuration: Arbitrary[Duration] = + Arbitrary(arbitraryFiniteDuration.arbitrary.map(fd => fd: Duration)) + // Copied from cats-laws. implicit def arbitrarySortedMap[K: Arbitrary: Order, V: Arbitrary]: Arbitrary[SortedMap[K, V]] = Arbitrary(arbitrary[Map[K, V]].map(s => SortedMap.empty[K, V](implicitly[Order[K]].toOrdering) ++ s)) @@ -101,17 +88,6 @@ object KernelCheck { implicit val cogenUUID: Cogen[UUID] = Cogen[(Long, Long)].contramap(u => (u.getMostSignificantBits, u.getLeastSignificantBits)) - - implicit val cogenDuration: Cogen[Duration] = - Cogen[Long].contramap { d => - if (d == Duration.Inf) 3896691548866406746L - else if (d == Duration.MinusInf) 1844151880988859955L - else if (d == Duration.Undefined) -7917359255778781894L - else d.toNanos - } - - implicit val cogenFiniteDuration: Cogen[FiniteDuration] = - Cogen[Long].contramap(_.toNanos) } class TestsConfig extends ScalaCheckSuite {