test-check

2020-09-27T16:49:55.001100Z

Is it possible to make a vector generator that always generates X number of items but can shrink down to only 1 of those items?

2020-09-27T16:50:40.001400Z

What's the use case?

2020-09-27T16:52:17.002400Z

I have a test that has some expensive setup and I want to run the max items through it (each item of the vector) but still want to be able to get it to shrink to a single item if it fails

2020-09-27T16:53:57.003200Z

you can get approximately this behavior by modifying the size parameter that won't specifically guarantee large vectors, but it does express the idea of "I want to generate big inputs for whatever reason"

2020-09-27T16:54:43.003900Z

But will that affect the size of other gens or can I modify per-gen?

2020-09-27T16:57:25.006100Z

ummmmmmhm let's see something like

(defn gen-vector-with-shallow-min-size
  [min-size element-gen & other-args]
  (gen/sized (fn [size] (gen/scale #(min min-size %) (apply gen/vector (gen/resize size element-gen) other-args)))))

2020-09-27T16:57:42.006500Z

kind of hairy, but I believe that's what you're describing

2020-09-27T16:58:00.006900Z

again, doesn't guarantee any minimum number of elements, but it will skew the distribution larger

2020-09-27T16:58:37.007300Z

(which is intentional -- it's nice to still test empty/small vectors occasionally just in case)

2020-09-27T16:59:15.007600Z

Nice! Thanks! I’ll give it a shot!

👍 1