1
我一直在用另一種語言重新實現一些Clojure函數,使用測試引用,我有點困惑於the tests的clojure.core/comp
。測試Clojure的comp函數
(deftest test-comp
(let [c0 (comp)]
(are [x] (= (identity x) (c0 x))
nil
42
[1 2 3]
#{}
:foo)
(are [x y] (= (identity x) (c0 y))
(+ 1 2 3) 6
(keyword "foo") :foo)))
comp
本身只使用一次,沒有參數。該行爲似乎沒有記錄,但the source顯示它只是返回identity
函數。
(defn comp
([] identity)
([f] f)
([f g]
(fn
([] (f (g)))
([x] (f (g x)))
([x y] (f (g x y)))
([x y z] (f (g x y z)))
([x y z & args] (f (apply g x y z args)))))
([f g & fs]
(reduce1 comp (list* f g fs))))
這是否意味着3/4這些寶石沒有經過測試?還是有測試保存在其他地方?我通過GitHub搜索發現了這些測試,它們並不總是完全可靠。
爲什麼zero arity表單有測試,看起來是最不實用的變體?
不太理解第二點。任何機會,你可以添加一個簡單的例子? –
@DanPrince更新了答案,HTH – Davyzhu