Skip to content

Commit

Permalink
Merge pull request #267 from Kevin-Lee/task/266/test-monad-laws
Browse files Browse the repository at this point in the history
Close #266 - There should be a way to test each Monad law instead of testing all the laws at once
  • Loading branch information
kevin-lee authored Aug 10, 2021
2 parents 6bf57eb + 9edeed9 commit 06e5a39
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 462 deletions.
32 changes: 18 additions & 14 deletions cats-effect/src/test/scala-2/effectie/cats/FxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ object FxSpec extends Properties {
override def tests: List[Test] = List(
property("test Fx[IO].effectOf", IoSpec.testEffectOf),
property("test Fx[IO].pureOf", IoSpec.testPureOf),
example("test Fx[IO].unitOf", IoSpec.testUnitOf),
property("test Fx[IO] Monad laws", IoSpec.testMonadLaws),
property("test Fx[Future].effectOf", FutureSpec.testEffectOf),
property("test Fx[Future].pureOf", FutureSpec.testPureOf),
example("test Fx[Future].unitOf", FutureSpec.testUnitOf),
property("test Fx[Future] Monad laws", FutureSpec.testMonadLaws),
property("test Fx[Id].effectOf", IdSpec.testEffectOf),
property("test Fx[Id].pureOf", IdSpec.testPureOf),
example("test Fx[Id].unitOf", IdSpec.testUnitOf),
property("test Fx[Id] Monad laws", IdSpec.testMonadLaws),
)
example("test Fx[IO].unitOf", IoSpec.testUnitOf)
) ++
IoSpec.testMonadLaws ++
List(
property("test Fx[Future].effectOf", FutureSpec.testEffectOf),
property("test Fx[Future].pureOf", FutureSpec.testPureOf),
example("test Fx[Future].unitOf", FutureSpec.testUnitOf),
) ++
FutureSpec.testMonadLaws ++
List(
property("test Fx[Id].effectOf", IdSpec.testEffectOf),
property("test Fx[Id].pureOf", IdSpec.testPureOf),
example("test Fx[Id].unitOf", IdSpec.testUnitOf),
) ++
IdSpec.testMonadLaws

object IoSpec {

Expand Down Expand Up @@ -76,7 +80,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = {
def testMonadLaws: List[Test] = {
import cats.syntax.eq._

implicit val eqIo: Eq[IO[Int]] =
Expand Down Expand Up @@ -147,7 +151,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = {
def testMonadLaws: List[Test] = {
import cats.syntax.eq._

implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
Expand Down Expand Up @@ -203,7 +207,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = MonadSpec.testMonadLaws[Id]
def testMonadLaws: List[Test] = MonadSpec.testMonadLaws[Id]

}

Expand Down
30 changes: 17 additions & 13 deletions cats-effect/src/test/scala-3/effectie/cats/FxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ object FxSpec extends Properties {
property("test Fx[IO].effectOf", IoSpec.testEffectOf),
property("test Fx[IO].pureOf", IoSpec.testPureOf),
example("test Fx[IO].unitOf", IoSpec.testUnitOf),
property("test Fx[IO] Monad laws", IoSpec.testMonadLaws),
property("test Fx[Future].effectOf", FutureSpec.testEffectOf),
property("test Fx[Future].pureOf", FutureSpec.testPureOf),
example("test Fx[Future].unitOf", FutureSpec.testUnitOf),
property("test Fx[Future] Monad laws", FutureSpec.testMonadLaws),
property("test Fx[Id].effectOf", IdSpec.testEffectOf),
property("test Fx[Id].pureOf", IdSpec.testPureOf),
example("test Fx[Id].unitOf", IdSpec.testUnitOf),
property("test Fx[Id] Monad laws", IdSpec.testMonadLaws),
)
) ++
IoSpec.testMonadLaws ++
List(
property("test Fx[Future].effectOf", FutureSpec.testEffectOf),
property("test Fx[Future].pureOf", FutureSpec.testPureOf),
example("test Fx[Future].unitOf", FutureSpec.testUnitOf),
) ++
FutureSpec.testMonadLaws ++
List(
property("test Fx[Id].effectOf", IdSpec.testEffectOf),
property("test Fx[Id].pureOf", IdSpec.testPureOf),
example("test Fx[Id].unitOf", IdSpec.testUnitOf),
) ++
IdSpec.testMonadLaws

object IoSpec {

Expand Down Expand Up @@ -74,7 +78,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = {
def testMonadLaws: List[Test] = {
import cats.syntax.eq.*

implicit val eqIo: Eq[IO[Int]] =
Expand Down Expand Up @@ -143,7 +147,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = {
def testMonadLaws: List[Test] = {
import cats.syntax.eq.*

implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
Expand Down Expand Up @@ -197,7 +201,7 @@ object FxSpec extends Properties {
actual ==== expected
}

def testMonadLaws: Property = MonadSpec.testMonadLaws[Id]
def testMonadLaws: List[Test] = MonadSpec.testMonadLaws[Id]

}

Expand Down
14 changes: 3 additions & 11 deletions cats-effect/src/test/scala/effectie/cats/MonadSpec.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package effectie.cats

import cats.Eq
import effectie.testing.cats.{Gens, Specs}
import hedgehog.Property
import hedgehog.runner.Test

object MonadSpec {
def testMonadLaws[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.laws[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
Gens.genIntFromMinToMax,
Gens.genIntToInt,
Gens.genAToMonadA(Gens.genIntToInt)
)
def testMonadLaws[F[_]: Fx](implicit eqF: Eq[F[Int]]): List[Test] =
effectie.testing.cats.MonadSpec.testAllLaws[F]
}
134 changes: 0 additions & 134 deletions cats-effect3/src/test/scala/effectie/cats/LawsProperties.scala

This file was deleted.

20 changes: 10 additions & 10 deletions cats-effect3/src/test/scala/effectie/cats/MonadSpec.scala
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
package effectie.cats

import cats.Eq
import effectie.testing.cats.Gens
import effectie.testing.cats.{Specs, Gens}
import hedgehog.Property

object MonadSpec {
def test1_Identity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.identity[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
)

def test2_Composition[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.composition[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
Gens.genIntToInt,
)

def test3_IdentityAp[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.identityAp[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
)

def test4_Homomorphism[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.homomorphism[F](
Gens.genIntFromMinToMax,
Gens.genIntToInt,
)

def test5_Interchange[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.interchange[F](
Gens.genIntFromMinToMax,
Gens.genIntToInt,
)

def test6_CompositionAp[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.compositionAp[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
Gens.genIntToInt,
)

def test7_LeftIdentity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.leftIdentity[F](
Gens.genIntFromMinToMax,
Gens.genAToMonadA(Gens.genIntToInt)
)

def test8_RightIdentity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.rightIdentity[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
)

def test9_Associativity[F[_]: Fx](implicit eqF: Eq[F[Int]]): Property =
Specs
.monadLaws
.MonadLaws
.associativity[F](
Gens.genFA[F, Int](Gens.genInt(Int.MinValue, Int.MaxValue)),
Gens.genAToMonadA(Gens.genIntToInt)
Expand Down
Loading

0 comments on commit 06e5a39

Please sign in to comment.