In F#, I have a record with a few fields:
type myRecord = { a:float; b:float; c:float }
I am using FsCheck to test some properties which use this record.
For (a contrived) example,
let verify_this_property (r:myRecord) = myFunction(r) = (r.a * r.b) / r.c
Due to the internal implementation restrictions of myFunction, I would like to have FsCheck create test cases in which each of the fields a,b,c are restricted to non-negative floats.
I suspect this requires creating a generator for myRecord, but I have not been able to find any examples of how to do this.
Can anyone supply guidance?
Try this:
The
<!>is an infixmap, useful for applicative style. This is an equivalent generator:If you don’t want to globally register your generator, you can use
forAll:Shrinking left as an exercise 😉