这是我的clojure函数,试图重现filter
函数:
(defn singleton? [coll]
(= 1 (count coll)))
(defn my-filter [pred? a-seq]
(if (singleton? a-seq)
(if (pred? (first a-seq))
a-seq)
(if (pred? (first a-seq))
(cons (first a-seq) (my-filter pred? (rest a-seq)))
(my-filter pred? (rest a-seq)))))
我的中间测试是:
(my-filter false? [1 2 3]) => empty? (actual return value is 'nil')
(my-filter even? [1 3 5 7]) => empty? (actual return value is 'nil')
当我运行midje时,我收到错误消息:
FAIL "my-filter" at (recursion.clj:54)
Actual result did not agree with the checking function.
Actual result: nil
Checking function: empty?
FAIL "my-filter" at (recursion.clj:57)
Actual result did not agree with the checking function.
Actual result: nil
Checking function: empty?
我很困惑,因为当我跑步时:
(empty? nil)
在repl中,我得到'真'。
为什么midje未通过此测试?