Created
August 15, 2013 06:09
-
-
Save etorreborre/6238633 to your computer and use it in GitHub Desktop.
A checkAll method to check ScalaCheck Properties with immutable specifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.specs2._ | |
| import org.scalacheck.Properties | |
| import org.specs2.matcher._ | |
| /** | |
| * [info] TestSpec | |
| * [info] MyProps must satisfy | |
| * [info] | |
| * [info] + MyProps.myProp1 | |
| * [info] + MyProps.myProp2 | |
| * [info] x MyProps.myProp3 | |
| * [error] A counter-example is [] (after 0 try) | |
| * [info] | |
| * [info] | |
| * [info] Total for specification TestSpec | |
| * [info] Finished in 14 ms | |
| * [info] 3 examples, 201 expectations, 1 failure, 0 error | |
| */ | |
| class TestSpec extends Specification with ScalaCheckMatchers { def is = | |
| checkAll(MyProps) | |
| def checkAll(props: Properties)(implicit p: Parameters) = s2""" | |
| ${props.name} must satisfy | |
| ${ props.properties.map { case (name, prop) => | |
| s2""" ${name ! check(prop)(p)} """ | |
| }.reduce(_ append _) | |
| }""" | |
| } | |
| import org.scalacheck.Prop._ | |
| object MyProps extends Properties("MyProps") { | |
| property("myProp1") = forAll { (n:Int, m:Int) => | |
| n+m == m+n | |
| } | |
| property("myProp2") = forAll { (n:Int, m:Int) => | |
| n+m == m+n | |
| } | |
| property("myProp3") = (0/1) throws classOf[ArithmeticException] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment