Delayed generators could make sense for recursive data structures. I'm wondering in which situation this Prop.delay
could be helpful. Could you please demonstrate a real life example.
Asked
Active
Viewed 61 times
2
1 Answers
2
I'm wondering in which situation this Prop.delay could be helpful. Could you please demonstrate a real life example.
Say you were writing extensions to your property-based test suite in Scalacheck, and wanted the user to build their properties, and your extension expects properties but shouldn't execute them right away.
Actually, Scalacheck uses the Prop.delay
construct properties internally to allow users to define tests with the Properties
trait/superclass.
class BadExample extends Properties("Bad example") {
property("divide by 0") = {
Prop.forAllNoShrink { x: Int =>
x / 0 == 0 // No!
}
}
}
This collects the properties so that they can be executed by a test runner (as an app or through sbt)
sealed class PropertySpecifier() {
def update(propName: String, p: => Prop) = {
props += ((name+"."+propName, Prop.delay(p)))
}
}
private val props = new scala.collection.mutable.ListBuffer[(String,Prop)]
lazy val property = new PropertySpecifier()

ashawley
- 4,195
- 1
- 27
- 40