Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure规范和;不能';t在100次尝试后满足该谓词……”;_Clojure_Clojure.spec - Fatal编程技术网

Clojure规范和;不能';t在100次尝试后满足该谓词……”;

Clojure规范和;不能';t在100次尝试后满足该谓词……”;,clojure,clojure.spec,Clojure,Clojure.spec,假设您有一个::give和a::giver: (s/def ::givee keyword?) (s/def ::giver keyword?) 形成一对unq/礼品: (s/def :unq/gift-pair (s/keys :req-un [::givee ::giver])) (s/def :unq/gift-history (s/coll-of :unq/gift-pair :kind vector?)) 然后你有一个:unq/礼物历史,它是unq/礼物对的向量: (s/def

假设您有一个
::give
和a
::giver

(s/def ::givee keyword?)
(s/def ::giver keyword?)
形成一对unq/礼品:

(s/def :unq/gift-pair (s/keys :req-un [::givee ::giver]))
(s/def :unq/gift-history (s/coll-of :unq/gift-pair :kind vector?))
然后你有一个
:unq/礼物历史
,它是
unq/礼物对的
向量

(s/def :unq/gift-pair (s/keys :req-un [::givee ::giver]))
(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)
在我尝试
stest/check
it之前:

(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来限制向量计数(认为这可能是问题所在),但没有成功

有没有关于如何正确运行
(stest/check `在礼品历史记录中设置礼品对)
的想法


谢谢。

问题在于向量的生成器和集合中的索引是独立的/不相关的。随机向量和整数不满足以下条件:

#(< (:g-year %) (count (:g-hist %)))
#(> (:g-year %) -1)

这是使用test.check的
let
宏,它比
bind
/
fmap
更方便,允许您使用看起来像常规
let
的代码组合/合成生成器。自定义生成器将参数向量返回给函数。

谢谢。成功这是你第三次在规格问题上帮助我。我可以在环路里和你碰头给你买杯啤酒吗?咖啡/甜甜圈?:-)哈哈,我要三个,平我:)当然-告诉我怎么做?检查这里,你的博客,GitHub和Chicago Clojure的电子邮件?:-)埃里克·托宾