Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
The following arranges to test that conjing an item onto a persistent queue results in that item being last in the queue:


(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)


Running this in Clojure works fine. In ClojureScript 1.10.520 you'll get a spec failure and it appears from the error report, the item is at the front of the queue. Here is an example:


[{: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 "Specification-based check failed", :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
"Specification-based check failed", :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 "Specification-based check failed", :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
"Specification-based check failed", :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 "Specification-based check failed", :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 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-3060 (reported by mfikes)
...