Fork me on GitHub
#clojure-spec
<
2019-04-15
>
Jakub Holý (HolyJak)06:04:27

Given a spec, how can I generate random value(s)? Does spec.gen/generate take a spec or is there another fn? Thank you!

jaihindhreddy07:04:40

clojure.spec.alpha/gen takes a spec and returns a generator for it. clojure.spec.gen.alpha/sample takes a generator and gives you a few examples. Takes an optional number of examples to generate clojure.spec.alpha/exercise takes a spec and gives you a seq of pairs, each containing generated example value, and the same value conformed. Check out their docstrings. Also, it's highly recommended to read the Spec guide in its entirety (https://clojure.org/guides/spec) It clears a lot of these things up (including potential gotchas like you need to include test.check for some of the functionality to work)

❤️ 4