Homework time!
def forAll[A](as: Gen[A])(f: A => Boolean): Prop = Prop { (n,rng) => randomStream(as)(rng).zip(Stream.from(0)).take(n).map { case (a, i) => try { if (f(a)) Passed else Falsified(a.toString, i) } catch { case e: Exception => Falsified(buildMsg(a, e), i) } }.find(_.isFalsified).getOrElse(Passed) }
def forAll[A](g: SGen[A])(f: A => Boolean): Prop = Prop { (max,n,rng) => val casesPerSize = (n - 1) / max + 1 val props: Stream[Prop] = Stream.from(0).take((n min max) + 1).map(i => forAll(g(i))(f)) val prop: Prop = props.map(p => Prop { (max, _, rng) => p.run(max, casesPerSize, rng) }).toList.reduce(_ && _) prop.run(max,n,rng) }
Homework time!