Skip to content

Commit

Permalink
Port tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Sep 21, 2017
1 parent 8c67038 commit 29f9434
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 118 deletions.
6 changes: 3 additions & 3 deletions js/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package js
package tests

import cats.kernel.laws.GroupLaws
import cats.kernel.laws.discipline.{MonoidTests, SemigroupTests}
import cats.laws.discipline._
import cats.js.instances.Await
import cats.js.instances.future.futureComonad
Expand Down Expand Up @@ -58,8 +58,8 @@ class FutureTests extends CatsSuite {

{
implicit val F = ListWrapper.semigroup[Int]
checkAll("Future[ListWrapper[Int]]", GroupLaws[Future[ListWrapper[Int]]].semigroup)
checkAll("Future[ListWrapper[Int]]", SemigroupTests[Future[ListWrapper[Int]]].semigroup)
}

checkAll("Future[Int]", GroupLaws[Future[Int]].monoid)
checkAll("Future[Int]", MonoidTests[Future[Int]].monoid)
}
6 changes: 3 additions & 3 deletions jvm/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package jvm
package tests

import cats.kernel.laws.GroupLaws
import cats.kernel.laws.discipline.{MonoidTests, SemigroupTests}
import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.tests.{CatsSuite, ListWrapper}
Expand Down Expand Up @@ -44,8 +44,8 @@ class FutureTests extends CatsSuite {

{
implicit val F = ListWrapper.semigroup[Int]
checkAll("Future[ListWrapper[Int]]", GroupLaws[Future[ListWrapper[Int]]].semigroup)
checkAll("Future[ListWrapper[Int]]", SemigroupTests[Future[ListWrapper[Int]]].semigroup)
}

checkAll("Future[Int]", GroupLaws[Future[Int]].monoid)
checkAll("Future[Int]", MonoidTests[Future[Int]].monoid)
}
1 change: 0 additions & 1 deletion kernel-laws/src/test/scala/cats/kernel/laws/LawTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class LawTests extends FunSuite with Discipline {
checkAll("Semilattice.asMeetPartialOrder[Set[Int]]", PartialOrderTests(Semilattice.asMeetPartialOrder[Set[Int]]).partialOrder)
checkAll("Semilattice.asJoinPartialOrder[Set[Int]]", PartialOrderTests(Semilattice.asJoinPartialOrder[Set[Int]]).partialOrder)

checkAll("Order[Unit]", OrderTests[Unit].order)
checkAll("Order[Unit]", OrderTests[Unit].order)
checkAll("Order[Boolean]", OrderTests[Boolean].order)
checkAll("Order[String]", OrderTests[String].order)
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/CategoryTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package tests

import cats.kernel.laws.GroupLaws
import cats.kernel.laws.discipline.{MonoidTests => MonoidTypeclassTests}

import cats.arrow.Category
import cats.laws.discipline.{MonoidKTests, SerializableTests}
Expand All @@ -15,5 +15,5 @@ class CategoryTest extends CatsSuite {
checkAll("Category[Function1].algebraK", SerializableTests.serializable(functionCategory.algebraK))

val functionAlgebra = functionCategory.algebra[Int]
checkAll("Category[Function1].algebra[Int]", GroupLaws[Endo[Int]].monoid(functionAlgebra))
checkAll("Category[Function1].algebra[Int]", MonoidTypeclassTests[Endo[Int]](functionAlgebra).monoid)
}
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/ComposeTest.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package tests

import cats.kernel.laws.GroupLaws
import cats.kernel.laws.discipline.{SemigroupTests => SemigroupTypeclassTests}

import cats.arrow.Compose
import cats.laws.discipline.{SemigroupKTests, SerializableTests}
Expand All @@ -15,7 +15,7 @@ class ComposeTest extends CatsSuite {
checkAll("Compose[Function1].algebraK", SerializableTests.serializable(functionCompose.algebraK))

val functionAlgebra = functionCompose.algebra[Int]
checkAll("Compose[Function1].algebra[Int]", GroupLaws[Endo[Int]].semigroup(functionAlgebra))
checkAll("Compose[Function1].algebra[Int]", SemigroupTypeclassTests[Endo[Int]](functionAlgebra).semigroup)

test("syntax") {
(((_: Int) + 1) <<< ((_: Int) / 2))(2) should be(2)
Expand Down
19 changes: 12 additions & 7 deletions tests/src/test/scala/cats/tests/ConstTests.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package cats
package tests

import cats.kernel.laws.{GroupLaws, OrderLaws}

import cats.kernel.laws.discipline.{
MonoidTests => MonoidTypeclassTests,
SemigroupTests => SemigroupTypeclassTests,
OrderTests => OrderTypeclassTests,
PartialOrderTests => PartialOrderTypeclassTests,
EqTests => EqTypeclassTests
}
import cats.data.{Const, NonEmptyList}
import cats.functor.Contravariant
import cats.laws.discipline._
Expand Down Expand Up @@ -30,17 +35,17 @@ class ConstTests extends CatsSuite {
}

// Algebra checks for Serializability of instances as part of the laws
checkAll("Monoid[Const[Int, String]]", GroupLaws[Const[Int, String]].monoid)
checkAll("Monoid[Const[Int, String]]", MonoidTypeclassTests[Const[Int, String]].monoid)

checkAll("Const[NonEmptyList[Int], String]", GroupLaws[Const[NonEmptyList[Int], String]].semigroup)
checkAll("Const[NonEmptyList[Int], String]", SemigroupTypeclassTests[Const[NonEmptyList[Int], String]].semigroup)

// Note while Eq is a superclass of PartialOrder and PartialOrder a superclass
// of Order, you can get different instances with different (more general) constraints.
// For instance, you can get an Order for Const if the first type parameter has an Order,
// but you can also get just an Eq for Const if the first type parameter has just an Eq
checkAll("Const[Map[Int, Int], String]", OrderLaws[Const[Map[Int, Int], String]].eqv)
checkAll("PartialOrder[Const[Set[Int], String]]", OrderLaws[Const[Set[Int], String]].partialOrder)
checkAll("Order[Const[Int, String]]", OrderLaws[Const[Int, String]].order)
checkAll("Const[Map[Int, Int], String]", EqTypeclassTests[Const[Map[Int, Int], String]].eqv)
checkAll("PartialOrder[Const[Set[Int], String]]", PartialOrderTypeclassTests[Const[Set[Int], String]].partialOrder)
checkAll("Order[Const[Int, String]]", OrderTypeclassTests[Const[Int, String]].order)

checkAll("Const[String, Int]", ContravariantTests[Const[String, ?]].contravariant[Int, Int, Int])
checkAll("Contravariant[Const[String, ?]]", SerializableTests.serializable(Contravariant[Const[String, ?]]))
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/EitherKTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats.tests

import cats._
import cats.kernel.laws.OrderLaws
import cats.kernel.laws.discipline.{EqTests => EqTypeclassTests}
import cats.data.EitherK
import cats.functor.Contravariant
import cats.laws.discipline._
Expand All @@ -28,7 +28,7 @@ class EitherKTests extends CatsSuite {
checkAll("CoflatMap[EitherK[Eval, Eval, ?]]", SerializableTests.serializable(CoflatMap[EitherK[Eval, Eval, ?]]))
}

checkAll("EitherK[Option, Option, Int]", OrderLaws[EitherK[Option, Option, Int]].eqv)
checkAll("EitherK[Option, Option, Int]", EqTypeclassTests[EitherK[Option, Option, Int]].eqv)
checkAll("Eq[EitherK[Option, Option, Int]]", SerializableTests.serializable(Eq[EitherK[Option, Option, Int]]))

checkAll("EitherK[Show, Show, ?]", ContravariantTests[EitherK[Show, Show, ?]].contravariant[Int, Int, Int])
Expand Down
18 changes: 12 additions & 6 deletions tests/src/test/scala/cats/tests/EitherTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import cats.functor.Bifunctor
import cats.functor._
import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.kernel.laws.{GroupLaws, OrderLaws}
import cats.kernel.laws.discipline.{
MonoidTests => MonoidTypeclassTests,
SemigroupTests => SemigroupTypeclassTests,
OrderTests => OrderTypeclassTests,
PartialOrderTests => PartialOrderTypeclassTests,
EqTests => EqTypeclassTests
}


class EitherTTests extends CatsSuite {
Expand All @@ -20,7 +26,7 @@ class EitherTTests extends CatsSuite {
{
implicit val F = ListWrapper.order[Either[String, Int]]

checkAll("EitherT[List, String, Int]", OrderLaws[EitherT[ListWrapper, String, Int]].order)
checkAll("EitherT[List, String, Int]", OrderTypeclassTests[EitherT[ListWrapper, String, Int]].order)
checkAll("Order[EitherT[List, String, Int]]", SerializableTests.serializable(Order[EitherT[ListWrapper, String, Int]]))
}

Expand Down Expand Up @@ -100,14 +106,14 @@ class EitherTTests extends CatsSuite {
{
implicit val F = ListWrapper.partialOrder[Either[String, Int]]

checkAll("EitherT[ListWrapper, String, Int]", OrderLaws[EitherT[ListWrapper, String, Int]].partialOrder)
checkAll("EitherT[ListWrapper, String, Int]", PartialOrderTypeclassTests[EitherT[ListWrapper, String, Int]].partialOrder)
checkAll("PartialOrder[EitherT[ListWrapper, String, Int]]", SerializableTests.serializable(PartialOrder[EitherT[ListWrapper, String, Int]]))
}

{
implicit val F = ListWrapper.semigroup[Either[String, Int]]

checkAll("EitherT[ListWrapper, String, Int]", GroupLaws[EitherT[ListWrapper, String, Int]].semigroup)
checkAll("EitherT[ListWrapper, String, Int]", SemigroupTypeclassTests[EitherT[ListWrapper, String, Int]].semigroup)
checkAll("Semigroup[EitherT[ListWrapper, String, Int]]", SerializableTests.serializable(Semigroup[EitherT[ListWrapper, String, Int]]))
}

Expand All @@ -116,14 +122,14 @@ class EitherTTests extends CatsSuite {

Semigroup[EitherT[ListWrapper, String, Int]]

checkAll("EitherT[ListWrapper, String, Int]", GroupLaws[EitherT[ListWrapper, String, Int]].monoid)
checkAll("EitherT[ListWrapper, String, Int]", MonoidTypeclassTests[EitherT[ListWrapper, String, Int]].monoid)
checkAll("Monoid[EitherT[ListWrapper, String, Int]]", SerializableTests.serializable(Monoid[EitherT[ListWrapper, String, Int]]))
}

{
implicit val F = ListWrapper.eqv[Either[String, Int]]

checkAll("EitherT[ListWrapper, String, Int]", OrderLaws[EitherT[ListWrapper, String, Int]].eqv)
checkAll("EitherT[ListWrapper, String, Int]", EqTypeclassTests[EitherT[ListWrapper, String, Int]].eqv)
checkAll("Eq[EitherT[ListWrapper, String, Int]]", SerializableTests.serializable(Eq[EitherT[ListWrapper, String, Int]]))
}

Expand Down
19 changes: 12 additions & 7 deletions tests/src/test/scala/cats/tests/EitherTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ package tests

import cats.data.EitherT
import cats.laws.discipline._
import cats.kernel.laws.{GroupLaws, OrderLaws}
import cats.kernel.laws.discipline.{
MonoidTests => MonoidTypeclassTests,
SemigroupTests => SemigroupTypeclassTests,
OrderTests => OrderTypeclassTests,
PartialOrderTests => PartialOrderTypeclassTests,
EqTests => EqTypeclassTests
}
import scala.util.Try

class EitherTests extends CatsSuite {
implicit val iso = CartesianTests.Isomorphisms.invariant[Either[Int, ?]]

checkAll("Either[String, Int]", GroupLaws[Either[String, Int]].monoid)
checkAll("Either[String, Int]", MonoidTypeclassTests[Either[String, Int]].monoid)
checkAll("Monoid[Either[String, Int]]", SerializableTests.serializable(Monoid[Either[String, Int]]))

checkAll("Either[Int, Int]", CartesianTests[Either[Int, ?]].cartesian[Int, Int, Int])
Expand All @@ -29,7 +35,7 @@ class EitherTests extends CatsSuite {
checkAll("Either[ListWrapper[String], ?]", SemigroupKTests[Either[ListWrapper[String], ?]].semigroupK[Int])
checkAll("SemigroupK[Either[ListWrapper[String], ?]]", SerializableTests.serializable(SemigroupK[Either[ListWrapper[String], ?]]))

checkAll("Either[ListWrapper[String], Int]", GroupLaws[Either[ListWrapper[String], Int]].semigroup)
checkAll("Either[ListWrapper[String], Int]", SemigroupTypeclassTests[Either[ListWrapper[String], Int]].semigroup)
checkAll("Semigroup[Either[ListWrapper[String], Int]]", SerializableTests.serializable(Semigroup[Either[ListWrapper[String], Int]]))

val partialOrder = catsStdPartialOrderForEither[Int, String]
Expand All @@ -40,13 +46,12 @@ class EitherTests extends CatsSuite {
{
implicit val S = ListWrapper.eqv[String]
implicit val I = ListWrapper.eqv[Int]
checkAll("Either[ListWrapper[String], ListWrapper[Int]]", OrderLaws[Either[ListWrapper[String], ListWrapper[Int]]].eqv)
checkAll("Either[ListWrapper[String], ListWrapper[Int]]", EqTypeclassTests[Either[ListWrapper[String], ListWrapper[Int]]].eqv)
checkAll("Eq[Either[ListWrapper[String], ListWrapper[Int]]]", SerializableTests.serializable(Eq[Either[ListWrapper[String], ListWrapper[Int]]]))
}

val orderLaws = OrderLaws[Either[Int, String]]
checkAll("Either[Int, String]", orderLaws.partialOrder(partialOrder))
checkAll("Either[Int, String]", orderLaws.order(order))
checkAll("Either[Int, String]", PartialOrderTypeclassTests[Either[Int, String]](partialOrder).partialOrder)
checkAll("Either[Int, String]", OrderTypeclassTests[Either[Int, String]](order).order)

test("Left/Right cast syntax") {
forAll { (e: Either[Int, String]) =>
Expand Down
21 changes: 14 additions & 7 deletions tests/src/test/scala/cats/tests/EvalTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import scala.math.min
import cats.laws.ComonadLaws
import cats.laws.discipline.{BimonadTests, CartesianTests, ReducibleTests, SerializableTests}
import cats.laws.discipline.arbitrary._
import cats.kernel.laws.{GroupLaws, OrderLaws}
import cats.kernel.laws.discipline.{
MonoidTests => MonoidTypeclassTests,
SemigroupTests => SemigroupTypeclassTests,
GroupTests => GroupTypeclassTests,
OrderTests => OrderTypeclassTests,
PartialOrderTests => PartialOrderTypeclassTests,
EqTests => EqTypeclassTests
}

class EvalTests extends CatsSuite {
implicit val eqThrow: Eq[Throwable] = Eq.allEqual
Expand Down Expand Up @@ -95,31 +102,31 @@ class EvalTests extends CatsSuite {
checkAll("Eval[Int]", ReducibleTests[Eval].reducible[Option, Int, Int])
checkAll("Reducible[Eval]", SerializableTests.serializable(Reducible[Eval]))

checkAll("Eval[Int]", GroupLaws[Eval[Int]].group)
checkAll("Eval[Int]", GroupTypeclassTests[Eval[Int]].group)

{
implicit val A = ListWrapper.monoid[Int]
checkAll("Eval[ListWrapper[Int]]", GroupLaws[Eval[ListWrapper[Int]]].monoid)
checkAll("Eval[ListWrapper[Int]]", MonoidTypeclassTests[Eval[ListWrapper[Int]]].monoid)
}

{
implicit val A = ListWrapper.semigroup[Int]
checkAll("Eval[ListWrapper[Int]]", GroupLaws[Eval[ListWrapper[Int]]].semigroup)
checkAll("Eval[ListWrapper[Int]]", SemigroupTypeclassTests[Eval[ListWrapper[Int]]].semigroup)
}

{
implicit val A = ListWrapper.order[Int]
checkAll("Eval[ListWrapper[Int]]", OrderLaws[Eval[ListWrapper[Int]]].order)
checkAll("Eval[ListWrapper[Int]]", OrderTypeclassTests[Eval[ListWrapper[Int]]].order)
}

{
implicit val A = ListWrapper.partialOrder[Int]
checkAll("Eval[ListWrapper[Int]]", OrderLaws[Eval[ListWrapper[Int]]].partialOrder)
checkAll("Eval[ListWrapper[Int]]", PartialOrderTypeclassTests[Eval[ListWrapper[Int]]].partialOrder)
}

{
implicit val A = ListWrapper.eqv[Int]
checkAll("Eval[ListWrapper[Int]]", OrderLaws[Eval[ListWrapper[Int]]].eqv)
checkAll("Eval[ListWrapper[Int]]", EqTypeclassTests[Eval[ListWrapper[Int]]].eqv)
}

// The following tests check laws which are a different formulation of
Expand Down
59 changes: 36 additions & 23 deletions tests/src/test/scala/cats/tests/FunctionTests.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package cats
package tests

import cats.arrow.{CommutativeArrow, Choice}
import cats.arrow.{Choice, CommutativeArrow}
import cats.functor.Contravariant
import cats.kernel.laws.discipline.{
MonoidTests => MonoidTypeclassTests,
SemigroupTests => SemigroupTypeclassTests,
EqTests => EqTypeclassTests,
CommutativeSemigroupTests,
PartialOrderTests => PartialOrderTypeclassTests,
OrderTests => OrderTypeclassTests,
BandTests,
SemilatticeTests,
CommutativeMonoidTests,
BoundedSemilatticeTests,
GroupTests => GroupTypeclassTests,
CommutativeGroupTests
}
import cats.laws.discipline._
import cats.laws.discipline.eq._
import cats.laws.discipline.arbitrary._
import cats.kernel.laws.{ GroupLaws, OrderLaws }
import cats.kernel.{ CommutativeSemigroup, CommutativeMonoid, CommutativeGroup }
import cats.kernel.{ Band, Semilattice, BoundedSemilattice }

Expand Down Expand Up @@ -41,18 +54,18 @@ class FunctionTests extends CatsSuite {


// law checks for the various Function0-related instances
checkAll("Function0[Eqed]", OrderLaws[Function0[Eqed]].eqv)
checkAll("Function0[POrd]", OrderLaws[Function0[POrd]].partialOrder)
checkAll("Function0[Ord]", OrderLaws[Function0[Ord]].order)
checkAll("Function0[Semi]", GroupLaws[Function0[Semi]].semigroup)
checkAll("Function0[CSemi]", GroupLaws[Function0[CSemi]].commutativeSemigroup)
checkAll("Function0[Bnd]", GroupLaws[Function0[Bnd]].band)
checkAll("Function0[SL]", GroupLaws[Function0[SL]].semilattice)
checkAll("Function0[BSL]", GroupLaws[Function0[BSL]].boundedSemilattice)
checkAll("Function0[Mono]", GroupLaws[Function0[Mono]].monoid)
checkAll("Function0[CMono]", GroupLaws[Function0[CMono]].commutativeMonoid)
checkAll("Function0[Grp]", GroupLaws[Function0[Grp]].group)
checkAll("Function0[CGrp]", GroupLaws[Function0[CGrp]].commutativeGroup)
checkAll("Function0[Eqed]", EqTypeclassTests[Function0[Eqed]].eqv)
checkAll("Function0[POrd]", PartialOrderTypeclassTests[Function0[POrd]].partialOrder)
checkAll("Function0[Ord]", OrderTypeclassTests[Function0[Ord]].order)
checkAll("Function0[Semi]", SemigroupTypeclassTests[Function0[Semi]].semigroup)
checkAll("Function0[CSemi]", CommutativeSemigroupTests[Function0[CSemi]].commutativeSemigroup)
checkAll("Function0[Bnd]", BandTests[Function0[Bnd]].band)
checkAll("Function0[SL]", SemilatticeTests[Function0[SL]].semilattice)
checkAll("Function0[BSL]", BoundedSemilatticeTests[Function0[BSL]].boundedSemilattice)
checkAll("Function0[Mono]", MonoidTypeclassTests[Function0[Mono]].monoid)
checkAll("Function0[CMono]", CommutativeMonoidTests[Function0[CMono]].commutativeMonoid)
checkAll("Function0[Grp]", GroupTypeclassTests[Function0[Grp]].group)
checkAll("Function0[CGrp]", CommutativeGroupTests[Function0[CGrp]].commutativeGroup)

// serialization tests for the various Function0-related instances
checkAll("Eq[() => Eqed]", SerializableTests.serializable(Eq[() => Eqed]))
Expand All @@ -70,15 +83,15 @@ class FunctionTests extends CatsSuite {


// law checks for the various Function1-related instances
checkAll("Function1[String, Semi]", GroupLaws[Function1[String, Semi]].semigroup)
checkAll("Function1[String, CSemi]", GroupLaws[Function1[String, CSemi]].commutativeSemigroup)
checkAll("Function1[String, Bnd]", GroupLaws[Function1[String, Bnd]].band)
checkAll("Function1[String, SL]", GroupLaws[Function1[String, SL]].semilattice)
checkAll("Function1[String, BSL]", GroupLaws[Function1[String, BSL]].boundedSemilattice)
checkAll("Function1[String, Mono]", GroupLaws[Function1[String, Mono]].monoid)
checkAll("Function1[String, CMono]", GroupLaws[Function1[String, CMono]].commutativeMonoid)
checkAll("Function1[String, Grp]", GroupLaws[Function1[String, Grp]].group)
checkAll("Function1[String, CGrp]", GroupLaws[Function1[String, CGrp]].commutativeGroup)
checkAll("Function1[String, Semi]", SemigroupTypeclassTests[Function1[String, Semi]].semigroup)
checkAll("Function1[String, CSemi]", CommutativeSemigroupTests[Function1[String, CSemi]].commutativeSemigroup)
checkAll("Function1[String, Bnd]", BandTests[Function1[String, Bnd]].band)
checkAll("Function1[String, SL]", SemilatticeTests[Function1[String, SL]].semilattice)
checkAll("Function1[String, BSL]", BoundedSemilatticeTests[Function1[String, BSL]].boundedSemilattice)
checkAll("Function1[String, Mono]", MonoidTypeclassTests[Function1[String, Mono]].monoid)
checkAll("Function1[String, CMono]", CommutativeMonoidTests[Function1[String, CMono]].commutativeMonoid)
checkAll("Function1[String, Grp]", GroupTypeclassTests[Function1[String, Grp]].group)
checkAll("Function1[String, CGrp]", CommutativeGroupTests[Function1[String, CGrp]].commutativeGroup)

// serialization tests for the various Function1-related instances
checkAll("Semigroup[String => Semi]", SerializableTests.serializable(Semigroup[String => Semi]))
Expand Down
Loading

0 comments on commit 29f9434

Please sign in to comment.