我有以下代码,我正在尝试使用path-and-subpath
生成器为(s/fdef conj-set ...)
创建值。
(def path (s/coll-of (s/with-gen string? #(s/gen #{"a" "b" "c" "d"}))
:min-count 1
:kind vector?
:into []))
(s/def ::path
(s/with-gen
path
(fn [] (gen/fmap #(vec (take 5 %)) (s/gen path)))))
;; GENERATES THE TUPLES OF PATH AND SUB-PATH
(def path-and-subpath
(->
::path
s/gen
(gen/bind
(fn [xs]
(gen/tuple
(gen/return xs)
(->> xs count inc (s/int-in 1) s/gen))))
(gen/bind
(fn [[xs i]]
(gen/tuple
(gen/return xs)
(gen/return (subvec xs 0 i)))))))
(s/fdef conj-set
:args (s/and
(s/cat :path <FIRST_VALUE_IN_GENERATED_TUPLE>
:sub-path <SECOND_VALUE_IN_GENERTED_TUPLE>)
#(= (-> % :args :sub-path)
(->> % :args :full-path (take (-> % :args :sub-path count))))))
我不知道如何将这两件事放在一起。我有一个生成元组的生成器,我有一个fdef
具有我想要指定的依赖参数。如何将它们结合起来?