Created
February 16, 2010 12:37
-
-
Save zahardzhan/305497 to your computer and use it in GitHub Desktop.
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
(use 'clojure.test) | |
(defn same | |
"Returns true if (f x) returns same value for any x in coll." | |
[f coll] | |
(apply = (map f coll))) | |
(deftest same-test | |
(is (same :x [{:x nil} {:y nil}])) | |
(is (same :x [{:x 1} {:x 1 :y 2}])) | |
(is (not (same :x [{:x 1} {:x 2}]))) | |
(is (same 0 [[1 2 3] [1 3 2]])) | |
(is (same (comp not nil? #{:x :y}) [:x :y])) | |
(is (not (same (comp not nil? #{:x :y}) [:x :y :z]))) | |
(is (same (partial identical? 1) [1 1 1 1])) | |
(is (not (same (partial identical? 1) [1 1 1 2]))) | |
(is (same type [1 2 3])) | |
(is (not (same type [1 2 1/2]))) | |
(is (same true [true true (= 2 2)])) | |
(is (not (same nil? [nil nil false])))) | |
(same-test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment