请在 2024 状态 Clojure 问卷调查! 中分享您的想法。

欢迎!请参阅 关于 页面以获取更多关于如何使用此功能的信息。

0
ClojureScript
以下安排以测试在持久队列上添加一个项目会导致该项目成为队列的最后项目。


(require '[clojure.spec.alpha :as s]
         '[clojure.spec.gen.alpha :as gen]
         '[clojure.spec.test.alpha :as st]
         '[clojure.test.check]
         '[clojure.test.check.properties])

(s/def ::int-queue (s/coll-of int?
                              :gen #(gen/fmap
                                      (fn [x] (into #?(:cljs #queue [] :clj clojure.lang.PersistentQueue/EMPTY) x))
                                      (s/gen (s/coll-of int? :gen-max 5)))))

(defn enqueue [int-queue n]
  (conj int-queue n))

(s/fdef enqueue
        :args (s/cat :int-queue ::int-queue :n int?)
        :ret ::int-queue
        :fn #(= (last (:ret %)) (:n (:args %))))

(st/check `enqueue)


在 Clojure 中运行此代码正常。在 ClojureScript 1.10.520 中您将得到一个规格失败,从错误报告中可以看出,该项目位于队列的前端。以下是一个示例


[{:spec #object[cljs.spec.alpha.t_cljs$spec$alpha3986], :clojure.spec.test.check/ret
{:shrunk {:total-nodes-visited 4, :depth 1, :pass? false, :result #error
{:message "基于规格的检查失败", :data {:cljs.spec.alpha/problems
[{:path [:fn], :pred (cljs.core/fn [%] (cljs.core/= (cljs.core/last (:ret %))
(:n (:args %)))), :val {:args {:int-queue (0), :n -1}, :ret (-1 0)}, :via [], :in []}],
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha3687],
:cljs.spec.alpha/value {:args {:int-queue (0), :n -1}, :ret (-1 0)},
:cljs.spec.test.alpha/args (#queue [0] -1), :cljs.spec.test.alpha/val
{:args {:int-queue (0), :n -1}, :ret (-1 0)}, :cljs.spec.alpha/failure :check-failed}},
:result-data #:clojure.test.check.properties{:error #error {:message
"基于规格的检查失败", :data {:cljs.spec.alpha/problems [{:path [:fn],
:pred (cljs.core/fn [%] (cljs.core/= (cljs.core/last (:ret %)) (:n (:args %)))),
:val {:args {:int-queue (0), :n -1}, :ret (-1 0)}, :via [], :in []}],
 :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha3687],
:cljs.spec.alpha/value {:args {:int-queue (0), :n -1}, :ret (-1 0)},
:cljs.spec.test.alpha/args (#queue [0] -1), :cljs.spec.test.alpha/val
{:args {:int-queue (0), :n -1}, :ret (-1 0)}, :cljs.spec.alpha/failure :check-failed}}},
:time-shrinking-ms 4, :smallest [(#queue [0] -1)]}, :failed-after-ms 4,
:num-tests 2, :seed 1552588512350, :fail [(#queue [0 0] -1)], :result #error
{:message "基于规格的检查失败", :data {:cljs.spec.alpha/problems
[{:path [:fn], :pred (cljs.core/fn [%] (cljs.core/= (cljs.core/last (:ret %))
(:n (:args %)))), :val {:args {:int-queue (0 0), :n -1}, :ret (-1 0 0)}, :via [], :in []}],
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha3687],
:cljs.spec.alpha/value {:args {:int-queue (0 0), :n -1}, :ret (-1 0 0)},
 :cljs.spec.test.alpha/args (#queue [0 0] -1), :cljs.spec.test.alpha/val {:args
{:int-queue (0 0), :n -1}, :ret (-1 0 0)}, :cljs.spec.alpha/failure :check-failed}},
:result-data #:clojure.test.check.properties{:error #error {:message
"基于规格的检查失败", :data {:cljs.spec.alpha/problems [{:path [:fn],
:pred (cljs.core/fn [%] (cljs.core/= (cljs.core/last (:ret %)) (:n (:args %)))),
:val {:args {:int-queue (0 0), :n -1}, :ret (-1 0 0)}, :via [], :in []}],
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha3687],
:cljs.spec.alpha/value {:args {:int-queue (0 0), :n -1}, :ret (-1 0 0)},
:cljs.spec.test.alpha/args (#queue [0 0] -1), :cljs.spec.test.alpha/val {:args
{:int-queue (0 0), :n -1}, :ret (-1 0 0)}, :cljs.spec.alpha/failure :check-failed}}},
:failing-size 1, :pass? false}, :sym cljs.user/enqueue, :failure #error
{:message "基于规格的检查失败", :data {:cljs.spec.alpha/problems
[{:path [:fn], :pred (cljs.core/fn [%] (cljs.core/= (cljs.core/last (:ret %))
(:n (:args %)))), :val {:args {:int-queue (0), :n -1}, :ret (-1 0)}, :via [], :in []}],
:cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha3687],
:cljs.spec.alpha/value {:args {:int-queue (0), :n -1}, :ret (-1 0)},
:cljs.spec.test.alpha/args (#queue [0] -1), :cljs.spec.test.alpha/val {:args
{:int-queue (0), :n -1}, :ret (-1 0)}, :cljs.spec.alpha/failure :check-failed}}}]

1 答案

0
by
...