Skip to content

Commit

Permalink
Rename laws -> tests, remove redundancies
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed May 29, 2021
1 parent b81e1fb commit 844670d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 355 deletions.

This file was deleted.

This file was deleted.

100 changes: 0 additions & 100 deletions algebra-laws/shared/src/main/scala/cats/algebra/laws/GroupLaws.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import org.scalacheck.Prop._

import cats.algebra.instances.boolean._

object LatticePartialOrderLaws {
def apply[A: Eq: Arbitrary] = new LatticePartialOrderLaws[A] {
object LatticePartialOrderTests {
def apply[A: Eq: Arbitrary] = new LatticePartialOrderTests[A] {
def Equ = Eq[A]
def Arb = implicitly[Arbitrary[A]]
}
}

trait LatticePartialOrderLaws[A] extends Laws {
trait LatticePartialOrderTests[A] extends Laws {

implicit def Equ: Eq[A]
implicit def Arb: Arbitrary[A]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ package cats.algebra.laws

import cats.algebra._
import cats.algebra.lattice._

import cats.kernel.laws.discipline.{BoundedSemilatticeTests, SemilatticeTests}
import org.scalacheck.{Arbitrary, Prop}
import org.scalacheck.Prop._
import org.typelevel.discipline.Laws

object LatticeLaws {
def apply[A: Eq: Arbitrary] = new LatticeLaws[A] {
object LatticeTests {
def apply[A: Eq: Arbitrary] = new LatticeTests[A] {
def Equ = Eq[A]
def Arb = implicitly[Arbitrary[A]]
}
}

trait LatticeLaws[A] extends GroupLaws[A] {
trait LatticeTests[A] extends Laws {

implicit def Equ: Eq[A]
implicit def Arb: Arbitrary[A]

def joinSemilattice(implicit A: JoinSemilattice[A]) = new LatticeProperties(
name = "joinSemilattice",
parents = Nil,
join = Some(semilattice(A.joinSemilattice)),
join = Some(SemilatticeTests[A](A.joinSemilattice).semilattice),
meet = None,
Rules.serializable(A)
)
Expand All @@ -30,15 +31,15 @@ trait LatticeLaws[A] extends GroupLaws[A] {
name = "meetSemilattice",
parents = Nil,
join = None,
meet = Some(semilattice(A.meetSemilattice)),
meet = Some(SemilatticeTests[A](A.meetSemilattice).semilattice),
Rules.serializable(A)
)

def lattice(implicit A: Lattice[A]) = new LatticeProperties(
name = "lattice",
parents = Seq(joinSemilattice, meetSemilattice),
join = Some(semilattice(A.joinSemilattice)),
meet = Some(semilattice(A.meetSemilattice)),
join = Some(SemilatticeTests[A](A.joinSemilattice).semilattice),
meet = Some(SemilatticeTests[A](A.meetSemilattice).semilattice),
"absorption" -> forAll { (x: A, y: A) =>
(A.join(x, A.meet(x, y)) ?== x) && (A.meet(x, A.join(x, y)) ?== x)
}
Expand All @@ -47,8 +48,8 @@ trait LatticeLaws[A] extends GroupLaws[A] {
def distributiveLattice(implicit A: DistributiveLattice[A]) = new LatticeProperties(
name = "distributiveLattice",
parents = Seq(lattice),
join = Some(semilattice(A.joinSemilattice)),
meet = Some(semilattice(A.meetSemilattice)),
join = Some(SemilatticeTests[A](A.joinSemilattice).semilattice),
meet = Some(SemilatticeTests[A](A.meetSemilattice).semilattice),
"distributive" -> forAll { (x: A, y: A, z: A) =>
(A.join(x, A.meet(y, z)) ?== A.meet(A.join(x, y), A.join(x, z))) &&
(A.meet(x, A.join(y, z)) ?== A.join(A.meet(x, y), A.meet(x, z)))
Expand All @@ -58,50 +59,50 @@ trait LatticeLaws[A] extends GroupLaws[A] {
def boundedJoinSemilattice(implicit A: BoundedJoinSemilattice[A]) = new LatticeProperties(
name = "boundedJoinSemilattice",
parents = Seq(joinSemilattice),
join = Some(boundedSemilattice(A.joinSemilattice)),
join = Some(BoundedSemilatticeTests(A.joinSemilattice).boundedSemilattice),
meet = None
)

def boundedMeetSemilattice(implicit A: BoundedMeetSemilattice[A]) = new LatticeProperties(
name = "boundedMeetSemilattice",
parents = Seq(meetSemilattice),
join = None,
meet = Some(boundedSemilattice(A.meetSemilattice))
meet = Some(BoundedSemilatticeTests(A.meetSemilattice).boundedSemilattice)
)

def boundedJoinLattice(implicit A: Lattice[A] with BoundedJoinSemilattice[A]) = new LatticeProperties(
name = "boundedJoinLattice",
parents = Seq(boundedJoinSemilattice, lattice),
join = Some(boundedSemilattice(A.joinSemilattice)),
meet = Some(semilattice(A.meetSemilattice))
join = Some(BoundedSemilatticeTests(A.joinSemilattice).boundedSemilattice),
meet = Some(SemilatticeTests(A.meetSemilattice).semilattice)
)

def boundedMeetLattice(implicit A: Lattice[A] with BoundedMeetSemilattice[A]) = new LatticeProperties(
name = "boundedMeetLattice",
parents = Seq(boundedMeetSemilattice, lattice),
join = Some(semilattice(A.joinSemilattice)),
meet = Some(boundedSemilattice(A.meetSemilattice))
join = Some(SemilatticeTests(A.joinSemilattice).semilattice),
meet = Some(BoundedSemilatticeTests(A.meetSemilattice).boundedSemilattice)
)

def boundedLattice(implicit A: BoundedLattice[A]) = new LatticeProperties(
name = "boundedLattice",
parents = Seq(boundedJoinSemilattice, boundedMeetSemilattice, lattice),
join = Some(boundedSemilattice(A.joinSemilattice)),
meet = Some(boundedSemilattice(A.meetSemilattice))
join = Some(BoundedSemilatticeTests(A.joinSemilattice).boundedSemilattice),
meet = Some(BoundedSemilatticeTests(A.meetSemilattice).boundedSemilattice)
)

def boundedDistributiveLattice(implicit A: BoundedDistributiveLattice[A]) = new LatticeProperties(
name = "boundedLattice",
parents = Seq(boundedLattice, distributiveLattice),
join = Some(boundedSemilattice(A.joinSemilattice)),
meet = Some(boundedSemilattice(A.meetSemilattice))
join = Some(BoundedSemilatticeTests(A.joinSemilattice).boundedSemilattice),
meet = Some(BoundedSemilatticeTests(A.meetSemilattice).boundedSemilattice)
)

class LatticeProperties(
val name: String,
val parents: Seq[LatticeProperties],
val join: Option[GroupProperties],
val meet: Option[GroupProperties],
val join: Option[Laws#RuleSet],
val meet: Option[Laws#RuleSet],
val props: (String, Prop)*
) extends RuleSet {
private val _m = meet.map { "meet" -> _ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package cats.algebra.laws

import cats.algebra._
import cats.algebra.lattice.{Bool, DeMorgan, GenBool, Heyting, Logic}
import cats.kernel.laws.discipline.{BoundedSemilatticeTests, SemilatticeTests}
import org.scalacheck.{Arbitrary, Prop}
import org.scalacheck.Prop._

object LogicLaws {
def apply[A: Eq: Arbitrary] = new LogicLaws[A] {
object LogicTests {
def apply[A: Eq: Arbitrary] = new LogicTests[A] {
def Equ = Eq[A]
def Arb = implicitly[Arbitrary[A]]
}
}

trait LogicLaws[A] extends LatticeLaws[A] {
trait LogicTests[A] extends LatticeTests[A] {

def heyting(implicit A: Heyting[A]) = new LogicProperties(
name = "heyting",
Expand Down Expand Up @@ -49,8 +50,8 @@ trait LogicLaws[A] extends LatticeLaws[A] {
ll = new LatticeProperties(
name = "lowerBoundedDistributiveLattice",
parents = Seq(boundedJoinSemilattice, distributiveLattice),
join = Some(boundedSemilattice(A.joinSemilattice)),
meet = Some(semilattice(A.meetSemilattice))
join = Some(BoundedSemilatticeTests(A.joinSemilattice).boundedSemilattice),
meet = Some(SemilatticeTests(A.meetSemilattice).semilattice)
),
"""x\y ∧ y = 0""" -> forAll { (x: A, y: A) =>
A.and(A.without(x, y), y) ?== A.zero
Expand Down
Loading

0 comments on commit 844670d

Please sign in to comment.