-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tighten test code for Contravariant derivatives
- Loading branch information
1 parent
110ac5e
commit f7c4104
Showing
5 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
laws/src/main/scala/cats/laws/ContravariantSemigroupalLaws.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cats | ||
package laws | ||
|
||
import cats.ContravariantSemigroupal | ||
import cats.syntax.contravariantSemigroupal._ | ||
|
||
/** | ||
* Laws that are expected for any `cats.ContravariantSemigroupal`. | ||
*/ | ||
trait ContravariantSemigroupalLaws[F[_]] extends ContravariantLaws[F] with SemigroupalLaws[F] { | ||
implicit override def F: ContravariantSemigroupal[F] | ||
|
||
def delta[A](a: A): (A, A) = (a, a) | ||
|
||
def contravariantSemigroupalContramap2DiagonalAssociates[A](m: F[A], n: F[A], o: F[A]): IsEq[F[A]] = | ||
((m, n).contramapN(delta[A]), o).contramapN(delta[A]) <-> (m, (n, o).contramapN(delta[A])).contramapN(delta[A]) | ||
} | ||
object ContravariantSemigroupalLaws { | ||
def apply[F[_]](implicit ev: ContravariantSemigroupal[F]): ContravariantSemigroupalLaws[F] = | ||
new ContravariantSemigroupalLaws[F] { def F: ContravariantSemigroupal[F] = ev } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
laws/src/main/scala/cats/laws/discipline/ContravariantSemigroupalTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cats | ||
package laws | ||
package discipline | ||
|
||
import cats.ContravariantSemigroupal | ||
import cats.laws.discipline.SemigroupalTests.Isomorphisms | ||
import org.scalacheck.{Arbitrary, Cogen} | ||
import org.scalacheck.Prop._ | ||
|
||
trait ContravariantSemigroupalTests[F[_]] extends ContravariantTests[F] with SemigroupalTests[F] { | ||
def laws: ContravariantSemigroupalLaws[F] | ||
|
||
def contravariantSemigroupal[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit | ||
arbFA: Arbitrary[F[A]], | ||
arbFB: Arbitrary[F[B]], | ||
arbFC: Arbitrary[F[C]], | ||
CogenA: Cogen[A], | ||
CogenB: Cogen[B], | ||
CogenC: Cogen[C], | ||
EqFA: Eq[F[A]], | ||
EqFB: Eq[F[B]], | ||
EqFC: Eq[F[C]], | ||
EqFABC: Eq[F[(A, B, C)]], | ||
iso: Isomorphisms[F] | ||
): RuleSet = { | ||
new RuleSet { | ||
val name = "contravariantSemigroupal" | ||
val parents = Seq(contravariant[A, B, C], semigroupal[A, B, C]) | ||
val bases = Seq.empty | ||
val props = Seq( | ||
"contravariantSemigroupal contramap2 delta associates" -> | ||
forAll(laws.contravariantSemigroupalContramap2DiagonalAssociates[A] _) | ||
) | ||
} | ||
} | ||
} | ||
|
||
object ContravariantSemigroupalTests { | ||
def apply[F[_]: ContravariantSemigroupal]: ContravariantSemigroupalTests[F] = | ||
new ContravariantSemigroupalTests[F] { def laws: ContravariantSemigroupalLaws[F] = ContravariantSemigroupalLaws[F] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters