Is size value used for a Gen's sample taking a custom generator?

73 Views Asked by At

I'm generating custom data using FsCheck's Gen.

Suppose you have a function returning Gen<'T>:

let chooseRectangle widthMax heightMax offset =
   gen {
       let! left = Gen.choose(0, widthMax-offset)
       let! top = Gen.choose(0, heightMax-offset)
       let! width = Gen.choose(offset, widthMax-left)
       let! height = Gen.choose(offset, heightMax-top)
       return { Left=left
                Top=top
                Width=width
                Height=height
               }
   }

which is then used for generating data:

Gen.sample 0 10 (chooseRectangle 400 200 10)

is the size argument (first one) used in this case and does it influence the value repartition?

1

There are 1 best solutions below

1
On BEST ANSWER

No, not in your case, as far as I can tell.

That first argument is size. sample threads it through into the generator you call it with, but what that generator does with it is up to that particular implementation. For sequence generators it may for instance control the length of the sequence.

Your generator however is solely built on top of Gen.choose, which explicitly ignores it:

let choose (l, h) = Gen (fun _ r -> range (l,h) r |> fst) 

where size is the _ argument. See here.