对于 Clojure 新手来说,我可能最简单的测试失败了,并出现了一条相当令人困惑的消息。
(ns leiningen.booltest
(:use clojure.test))
(with-test
(defn bool-function []
(true))
(is (= (bool-function) true))
)
ERROR in (bool-function) (booltest.clj:10)
expected: (= (bool-function) true)
actual: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn
最佳答案
您正在将 true 作为函数调用:with-test
表达式第 3 行的 (true)
。它应该只是 true
,不带括号。
您可以进一步简化表达式,因为 bool-function
已经返回 true
:
(with-test
(defn bool-function []
true)
(is (bool-function)))
关于clojure - 测试返回 bool 值的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025490/