Skip to content

Commit

Permalink
Merge pull request #733 from fthomas/topic/co-kleisli-assoc-laws
Browse files Browse the repository at this point in the history
Test associativity of (Co)Kleisli composition
  • Loading branch information
stew committed Dec 10, 2015
2 parents 7685147 + a21ede9 commit b2af89d
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 b2af89d

Please sign in to comment.