Skip to content

Commit

Permalink
Add tests for new OptionT methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Heiber committed Feb 29, 2020
1 parent 69c0f01 commit 3dfd6bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final case class OptionT[F[_], A](value: F[Option[A]]) {
transform(_.flatMap(f))

/**
* Perform an effect if the value inside the is a `None`, leaving the result untouched. Equivalent to [[orElseF]]
* Perform an effect if the value inside the is a `None`, leaving the value untouched. Equivalent to [[orElseF]]
* with an effect returning `None` as argument.
*/
def flatTapNone[B](f: => F[B])(implicit F: Monad[F]): OptionT[F, A] =
Expand Down
19 changes: 19 additions & 0 deletions tests/src/test/scala/cats/tests/OptionTSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ class OptionTSuite extends CatsSuite {
}
}

test("foldF and cataF consistent") {
forAll { (o: OptionT[List, Int], s: String, f: Int => List[String]) =>
o.foldF(List(s))(f) should ===(o.cataF(List(s), f))
}
}

test("fold and foldF consistent") {
forAll { (o: OptionT[List, Int], s: String, f: Int => String) =>
val f2 = f.andThen(i => List(i))
o.fold(s)(f) should ===(o.foldF(List(s))(f2))
}
}

test("flatTapNone doesn't change value inside") {
forAll { (o: OptionT[Eval, Int], f: Eval[String]) =>
o.flatTapNone(f) should ===(o)
}
}

test("OptionT[Id, A].fold consistent with Option.fold") {
forAll { (o: Option[Int], s: String, f: Int => String) =>
o.fold(s)(f) should ===(OptionT[Id, Int](o).fold(s)(f))
Expand Down

0 comments on commit 3dfd6bb

Please sign in to comment.