-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainTest.scala
45 lines (38 loc) · 1.6 KB
/
MainTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalacheck._
import org.scalacheck.effect.PropF
import org.scalatest.exceptions.TestFailedException
import org.scalatestplus.scalacheck.{CheckerAsserting, Checkers, ScalaCheckPropertyChecks}
import scala.concurrent.Future
class MainTest extends AsyncFlatSpec with Matchers with ScalaCheckPropertyChecks {
behavior of "Main"
it should "perform computations" in {
forAll(Gen.oneOf(0 until 10)) { i =>
assert(i < 5) // intentional fail - we want to see how the failure is reported
}
}
it should "perform async computations" in {
PropF.forAllF(Gen.oneOf(0 until 10)) { i =>
Future {
assert(i < 5) // intentional fail - we want to see how the failure is reported
}.map(_ => ()) // forAllF supports Future[Unit] by default, so we need to throw away the Assertion value
}.check().map { result =>
val propResult = result.status match {
case _: Test.Proved =>
Prop.Result(Prop.Proof)
case Test.Exhausted =>
Prop.Result(Prop.Undecided)
case Test.Failed(scalaCheckArgs, scalaCheckLabels) =>
Prop.Result(status = Prop.False, args = scalaCheckArgs, labels = scalaCheckLabels)
case Test.PropException(scalaCheckArgs, e, scalaCheckLabels) =>
Prop.Result(status = Prop.Exception(e), args = scalaCheckArgs, labels = scalaCheckLabels)
case _ if result.passed =>
Prop.Result(Prop.True)
case _ =>
Prop.Result(Prop.False)
}
Checkers.check(Prop(_ => propResult))
}
}
}