2024 Clojure 状态调查! 分享您的想法。

欢迎!请参见 关于 页面以获取更多关于如何使用本站的信息。

0
ClojureScript
以下测试安排,确保将项目 conj 到持久队列中会使该项目成为队列中的最后一个


(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 失败,并且从错误报告中可以看出,该项目在队列中是在前面的。以下是一个示例


[{: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
...