typelevel / scalacheck

Property-based testing for Scala
http://www.scalacheck.org
BSD 3-Clause "New" or "Revised" License
1.94k stars 407 forks source link

Suggestion: add method to define a flat list of classify conditions to collect statistics on Prop #566

Open dabd opened 5 years ago

dabd commented 5 years ago

When defining multiple classify conditions to collect statistics on a property, the currently available classify methods on Prop require nesting each classify call resulting in deeply nested code. A method that accepts a flat list of classify conditions would make it more pleasant to use. Something like (using Stream so we don't evaluate all conditions prematurely):

  @scala.annotation.tailrec
  def classify(conditions: Stream[(Boolean, Any, Any)])(prop: Prop): Prop = conditions match {
    case Stream.Empty => prop
    case h #:: Stream.Empty =>
      if (h._1) collect(h._2)(prop) else collect(h._3)(prop)
    case h #:: t =>
      classify(t)(Prop.classify(h._1, h._2, h._3)(prop))
  }
non commented 5 years ago

@dabd I haven't dug into the classification code much, so I'll need some time to think about it. Thanks for suggesting this.

dabd commented 5 years ago

@non In your talk about scalacheck you mention in one of the slides that we should pay attention to the distribution and range of generators. It would be useful to have tools to look at test case distribution on par with Haskell's QuickCheck tools such as cover and similar. checkCoverage looks useful as a better stopping criteria than choosing an arbitrary minSuccessfulTests.