I'm trying to do property-based testing for this simple function:
(defn distinct-kw-keys
[maps]
(->> (map keys maps)
(flatten)
(filter keyword?)
(distinct)
(vec)))
... using fdef
and check
:
(require '[clojure.spec.alpha :as s]
'[clojure.spec.test.alpha :as test])
(s/fdef distinct-kw-keys
:args (s/cat :maps (s/coll-of map?))
:ret (s/coll-of keyword?
:kind vector?
:distinct true))
(test/check `distinct-kw-keys)
Calling test/check
terminates after a while throwing OutOfMemoryError
:
Exception in thread "Timer-1" Error printing return value (OutOfMemoryError) at clojure.test.check.generators/choose$fn (generators.cljc:260). Java heap space
etc.
I can't figure out what's the problem here. Function and specs seem to work fine, e.g.
(require '[clojure.spec.gen.alpha :as gen])
(s/valid?
(s/coll-of keyword?
:kind vector?
:distinct true)
(distinct-kw-keys
(gen/generate
(s/gen
(s/coll-of map?))))) ;; => true