假设你有一个
::givee
以及
::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
这是一个
vector
属于
UNQ/礼品对
以下内容:
(s/def :unq/gift-history (s/coll-of :unq/gift-pair :kind vector?))
最后,假设您要替换
:unq/gift-pair
在
矢量
:
(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)
正确地?
谢谢您。