假设您有 a::givee
和 a ::giver
:
(s/def ::givee keyword?)
(s/def ::giver keyword?)
那形成一个unq/gift-pair
:
(s/def :unq/gift-pair (s/keys :req-un [::givee ::giver]))
然后你有一个:unq/gift-history
which is a vector
of unq/gift-pair
:
(s/def :unq/gift-history (s/coll-of :unq/gift-pair :kind vector?))
最后,假设您要替换其中的:unq/gift-pair
一个vector
:
(defn set-gift-pair-in-gift-history [g-hist g-year g-pair]
(assoc g-hist g-year g-pair))
(s/fdef set-gift-pair-in-gift-history
:args (s/and (s/cat :g-hist :unq/gift-history
:g-year int?
:g-pair :unq/gift-pair)
#(< (:g-year %) (count (:g-hist %)))
#(> (:g-year %) -1))
:ret :unq/gift-history)
一切正常:
(s/conform :unq/gift-history
(set-gift-pair-in-gift-history [{:givee :me, :giver :you} {:givee :him, :giver :her}] 1 {:givee :dog, :giver :cat}))
=> [{:givee :me, :giver :you} {:givee :dog, :giver :cat}]
直到我尝试stest/check
它:
(stest/check `set-gift-pair-in-gift-history)
clojure.lang.ExceptionInfo: Couldn't satisfy such-that predicate after 100 tries.
java.util.concurrent.ExecutionException: clojure.lang.ExceptionInfo: Couldn't satisfy such-that predicate after 100 tries. {}
我曾尝试使用s/int-in
限制向量计数(认为这可能是问题)但没有成功。
关于如何(stest/check `set-gift-pair-in-gift-history)
正确运行的任何想法?
谢谢你。