2
votes

How can I establish conditions on test inputs when performing Property-based testing?

For example, the following code generates bools when I need ints:

Gen.map (fun v -> v > 0) 

Here's the function:

[<Property(QuietOnSuccess = true)>]
let ``number of cells in grid equals rowcount squared`` () =
    let values = Arb.generate<int> |> Gen.map (fun v -> v > 0) 
                                   |> Arb.fromGen

I need something like this so that I can get qualifying ints:

Gen.filter (fun v -> v > 0) 

However, I just don't see an option for this.

Any suggestions?

1
Dude, I'm starting to get the hang of FSharp now. I'm still not on your level though. I took a two week break from coding and now I'm back.Scott Nimrod
Gen.where or Gen.suchThat?Mark Seemann
Of interest: FsCheck - GenGuy Coder

1 Answers

1
votes

Try Gen.suchThat (fun v -> v > 0)