stedolan / crowbar

Property fuzzing for OCaml
MIT License
180 stars 31 forks source link

Length of lists #70

Open lindig opened 1 year ago

lindig commented 1 year ago

I have noticed that lists generated by list are short and I found no easy way to control their length. Should list not take a generator as argument for the length? This would make it easy to plug range or const for the length. Otherwise I would suggest to solve this problem in one of the examples.

nikhil-kamath commented 7 months ago

Looks like this is an inherent bug to the way size is dealt with throughout crowbar: looking at this line shows that the size begins hard coded at 100, making it impossible to actually dynamically generate longer lists.

i think if you use list right now, the maximum size you'll get is 6 (due to size scaling by -50% in the list gen). this alternative allows the maximum size to go up to 33 by making the size scaling -3 from the dynamic_bind generator instead:

let listn (g : 'a gen) : 'a list gen =
  fix (fun listn ->
      dynamic_bind (range 15) (fun n ->
          if n = 0 then const []
          else
            dynamic_bind g (fun x ->
                dynamic_bind listn (fun xs -> const (x :: xs)))))