Created
July 6, 2014 23:23
-
-
Save koddsson/d41acc0ed7c8a5b3de70 to your computer and use it in GitHub Desktop.
Running into problems with Clojure return types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.koddsson.for-clojure | |
(:use [clojure.test :only [is deftest run-tests]])) | |
(defn my-flatten | |
([x] (if (not (and (seq? x) (vector? x))) | |
x ; If x is not a sequence nor a vector | |
(map my-flatten x)))) ; else recursivly apply the flatten function | |
(deftest test28 | |
(is (= (my-flatten '((1 2) 3 [4 [5 6]])) '(1 2 3 4 5 6))) | |
(is (= (my-flatten ["a" ["b"] "c"]) '("a" "b" "c"))) | |
(is (= (my-flatten '((((:a))))) '(:a)))) | |
(run-tests) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ bubblegum 20 → λ git master* → lein exec -p 28.clj | |
Testing com.koddsson.for-clojure | |
FAIL in (test28) (28.clj:10) | |
expected: (= (my-flatten (quote ((1 2) 3 [4 [5 6]]))) (quote (1 2 3 4 5 6))) | |
actual: (not (= ((1 2) 3 [4 [5 6]]) (1 2 3 4 5 6))) | |
FAIL in (test28) (28.clj:11) | |
expected: (= (my-flatten ["a" ["b"] "c"]) (quote ("a" "b" "c"))) | |
actual: (not (= ["a" ["b"] "c"] ("a" "b" "c"))) | |
FAIL in (test28) (28.clj:12) | |
expected: (= (my-flatten (quote ((((:a)))))) (quote (:a))) | |
actual: (not (= ((((:a)))) (:a))) | |
Ran 1 tests containing 3 assertions. | |
3 failures, 0 errors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this: