In ScalaCheck it seems that a mapped/flatMapped Gen
will fail as soon as any inner gen has a value filtered out. E.g. (using ScalaTest)
class ScalaCheckGen extends FreeSpec with GeneratorDrivenPropertyChecks {
"Fails" in {
forAll(Gen.listOfN(100, arbitrary[Int].suchThat(_ % 2 == 0))){
_ => assert(true)}
//Gave up after 0 successful property evaluations. 51 evaluations were discarded.
}
"Passes" in {
forAll(Gen.listOfN(100, arbitrary[Int].map(_ * 2))){
_ => assert(true)}
}
}
Suppose the trivial workaround above didn't work because the suchThat
condition was complex. How could this be rewritten to work while still using a suchThat
?