Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru committed May 12, 2017
1 parent 8dc3cc8 commit 1822867
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
33 changes: 21 additions & 12 deletions core/shared/src/test/scala/cats/effect/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package cats
package effect

import org.scalacheck._

import scala.util.Either

object Generators {
import Arbitrary._

implicit def arbIO[A: Arbitrary: Cogen]: Arbitrary[IO[A]] = Arbitrary(Gen.delay(genIO[A]))
implicit def arbIO[A: Arbitrary: Cogen]: Arbitrary[IO[A]] =
Arbitrary(Gen.delay(genIO[A]))

def genIO[A: Arbitrary: Cogen]: Gen[IO[A]] = {
Gen.frequency(
Expand All @@ -41,22 +41,31 @@ object Generators {
5 -> genPure[A],
5 -> genApply[A],
1 -> genFail[A],
10 -> genFlatMap[A])
5 -> genBindSuspend[A])
}

def genPure[A: Arbitrary]: Gen[IO[A]] = arbitrary[A].map(IO.pure(_))
def genPure[A: Arbitrary]: Gen[IO[A]] =
arbitrary[A].map(IO.pure)

def genApply[A: Arbitrary]: Gen[IO[A]] = arbitrary[A].map(IO.apply(_))
def genApply[A: Arbitrary]: Gen[IO[A]] =
arbitrary[A].map(IO.apply(_))

def genFail[A]: Gen[IO[A]] = arbitrary[Throwable].map(IO.raiseError(_))
def genFail[A]: Gen[IO[A]] =
arbitrary[Throwable].map(IO.raiseError)

def genAsync[A: Arbitrary]: Gen[IO[A]] = arbitrary[(Either[Throwable, A] => Unit) => Unit].map(IO.async(_))
def genAsync[A: Arbitrary]: Gen[IO[A]] =
arbitrary[(Either[Throwable, A] => Unit) => Unit].map(IO.async)

def genNestedAsync[A: Arbitrary: Cogen]: Gen[IO[A]] =
arbitrary[(Either[Throwable, IO[A]] => Unit) => Unit].map(k => IO.async(k).flatMap(x => x))
arbitrary[(Either[Throwable, IO[A]] => Unit) => Unit]
.map(k => IO.async(k).flatMap(x => x))

def genBindSuspend[A: Arbitrary: Cogen]: Gen[IO[A]] =
arbitrary[A].map(IO.apply(_).flatMap(IO.pure))

def genFlatMap[A: Arbitrary: Cogen]: Gen[IO[A]] = for {
ioa <- arbitrary[IO[A]]
f <- arbitrary[A => IO[A]]
} yield ioa.flatMap(f)
def genFlatMap[A: Arbitrary: Cogen]: Gen[IO[A]] =
for {
ioa <- arbitrary[IO[A]]
f <- arbitrary[A => IO[A]]
} yield ioa.flatMap(f)
}
3 changes: 1 addition & 2 deletions laws/shared/src/test/scala/cats/effect/IOTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ class IOTests extends BaseTestsSuite {
testAsync("sync.to[IO] is stack-safe") { implicit ec =>
// Override default generator to only generate
// synchronous instances that are stack-safe
implicit val arbIO: Arbitrary[IO[Int]] =
Arbitrary(Gen.delay(genSyncIO[Int]))
implicit val arbIO = Arbitrary(genSyncIO[Int])

check { (io: IO[Int]) =>
repeatedTransformLoop(10000, io) <-> io
Expand Down

0 comments on commit 1822867

Please sign in to comment.