Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds additional tests for Option T #692

Merged
merged 1 commit into from
Nov 24, 2015
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
16 changes: 14 additions & 2 deletions tests/src/test/scala/cats/tests/OptionTTests.scala
Original file line number Diff line number Diff line change
@@ -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._
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)))
Expand Down