From 43f2bc3e2e87cd26144826b85942656022efa5d1 Mon Sep 17 00:00:00 2001 From: peterneyens Date: Thu, 6 Jul 2017 21:01:26 +0100 Subject: [PATCH 1/2] Reduce the size of lists for faster tests --- .../scala/cats/tests/CokleisliTests.scala | 31 ++++++------------- .../cats/tests/ReaderWriterStateTTests.scala | 8 ++++- .../test/scala/cats/tests/StateTTests.scala | 4 +++ .../test/scala/cats/tests/WriterTTests.scala | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/tests/src/test/scala/cats/tests/CokleisliTests.scala b/tests/src/test/scala/cats/tests/CokleisliTests.scala index 9d25b2c4ab..ac31a3f975 100644 --- a/tests/src/test/scala/cats/tests/CokleisliTests.scala +++ b/tests/src/test/scala/cats/tests/CokleisliTests.scala @@ -11,6 +11,9 @@ import org.scalacheck.Arbitrary class CokleisliTests extends SlowCatsSuite { + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = + slowCheckConfiguration.copy(sizeRange = slowCheckConfiguration.sizeRange.min(5)) + implicit def cokleisliEq[F[_], A, B](implicit A: Arbitrary[F[A]], FB: Eq[B]): Eq[Cokleisli[F, A, B]] = Eq.by[Cokleisli[F, A, B], F[A] => B](_.run) @@ -34,30 +37,14 @@ class CokleisliTests extends SlowCatsSuite { checkAll("Cokleisli[Option, Int, Int]", ContravariantTests[Cokleisli[Option, ?, Int]].contravariant[Int, Int, Int]) checkAll("Contravariant[Cokleisli[Option, ?, Int]]", SerializableTests.serializable(Contravariant[Cokleisli[Option, ?, Int]])) - { - // Ceremony to help scalac to do the right thing, see also #267. - type CokleisliNEL[A, B] = Cokleisli[NonEmptyList, A, B] - - checkAll("Cokleisli[NonEmptyList, Int, Int]", ArrowTests[CokleisliNEL].arrow[Int, Int, Int, Int, Int, Int]) - checkAll("Arrow[Cokleisli[NonEmptyList, ?, ?]]", SerializableTests.serializable(Arrow[CokleisliNEL])) - } + checkAll("Cokleisli[NonEmptyList, Int, Int]", ArrowTests[Cokleisli[NonEmptyList, ?, ?]].arrow[Int, Int, Int, Int, Int, Int]) + checkAll("Arrow[Cokleisli[NonEmptyList, ?, ?]]", SerializableTests.serializable(Arrow[Cokleisli[NonEmptyList, ?, ?]])) - { - // More ceremony, see above - type CokleisliNELE[A] = Cokleisli[NonEmptyList, A, A] + checkAll("Cokleisli[NonEmptyList, Int, Int]", MonoidKTests[λ[α => Cokleisli[NonEmptyList, α, α]]].monoidK[Int]) + checkAll("MonoidK[λ[α => Cokleisli[NonEmptyList, α, α]]]", SerializableTests.serializable(MonoidK[λ[α => Cokleisli[NonEmptyList, α, α]]])) - { - implicit val cokleisliMonoidK = Cokleisli.catsDataMonoidKForCokleisli[NonEmptyList] - checkAll("Cokleisli[NonEmptyList, Int, Int]", MonoidKTests[CokleisliNELE].monoidK[Int]) - checkAll("MonoidK[λ[α => Cokleisli[NonEmptyList, α, α]]]", SerializableTests.serializable(cokleisliMonoidK)) - } - - { - implicit val cokleisliSemigroupK = Cokleisli.catsDataSemigroupKForCokleisli[NonEmptyList] - checkAll("Cokleisli[NonEmptyList, Int, Int]", SemigroupKTests[CokleisliNELE].semigroupK[Int]) - checkAll("SemigroupK[λ[α => Cokleisli[NonEmptyList, α, α]]]", SerializableTests.serializable(cokleisliSemigroupK)) - } - } + checkAll("Cokleisli[List, Int, Int]", SemigroupKTests[λ[α => Cokleisli[List, α, α]]].semigroupK[Int]) + checkAll("SemigroupK[λ[α => Cokleisli[List, α, α]]]", SerializableTests.serializable(SemigroupK[λ[α => Cokleisli[List, α, α]]])) test("contramapValue with Id consistent with lmap"){ forAll { (c: Cokleisli[Id, Int, Long], f: Char => Int) => diff --git a/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala b/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala index ad366b6a0f..ca9781579b 100644 --- a/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala +++ b/tests/src/test/scala/cats/tests/ReaderWriterStateTTests.scala @@ -23,7 +23,7 @@ class ReaderWriterStateTTests extends CatsSuite { test("Traversing with ReaderWriterState is stack-safe") { val ns = (0 to 100000).toList - val rws = ns.traverse(_ => addAndLog(1)) + val rws = ns.traverse(_ => addLogUnit(1)) rws.runS("context", 0).value should === (100001) } @@ -394,6 +394,12 @@ object ReaderWriterStateTTests { } } + def addLogUnit(i: Int): ReaderWriterState[String, Int, Unit, Int] = { + import cats.kernel.instances.unit._ + + ReaderWriterState { (context, state) => ((), state + i, state + i) } + } + implicit def RWSTEq[F[_], E, S, L, A](implicit S: Arbitrary[S], E: Arbitrary[E], FLSA: Eq[F[(L, S, A)]], F: Monad[F]): Eq[ReaderWriterStateT[F, E, S, L, A]] = Eq.by[ReaderWriterStateT[F, E, S, L, A], (E, S) => F[(L, S, A)]] { state => diff --git a/tests/src/test/scala/cats/tests/StateTTests.scala b/tests/src/test/scala/cats/tests/StateTTests.scala index e697f93460..a91f34dc34 100644 --- a/tests/src/test/scala/cats/tests/StateTTests.scala +++ b/tests/src/test/scala/cats/tests/StateTTests.scala @@ -9,6 +9,10 @@ import cats.laws.discipline.arbitrary._ import org.scalacheck.Arbitrary class StateTTests extends CatsSuite { + + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = + checkConfiguration.copy(sizeRange = 5) + import StateTTests._ test("basic state usage"){ diff --git a/tests/src/test/scala/cats/tests/WriterTTests.scala b/tests/src/test/scala/cats/tests/WriterTTests.scala index 5dbd4042a0..0bf6a403e0 100644 --- a/tests/src/test/scala/cats/tests/WriterTTests.scala +++ b/tests/src/test/scala/cats/tests/WriterTTests.scala @@ -16,7 +16,7 @@ class WriterTTests extends CatsSuite { // Scalacheck to calm down a bit so we don't hit memory and test duration // issues. implicit override val generatorDrivenConfig: PropertyCheckConfiguration = - PropertyCheckConfiguration(minSuccessful = 20, sizeRange = 5) + checkConfiguration.copy(sizeRange = 5) checkAll("WriterT[List, Int, Int]", OrderLaws[WriterT[List, Int, Int]].eqv) checkAll("Eq[WriterT[List, Int, Int]]", SerializableTests.serializable(Eq[WriterT[List, Int, Int]])) From e8354c0fcf749767c58b03202405668686bfd2fe Mon Sep 17 00:00:00 2001 From: peterneyens Date: Thu, 6 Jul 2017 22:16:04 +0100 Subject: [PATCH 2/2] Reduce minimal successful matches CokleisliTests --- tests/src/test/scala/cats/tests/CokleisliTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/src/test/scala/cats/tests/CokleisliTests.scala b/tests/src/test/scala/cats/tests/CokleisliTests.scala index ac31a3f975..214c02999b 100644 --- a/tests/src/test/scala/cats/tests/CokleisliTests.scala +++ b/tests/src/test/scala/cats/tests/CokleisliTests.scala @@ -12,7 +12,9 @@ import org.scalacheck.Arbitrary class CokleisliTests extends SlowCatsSuite { implicit override val generatorDrivenConfig: PropertyCheckConfiguration = - slowCheckConfiguration.copy(sizeRange = slowCheckConfiguration.sizeRange.min(5)) + slowCheckConfiguration.copy( + sizeRange = slowCheckConfiguration.sizeRange.min(5), + minSuccessful = slowCheckConfiguration.minSuccessful.min(20)) implicit def cokleisliEq[F[_], A, B](implicit A: Arbitrary[F[A]], FB: Eq[B]): Eq[Cokleisli[F, A, B]] = Eq.by[Cokleisli[F, A, B], F[A] => B](_.run)