This link explains the generator, but does not specify exactly how to use it. I am not sure how to test the contents of the list generated by the generator.
I would like the following code. (forall is an imaginary function.)
open FsCheck
open FsCheck.Xunit
let isZero x = (x = 0)
let Zeros = Gen.constant 0 |> Gen.sample 0 100
[<Property>]
let TestSample =
forall isZero Zeros
I agree that this can be confusing. It's simplest to define a custom type and then create a generator for it:
The
Zerotype has a generator that creates zero values. TheTestSampleproperty then confirms that every element of an arbitrary list of zeros is indeed zero. FsCheck will automatically generate lists of various sizes to confirm this. You can run withVerbose = trueto see them if you want.Since you want to use Xunit properties, you have to register the generator, as described here.
As the documentation mentions, you shouldn't use
Gen.samplewhen writing properties.