Skip to content

Commit

Permalink
Merge pull request #1417 from travisbrown/topic/stack-unsafe-monad-tests
Browse files Browse the repository at this point in the history
Add stackUnsafeMonad to MonadTests
  • Loading branch information
peterneyens authored Oct 25, 2016
2 parents 800711b + 308cc07 commit 6b07ff7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ lazy val laws = crossProject.crossType(CrossType.Pure)
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
.configureCross(disableScoverage210Jvm)
.settings(libraryDependencies ++= Seq("org.typelevel" %%% "catalysts-platform" % "0.0.4"))
.settings(testingDependencies: _*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.jsSettings(coverageEnabled := false)
Expand Down
28 changes: 28 additions & 0 deletions laws/src/main/scala/cats/laws/discipline/MonadTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ trait MonadTests[F[_]] extends ApplicativeTests[F] with FlatMapTests[F] {
) ++ (if (Platform.isJvm) Seq[(String, Prop)]("tailRecM stack safety" -> laws.tailRecMStackSafety) else Seq.empty)
}
}

def stackUnsafeMonad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
ArbFAtoB: Arbitrary[F[A => B]],
ArbFBtoC: Arbitrary[F[B => 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)]],
EqFInt: Eq[F[Int]],
iso: Isomorphisms[F]
): RuleSet = {
new RuleSet {
def name: String = "monad (stack-unsafe)"
def bases: Seq[(String, RuleSet)] = Nil
def parents: Seq[RuleSet] = Seq(applicative[A, B, C], flatMap[A, B, C])
def props: Seq[(String, Prop)] = Seq(
"monad left identity" -> forAll(laws.monadLeftIdentity[A, B] _),
"monad right identity" -> forAll(laws.monadRightIdentity[A] _),
"map flatMap coherence" -> forAll(laws.mapFlatMapCoherence[A, B] _)
)
}
}
}

object MonadTests {
Expand Down
15 changes: 15 additions & 0 deletions laws/src/test/scala/cats/laws/discipline/MonadTestsTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cats
package laws
package discipline

import cats.instances.all._
import cats.laws.discipline.arbitrary._
import org.scalatest.FunSuite
import org.typelevel.discipline.scalatest.Discipline

class MonadTestsTests extends FunSuite with Discipline {
// We don't use `stackUnsafeMonad` in our laws checking for instances in Cats,
// so we confirm here that the laws pass for `Eval` (the monad instance for
// which is actually stack safe, like all other monad instances in Cats.)
checkAll("Eval[Int]", MonadTests[Eval].stackUnsafeMonad[Int, Int, Int])
}

0 comments on commit 6b07ff7

Please sign in to comment.