Skip to content

Commit

Permalink
Add kernel-laws dependency and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed May 15, 2021
1 parent 39716dc commit 5130867
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 229 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package laws

import cats.algebra.ring._

import cats.algebra.laws.platform.Platform
import cats.platform.Platform

import org.typelevel.discipline.Predicate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.kernel._
import org.scalacheck.Prop._
import org.scalacheck.{Arbitrary, Prop}
import cats.kernel.instances.boolean._
import cats.kernel.laws.discipline.SerializableTests

object Rules {

Expand Down Expand Up @@ -95,9 +96,5 @@ object Rules {
// ugly platform-specific code follows

def serializable[M](m: M): (String, Prop) =
"serializable" -> (if (IsSerializable()) {
Prop(_ => Result(status = Proof))
} else {
Prop(_ => IsSerializable.testSerialization(m))
})
SerializableTests.serializable(m).props.head
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object FPApprox {
def exact[A: Rng: Order](a: A): FPApprox[A] = FPApprox(a, abs(a), 0)
def approx[A: Rng: Order](a: A): FPApprox[A] = FPApprox(a, abs(a), 1)

trait Epsilon[A] {
trait Epsilon[A] extends Serializable {
def minValue: A
def epsilon: A
def isFinite(a: A): Boolean
Expand Down
57 changes: 28 additions & 29 deletions algebra-laws/shared/src/test/scala/cats/algebra/laws/LawTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import cats.algebra.lattice._
import cats.algebra.ring._
import cats.algebra.instances.all._
import cats.algebra.instances.BigDecimalAlgebra

import cats.algebra.laws.platform.Platform

import cats.platform.Platform
import org.scalacheck.{Arbitrary, Cogen}
import Arbitrary.arbitrary
import cats.kernel.laws.discipline.{EqTests, OrderTests, PartialOrderTests}

import scala.collection.immutable.BitSet
import scala.util.Random

Expand All @@ -21,7 +21,6 @@ class LawTests extends munit.DisciplineSuite {
implicit val intLattice: BoundedDistributiveLattice[Int] = IntMinMaxLattice
implicit val longLattice: BoundedDistributiveLattice[Long] = LongMinMaxLattice

implicit def orderLaws[A: Cogen: Eq: Arbitrary]: OrderLaws[A] = OrderLaws[A]
implicit def groupLaws[A: Eq: Arbitrary]: GroupLaws[A] = GroupLaws[A]
implicit def logicLaws[A: Eq: Arbitrary]: LogicLaws[A] = LogicLaws[A]

Expand Down Expand Up @@ -50,7 +49,7 @@ class LawTests extends munit.DisciplineSuite {
Cogen[A].contramap[HasPartialOrder[A]](_.a)
}

checkAll("Boolean", OrderLaws[Boolean].order) //("Boolean").check(_.order)
checkAll("Boolean", OrderTests[Boolean].order) //("Boolean").check(_.order)
checkAll("Boolean", LogicLaws[Boolean].bool)
checkAll("SimpleHeyting", LogicLaws[SimpleHeyting].logic(Logic.fromHeyting(Heyting[SimpleHeyting])))
checkAll("SimpleHeyting", LogicLaws[SimpleHeyting].heyting)
Expand All @@ -65,61 +64,61 @@ class LawTests extends munit.DisciplineSuite {
// ensure that BoolRing[A].asBool is a valid Bool
checkAll("Boolean- bool-from-ring", LogicLaws[Boolean].bool(new BoolFromBoolRing(booleanRing)))

checkAll("String", OrderLaws[String].order)
checkAll("String", OrderTests[String].order)
checkAll("String", GroupLaws[String].monoid)

{
checkAll("Option[HasEq[Int]]", OrderLaws[Option[HasEq[Int]]].eqv)
checkAll("Option[HasPartialOrder[Int]]", OrderLaws[Option[HasPartialOrder[Int]]].partialOrder)
checkAll("Option[Int]", OrderLaws[Option[Int]].order)
checkAll("Option[HasEq[Int]]", EqTests[Option[HasEq[Int]]].eqv)
checkAll("Option[HasPartialOrder[Int]]", PartialOrderTests[Option[HasPartialOrder[Int]]].partialOrder)
checkAll("Option[Int]", OrderTests[Option[Int]].order)
checkAll("Option[Int]", GroupLaws[Option[Int]].monoid)
checkAll("Option[HasEq[String]]", OrderLaws[Option[HasEq[String]]].eqv)
checkAll("Option[HasPartialOrder[String]]", OrderLaws[Option[HasPartialOrder[String]]].partialOrder)
checkAll("Option[String]", OrderLaws[Option[String]].order)
checkAll("Option[HasEq[String]]", EqTests[Option[HasEq[String]]].eqv)
checkAll("Option[HasPartialOrder[String]]", PartialOrderTests[Option[HasPartialOrder[String]]].partialOrder)
checkAll("Option[String]", OrderTests[Option[String]].order)
checkAll("Option[String]", GroupLaws[Option[String]].monoid)
}

checkAll("List[HasEq[Int]]", OrderLaws[List[HasEq[Int]]].eqv)
checkAll("List[HasPartialOrder[Int]]", OrderLaws[List[HasPartialOrder[Int]]].partialOrder)
checkAll("List[Int]", OrderLaws[List[Int]].order)
checkAll("List[HasEq[Int]]", EqTests[List[HasEq[Int]]].eqv)
checkAll("List[HasPartialOrder[Int]]", PartialOrderTests[List[HasPartialOrder[Int]]].partialOrder)
checkAll("List[Int]", OrderTests[List[Int]].order)
checkAll("List[Int]", GroupLaws[List[Int]].monoid)
checkAll("List[HasEq[String]]", OrderLaws[List[HasEq[String]]].eqv)
checkAll("List[HasPartialOrder[String]]", OrderLaws[List[HasPartialOrder[String]]].partialOrder)
checkAll("List[String]", OrderLaws[List[String]].order)
checkAll("List[HasEq[String]]", EqTests[List[HasEq[String]]].eqv)
checkAll("List[HasPartialOrder[String]]", PartialOrderTests[List[HasPartialOrder[String]]].partialOrder)
checkAll("List[String]", OrderTests[List[String]].order)
checkAll("List[String]", GroupLaws[List[String]].monoid)

checkAll("Set[Byte]", LogicLaws[Set[Byte]].generalizedBool)
checkAll("Set[Byte]", RingLaws[Set[Byte]].boolRng(setBoolRng[Byte]))
checkAll("Set[Byte]-bool-from-rng", LogicLaws[Set[Byte]].generalizedBool(new GenBoolFromBoolRng(setBoolRng)))
checkAll("Set[Byte]-rng-from-bool", RingLaws[Set[Byte]].boolRng(GenBool[Set[Byte]].asBoolRing))
checkAll("Set[Int]", OrderLaws[Set[Int]].partialOrder)
checkAll("Set[Int]", PartialOrderTests[Set[Int]].partialOrder)
checkAll("Set[Int]", RingLaws[Set[Int]].semiring)
checkAll("Set[String]", RingLaws[Set[String]].semiring)

checkAll("Map[Char, Int]", OrderLaws[Map[Char, Int]].eqv)
checkAll("Map[Char, Int]", EqTests[Map[Char, Int]].eqv)
checkAll("Map[Char, Int]", RingLaws[Map[Char, Int]].semiring)
checkAll("Map[Int, BigInt]", OrderLaws[Map[Int, BigInt]].eqv)
checkAll("Map[Int, BigInt]", EqTests[Map[Int, BigInt]].eqv)
checkAll("Map[Int, BigInt]", RingLaws[Map[Int, BigInt]].semiring)

checkAll("Byte", OrderLaws[Byte].order)
checkAll("Byte", OrderTests[Byte].order)
checkAll("Byte", RingLaws[Byte].commutativeRing)
checkAll("Byte", LatticeLaws[Byte].lattice)

checkAll("Short", OrderLaws[Short].order)
checkAll("Short", OrderTests[Short].order)
checkAll("Short", RingLaws[Short].commutativeRing)
checkAll("Short", LatticeLaws[Short].lattice)

checkAll("Char", OrderLaws[Char].order)
checkAll("Char", OrderTests[Char].order)

checkAll("Int", OrderLaws[Int].order)
checkAll("Int", OrderTests[Int].order)
checkAll("Int", RingLaws[Int].commutativeRing)
checkAll("Int", LatticeLaws[Int].boundedDistributiveLattice)

{
checkAll("Int", RingLaws[Int].commutativeRig)
}

checkAll("Long", OrderLaws[Long].order)
checkAll("Long", OrderTests[Long].order)
checkAll("Long", RingLaws[Long].commutativeRing)
checkAll("Long", LatticeLaws[Long].boundedDistributiveLattice)

Expand Down Expand Up @@ -170,7 +169,7 @@ class LawTests extends munit.DisciplineSuite {
checkAll("(Int, Int) Band", GroupLaws[(Int, Int)].band)
}

checkAll("Unit", OrderLaws[Unit].order)
checkAll("Unit", OrderTests[Unit].order)
checkAll("Unit", RingLaws[Unit].commutativeRing)
checkAll("Unit", RingLaws[Unit].multiplicativeMonoid)
checkAll("Unit", LatticeLaws[Unit].boundedSemilattice)
Expand Down Expand Up @@ -223,8 +222,8 @@ class LawTests extends munit.DisciplineSuite {
}

// checkAll("Int", "fromOrdering", OrderLaws[Int].order(Order.fromOrdering[Int]))
checkAll("Array[Int]", OrderLaws[Array[Int]].order)
checkAll("Array[Int]", OrderLaws[Array[Int]].partialOrder)
checkAll("Array[Int]", OrderTests[Array[Int]].order)
checkAll("Array[Int]", PartialOrderTests[Array[Int]].partialOrder)

// Rational tests do not return on Scala-js, so we make them JVM only.
if (Platform.isJvm) checkAll("Rat", RingLaws[Rat].field)
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ lazy val algebraLaws = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(Test / scalacOptions := (Test / scalacOptions).value.filter(_ != "-Xfatal-warnings"))
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings)
.dependsOn(kernel, algebra)
.dependsOn(kernelLaws, algebra)
.nativeSettings(commonNativeSettings)

lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
Expand Down

0 comments on commit 5130867

Please sign in to comment.