This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-27
Channels
- # announcements (1)
- # babashka (7)
- # beginners (60)
- # calva (24)
- # cider (2)
- # cljdoc (9)
- # clojure (21)
- # clojure-australia (1)
- # clojure-europe (2)
- # clojurescript (26)
- # core-async (89)
- # datalog (11)
- # datomic (40)
- # fulcro (24)
- # graalvm (5)
- # luminus (1)
- # meander (1)
- # numerical-computing (1)
- # off-topic (3)
- # shadow-cljs (6)
- # test-check (10)
- # tools-deps (7)
- # xtdb (18)
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"
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)