This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-02
Channels
- # adventofcode (286)
- # aws (3)
- # beginners (243)
- # calva (4)
- # cider (51)
- # cljs-dev (8)
- # clojure (74)
- # clojure-conj (1)
- # clojure-france (1)
- # clojure-italy (1)
- # clojure-spec (21)
- # clojure-uk (22)
- # clojurescript (25)
- # clojurex (6)
- # code-reviews (5)
- # core-async (3)
- # cursive (1)
- # defnpodcast (1)
- # fulcro (29)
- # mount (1)
- # off-topic (85)
- # onyx (5)
- # other-languages (7)
- # pathom (6)
- # pedestal (6)
- # re-frame (20)
- # reagent (2)
- # reitit (8)
- # ring-swagger (10)
- # shadow-cljs (53)
- # spacemacs (8)
- # tools-deps (34)
nice talk/announcement. really looking forward to it, especially the "Better programmatic manipulation of specs" part 🙂
Does anyone know why this is crazy slow / never terminates?
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as stest])
(defn my-reverse [c]
(reverse c))
(s/def ::reverse-args (s/cat :c (s/coll-of any?)))
(s/def ::reverse-ret (s/coll-of any?))
(s/exercise ::reverse-args)
(s/exercise ::reverse-ret)
(s/def ::reverse-fn
(fn [{:keys [args ret]}]
(let [input-c (:c args)]
(= input-c
(my-reverse ret)))))
(s/fdef my-reverse
:args ::reverse-args
:ret ::reverse-ret
:fn ::reverse-fn)
(stest/check `my-reverse)
oddly - if I swap out (s/coll-of any?)
for coll?
I see the same behaviour but if I use (s/coll-of integer?)
it terminates nearly instantly (and successfully)
any?
generates pretty hairy stuff
I didn’t try it, but I can tell that generating cases for (s/coll-of any?)
is going to cause test.check to really go crazy
And is generally not a good fit for generative testing
You might wanna customize the generator so the tests will be quick without changing the semantics of validation that your spec gives
It is, and I think you wanna keep any?
in your spec but customize the generator to improve the testing
That is an option too.
This is what I was talking about: (s/def ::reverse-ret (s/with-gen (s/coll-of any?) #(s/gen (s/coll-of int?))))