Reputation: 335
Probably a stupid question, but how do I generate a list of a specific size for FSCheck?
I can restrict using:
let fn_of_2_check xs = (xs.Length=2) ==> fn_of_2 xs
but, obviously, this will throw away loads of lists.
Here fn_of_2
does some test on lists of length 2
only and returns true
or false
.
Upvotes: 2
Views: 961
Reputation: 243051
A trivial solution would be to write a test that takes two inputs and builds a two-element list from them:
let fn_of_2_check x y = fn_of_2 [x; y]
However, if you're testing the function for two-elements list only, then perhaps the function should take a two-element tuple as the input. Or, you could write a test that verifies some behaviour for two-element lists and some other behaviour for lists of other length.
(But if you want to check the behaviour for two-element lists specifically, then the above should work.)
Upvotes: 2
Reputation: 99730
How about:
let listOfLength n = Gen.listOfLength n Arb.generate |> Arb.fromGen
Check.Quick (Prop.forAll (listOfLength 2) fn_of_2)
Upvotes: 6