Skip to content

Commit

Permalink
Test associativity of (Co)Kleisli composition
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Dec 9, 2015
1 parent 44b4ff4 commit a21ede9
Showing 1 changed file with 27 additions and 0 deletions.
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)
}
}
}

0 comments on commit a21ede9

Please sign in to comment.