From 17a94ca435de326fb47ec35ea1efa851fef0c5ab Mon Sep 17 00:00:00 2001 From: Vikraman Choudhury Date: Tue, 24 Nov 2015 04:26:21 -0500 Subject: [PATCH] Add tests for IdT --- .../cats/laws/discipline/Arbitrary.scala | 3 +++ .../src/test/scala/cats/tests/IdTTests.scala | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/src/test/scala/cats/tests/IdTTests.scala diff --git a/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala index ee71f8d6aa..a5cabdb8df 100644 --- a/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala +++ b/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala @@ -38,6 +38,9 @@ object arbitrary extends ArbitraryInstances0 { implicit def optionTArbitrary[F[_], A](implicit F: Arbitrary[F[Option[A]]]): Arbitrary[OptionT[F, A]] = Arbitrary(F.arbitrary.map(OptionT.apply)) + implicit def idTArbitrary[F[_], A](implicit F: Arbitrary[F[A]]): Arbitrary[IdT[F, A]] = + Arbitrary(F.arbitrary.map(IdT.apply)) + implicit def evalArbitrary[A: Arbitrary]: Arbitrary[Eval[A]] = Arbitrary(Gen.oneOf( getArbitrary[A].map(Eval.now(_)), diff --git a/tests/src/test/scala/cats/tests/IdTTests.scala b/tests/src/test/scala/cats/tests/IdTTests.scala new file mode 100644 index 0000000000..393bf66f15 --- /dev/null +++ b/tests/src/test/scala/cats/tests/IdTTests.scala @@ -0,0 +1,22 @@ +package cats.tests + +import cats.{Foldable, Functor, Monad, Traverse} +import cats.data.IdT +import cats.laws.discipline.{FoldableTests, FunctorTests, MonadTests, SerializableTests, TraverseTests} +import cats.laws.discipline.arbitrary._ + +class IdTTests extends CatsSuite { + + checkAll("IdT[Functor, Int]", FunctorTests[IdT[List, ?]].functor[Int, Int, Int]) + checkAll("Functor[IdT[List, ?]]", SerializableTests.serializable(Functor[IdT[List, ?]])) + + checkAll("IdT[List, Int]", MonadTests[IdT[List, ?]].monad[Int, Int, Int]) + checkAll("Monad[IdT[List, ?]]", SerializableTests.serializable(Monad[IdT[List, ?]])) + + checkAll("IdT[Option, Int]", FoldableTests[IdT[Option, ?]].foldable[Int, Int]) + checkAll("Foldable[IdT[Option, ?]]", SerializableTests.serializable(Foldable[IdT[Option, ?]])) + + checkAll("IdT[Option, Int]", TraverseTests[IdT[Option, ?]].traverse[Int, Int, Int, Int, Option, Option]) + checkAll("Traverse[IdT[Option, ?]]", SerializableTests.serializable(Traverse[IdT[Option, ?]])) + +}