我正在尝试对这个简单的功能进行基于属性的测试:
(defn distinct-kw-keys
[maps]
(->> (map keys maps)
(flatten)
(filter keyword?)
(distinct)
(vec)))
...使用fdef
和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)
一段时间后调用test/check
终止OutOfMemoryError
:
Exception in thread "Timer-1" Error printing return value (OutOfMemoryError) at clojure.test.check.generators/choose$fn (generators.cljc:260). Java heap space
等等
我无法弄清楚这里有什么问题。功能和规格似乎工作正常,例如
(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