Skip to content

Instantly share code, notes, and snippets.

@zahardzhan
Created February 16, 2010 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zahardzhan/305497 to your computer and use it in GitHub Desktop.
Save zahardzhan/305497 to your computer and use it in GitHub Desktop.
(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