0

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?

Pengin
  • 4,692
  • 6
  • 36
  • 62

1 Answers1

0

Replace suchThat with retryUntil, but beware of infinite loops.

Pengin
  • 4,692
  • 6
  • 36
  • 62