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

Test associativity of (Co)Kleisli composition #733

Merged
merged 1 commit into from
Dec 10, 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
27 changes: 27 additions & 0 deletions tests/src/test/scala/cats/tests/OptionTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats
package tests

import cats.laws.{CoflatMapLaws, FlatMapLaws}
import cats.laws.discipline.{TraverseTests, CoflatMapTests, MonadCombineTests, SerializableTests}

class OptionTests extends CatsSuite {
Expand All @@ -21,4 +22,30 @@ class OptionTests extends CatsSuite {
fs.show should === (fs.toString)
}
}

// The following two tests check the kleisliAssociativity and
// cokleisliAssociativity laws which are a different formulation of
// the flatMapAssociativity and coflatMapAssociativity laws. Since
// these laws are more or less duplicates of existing laws, we don't
// check them for all types that have FlatMap or CoflatMap instances.

test("Kleisli associativity") {
forAll { (l: Long,
f: Long => Option[Int],
g: Int => Option[Char],
h: Char => Option[String]) =>
val isEq = FlatMapLaws[Option].kleisliAssociativity(f, g, h, l)
isEq.lhs should === (isEq.rhs)
}
}

test("Cokleisli associativity") {
forAll { (l: Option[Long],
f: Option[Long] => Int,
g: Option[Int] => Char,
h: Option[Char] => String) =>
val isEq = CoflatMapLaws[Option].cokleisliAssociativity(f, g, h, l)
isEq.lhs should === (isEq.rhs)
}
}
}