From 9714421540b9db5503895109c65d7edb44fba36a Mon Sep 17 00:00:00 2001 From: Mike Curry Date: Sat, 21 Nov 2015 20:22:16 +0000 Subject: [PATCH] Adds additional tests for Option T * Tests consistency between flatMap and flatMapF * Tests consistency between Show[OptionT] instance and OptionT.show --- .../src/test/scala/cats/tests/OptionTTests.scala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/src/test/scala/cats/tests/OptionTTests.scala b/tests/src/test/scala/cats/tests/OptionTTests.scala index ca7cd405d1..526d4874de 100644 --- a/tests/src/test/scala/cats/tests/OptionTTests.scala +++ b/tests/src/test/scala/cats/tests/OptionTTests.scala @@ -1,6 +1,6 @@ package cats.tests -import cats.{Applicative, Id, Monad} +import cats.{Applicative, Id, Monad, Show} import cats.data.{OptionT, Validated, Xor} import cats.laws.discipline.{ApplicativeTests, FunctorTests, MonadCombineTests, SerializableTests} import cats.laws.discipline.arbitrary._ @@ -81,6 +81,12 @@ class OptionTTests extends CatsSuite { } } + test("flatMap and flatMapF consistent") { + forAll { (optionT: OptionT[List, Int], f: Int => OptionT[List, Int]) => + optionT.flatMap(f) should === (optionT.flatMapF(f(_).value)) + } + } + test("OptionT[Id, A].toRight consistent with Xor.fromOption") { forAll { (o: OptionT[Id, Int], s: String) => o.toRight(s).value should === (Xor.fromOption(o.value, s)) @@ -117,11 +123,17 @@ class OptionTTests extends CatsSuite { } } - test("show"){ + test("show") { val xor: String Xor Option[Int] = Xor.right(Some(1)) OptionT[Xor[String, ?], Int](xor).show should === ("Xor.Right(Some(1))") } + test("implicit Show[OptionT] instance and explicit show method are consistent") { + forAll { optionT: OptionT[List, Int] => + optionT.show should === (implicitly[Show[OptionT[List, Int]]].show(optionT)) + } + } + test("transform consistent with value.map") { forAll { (o: OptionT[List, Int], f: Option[Int] => Option[String]) => o.transform(f) should === (OptionT(o.value.map(f)))