Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 为什么中捷测试失败?_Clojure - Fatal编程技术网

Clojure 为什么中捷测试失败?

Clojure 为什么中捷测试失败?,clojure,Clojure,下面是我的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? (

下面是我的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)))))
我的midje测试是:

(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)
在回答中,我得到了“真”


为什么midje没有通过这个测试?

你知道解构吗?我认为您可以稍微清理一下您的实现。我只是在本地运行这个,它对我有用。您使用的Clojure/Lein/Midje的版本是什么?我使用的是Java 1.7.051Java HotSpotTM 64位服务器上的Leiningen 2.3.4,OSX上的VM不知道如何检查Clojure版本。此外,我也在关注——我们确实进行了分解,但没有使用“when”等。尽管如此,我将对其进行重构,因为分解是一个好主意。谢谢。在你的project.clj中,你应该看到一个dependencies关键字。检查那里的clojure版本。例如,依赖项[[org.clojure/clojure 1.6.0][org.clojure/math.combinations 0.0.7][org.clojure/math.numeric-tower 0.0.4]]它是defproject递归1.0.0-SNAPSHOT:dependencies[[org.clojure/clojure 1.5.1][iloveponies.tests/recursion 0.1.0-SNAPSHOT]]:profiles{:dev{:plugins[[lein midje 3.1.1]]}