Skip to content

Commit

Permalink
Additional Profunctor tests covering lmap and rmap
Browse files Browse the repository at this point in the history
This adds additional tests for Profunctor which utilise the laws
infrastructure to exercise the lmap and rmap operations.
  • Loading branch information
mikejcurry committed Nov 17, 2015
1 parent b2b967b commit 1a6019e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions laws/src/main/scala/cats/laws/ProfunctorLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ trait ProfunctorLaws[F[_, _]] {
f2: A2 => A1, f1: A1 => A0,
g1: B0 => B1, g2: B1 => B2): IsEq[F[A2, B2]] =
fab.dimap(f1)(g1).dimap(f2)(g2) <-> fab.dimap(f1 compose f2)(g2 compose g1)

def profunctorLmapIdentity[A, B](fab: F[A, B]): IsEq[F[A, B]] =
fab.lmap(identity[A]) <-> fab

def profunctorRmapIdentity[A, B](fab: F[A, B]): IsEq[F[A, B]] =
fab.rmap(identity[B]) <-> fab

def profunctorLmapComposition[A2, A1, A0, B](fab: F[A0, B],
f: A2 => A1, g: A1 => A0): IsEq[F[A2, B]] =
fab.lmap(g).lmap(f) <-> fab.lmap(g compose f)

def profunctorRmapComposition[A, B2, B1, B0](fab: F[A, B0],
f: B0 => B1, g: B1 => B2): IsEq[F[A, B2]] =
fab.rmap(f).rmap(g) <-> fab.rmap(g compose f)

}

object ProfunctorLaws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ trait ProfunctorTests[F[_, _]] extends Laws {
ArbFAB: Arbitrary[F[A, B]],
ArbFCD: Arbitrary[F[C, D]],
EqFAB: Eq[F[A, B]],
EqFAD: Eq[F[A, D]],
EqFAG: Eq[F[A, G]]
): RuleSet =
new DefaultRuleSet(
name = "profunctor",
parent = None,
"profunctor identity" -> forAll(laws.profunctorIdentity[A, B] _),
"profunctor composition" -> forAll(laws.profunctorComposition[A, B, C, D, E, G] _))
"profunctor composition" -> forAll(laws.profunctorComposition[A, B, C, D, E, G] _),
"profunctor lmap identity" -> forAll(laws.profunctorLmapIdentity[A, B] _),
"profunctor rmap identity" -> forAll(laws.profunctorRmapIdentity[A, B] _),
"profunctor lmap composition" -> forAll(laws.profunctorLmapComposition[A, B, C, D] _),
"profunctor rmap composition" -> forAll(laws.profunctorRmapComposition[A, D, C, B] _))
}

object ProfunctorTests {
Expand Down
1 change: 1 addition & 0 deletions laws/src/main/scala/cats/laws/discipline/StrongTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait StrongTests[F[_, _]] extends ProfunctorTests[F] {
ArbFBC: Arbitrary[F[B, C]],
ArbFCD: Arbitrary[F[C, D]],
EqFAB: Eq[F[A, B]],
EqFAD: Eq[F[A, D]],
EqFAG: Eq[F[A, G]],
EqFAEDE: Eq[F[(A, E), (D, E)]],
EqFEAED: Eq[F[(E, A), (E, D)]]
Expand Down

0 comments on commit 1a6019e

Please sign in to comment.