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?
What's the use case?
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
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"
But will that affect the size of other gens or can I modify per-gen?
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)))))
kind of hairy, but I believe that's what you're describing
again, doesn't guarantee any minimum number of elements, but it will skew the distribution larger
(which is intentional -- it's nice to still test empty/small vectors occasionally just in case)
Nice! Thanks! I’ll give it a shot!