diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2009-06-23 23:29:33 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2009-06-23 23:29:33 -0400 |
commit | 85c4905b3ccb94dfdb2272e92de6ba1051e304e3 (patch) | |
tree | e4760e28748b1ad88786cb5dab8a8941944ee095 /src/clojure/contrib/test_clojure | |
parent | 6ad3cf6dc28f738ba06ada5824e2be05559ea0f9 (diff) |
gtic: updated clojure tests to new template syntax, commented out
"all-are" tests
Diffstat (limited to 'src/clojure/contrib/test_clojure')
-rw-r--r-- | src/clojure/contrib/test_clojure/clojure_set.clj | 4 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/compilation.clj | 2 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/control.clj | 12 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/data_structures.clj | 116 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/java_interop.clj | 104 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/logic.clj | 16 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/numbers.clj | 42 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/other_functions.clj | 4 | ||||
-rw-r--r-- | src/clojure/contrib/test_clojure/sequences.clj | 106 |
9 files changed, 204 insertions, 202 deletions
diff --git a/src/clojure/contrib/test_clojure/clojure_set.clj b/src/clojure/contrib/test_clojure/clojure_set.clj index 33e9f2c3..3e698406 100644 --- a/src/clojure/contrib/test_clojure/clojure_set.clj +++ b/src/clojure/contrib/test_clojure/clojure_set.clj @@ -12,7 +12,7 @@ (deftest test-union - (are (= _1 _2) + (are [x y] (= x y) (set/union) #{} ; identity @@ -65,7 +65,7 @@ ; at least one argument is needed (is (thrown? IllegalArgumentException (set/intersection))) - (are (= _1 _2) + (are [x y] (= x y) ; identity (set/intersection #{}) #{} (set/intersection #{1}) #{1} diff --git a/src/clojure/contrib/test_clojure/compilation.clj b/src/clojure/contrib/test_clojure/compilation.clj index 8f7bad90..d3e59a7a 100644 --- a/src/clojure/contrib/test_clojure/compilation.clj +++ b/src/clojure/contrib/test_clojure/compilation.clj @@ -17,7 +17,7 @@ (deftest test-compiler-metadata (let [m ^#'when] - (are (= _1 _2) + (are [x y] (= x y) (list? (:arglists m)) true (> (count (:arglists m)) 0) true diff --git a/src/clojure/contrib/test_clojure/control.clj b/src/clojure/contrib/test_clojure/control.clj index 15542bf6..79bf93fb 100644 --- a/src/clojure/contrib/test_clojure/control.clj +++ b/src/clojure/contrib/test_clojure/control.clj @@ -16,7 +16,7 @@ ;; *** Helper functions *** (defn maintains-identity [f] - (are (= (f _) _) + (are [x] (= (f x) x) nil false true 0 42 @@ -37,7 +37,7 @@ ; http://clojure.org/macros (deftest test-do - (are (= _1 _2) + (are [x y] (= x y) ; no params => nil (do) nil @@ -65,7 +65,7 @@ (deftest test-cond - (are (= _1 _2) + (are [x y] (= x y) (cond) nil (cond nil true) nil @@ -76,11 +76,11 @@ (cond nil 1 false 2 true 3 true (exception)) 3 ) ; false - (are (= (cond _ :a true :b) :b) + (are [x] (= (cond x :a true :b) :b) nil false ) ; true - (are (= (cond _ :a true :b) :a) + (are [x] (= (cond x :a true :b) :a) true 0 42 0.0 3.14 @@ -96,7 +96,7 @@ #{} #{1 2} ) ; evaluation - (are (= _1 _2) + (are [x y] (= x y) (cond (> 3 2) (+ 1 2) true :result true (exception)) 3 (cond (< 3 2) (+ 1 2) true :result true (exception)) :result ) diff --git a/src/clojure/contrib/test_clojure/data_structures.clj b/src/clojure/contrib/test_clojure/data_structures.clj index 8dda7182..7ca8f4e6 100644 --- a/src/clojure/contrib/test_clojure/data_structures.clj +++ b/src/clojure/contrib/test_clojure/data_structures.clj @@ -24,7 +24,7 @@ (deftest test-equality ; nil is not equal to any other value - (are (not (= nil _)) + (are [x] (not (= nil x)) true false 0 0.0 \space @@ -47,7 +47,7 @@ (is (not= 2/3 0.6666666666666666)) ; vectors equal other seqs by items equality - (are (= _1 _2) + (are [x y] (= x y) '() [] ; regression fixed in r1208; was not equal '(1) [1] '(1 2) [1 2] @@ -58,7 +58,7 @@ (is (not= [1 2] '(2 1))) ; order of items matters ; list and vector vs. set and map - (are (not= _1 _2) + (are [x y] (not= x y) ; only () equals [] () #{} () {} @@ -70,33 +70,35 @@ [1] #{1} ) ; sorted-map, hash-map and array-map - classes differ, but content is equal - (all-are (not= (class _1) (class _2)) - (sorted-map :a 1) - (hash-map :a 1) - (array-map :a 1)) - (all-are (= _1 _2) - (sorted-map) - (hash-map) - (array-map)) - (all-are (= _1 _2) - (sorted-map :a 1) - (hash-map :a 1) - (array-map :a 1)) - (all-are (= _1 _2) - (sorted-map :a 1 :z 3 :c 2) - (hash-map :a 1 :z 3 :c 2) - (array-map :a 1 :z 3 :c 2)) + +;; TODO: reimplement all-are with new do-template? +;; (all-are (not= (class _1) (class _2)) +;; (sorted-map :a 1) +;; (hash-map :a 1) +;; (array-map :a 1)) +;; (all-are (= _1 _2) +;; (sorted-map) +;; (hash-map) +;; (array-map)) +;; (all-are (= _1 _2) +;; (sorted-map :a 1) +;; (hash-map :a 1) +;; (array-map :a 1)) +;; (all-are (= _1 _2) +;; (sorted-map :a 1 :z 3 :c 2) +;; (hash-map :a 1 :z 3 :c 2) +;; (array-map :a 1 :z 3 :c 2)) ; struct-map vs. sorted-map, hash-map and array-map - (are (and (not= (class (struct equality-struct 1 2)) (class _)) - (= (struct equality-struct 1 2) _)) + (are [x] (and (not= (class (struct equality-struct 1 2)) (class x)) + (= (struct equality-struct 1 2) x)) (sorted-map :a 1 :b 2) (hash-map :a 1 :b 2) (array-map :a 1 :b 2)) ; sorted-set vs. hash-set (is (not= (class (sorted-set 1)) (class (hash-set 1)))) - (are (= _1 _2) + (are [x y] (= x y) (sorted-set) (hash-set) (sorted-set 1) (hash-set 1) (sorted-set 3 2 1) (hash-set 3 2 1) )) @@ -105,7 +107,7 @@ ;; *** Collections *** (deftest test-count - (are (= _1 _2) + (are [x y] (= x y) (count nil) 0 (count ()) 0 @@ -141,7 +143,7 @@ (count (java.util.HashMap. {:a 1 :b 2 :c 3})) 3 ) ; different types - (are (= (count [_]) 1) + (are [x] (= (count [x]) 1) nil true false 0 0.0 "" \space () [] #{} {} )) @@ -152,7 +154,7 @@ (is (thrown? ClassCastException (conj "" \a))) (is (thrown? ClassCastException (conj (into-array []) 1))) - (are (= _1 _2) + (are [x y] (= x y) (conj nil 1) '(1) (conj nil 3 2 1) '(1 2 3) @@ -232,7 +234,7 @@ (is (thrown? ClassCastException (peek #{1}))) (is (thrown? ClassCastException (peek {:a 1}))) - (are (= _1 _2) + (are [x y] (= x y) (peek nil) nil ; list = first @@ -269,7 +271,7 @@ (is (thrown? IllegalStateException (pop ()))) (is (thrown? IllegalStateException (pop []))) - (are (= _1 _2) + (are [x y] (= x y) (pop nil) nil ; list - pop first @@ -298,18 +300,18 @@ ;; *** Lists (IPersistentList) *** (deftest test-list - (are (list? _) + (are [x] (list? x) () '() (list) (list 1 2 3) ) ; order is important - (are (not (= _1 _2)) + (are [x y] (not (= x y)) (list 1 2) (list 2 1) (list 3 1 2) (list 1 2 3) ) - (are (= _1 _2) + (are [x y] (= x y) '() () (list) '() (list 1) '(1) @@ -343,7 +345,7 @@ ;; *** Maps (IPersistentMap) *** (deftest test-find - (are (= _1 _2) + (are [x y] (= x y) (find {} :a) nil (find {:a 1} :a) [:a 1] @@ -360,7 +362,7 @@ (deftest test-contains? ; contains? is designed to work preferably on maps and sets - (are (= _1 _2) + (are [x y] (= x y) (contains? {} :a) false (contains? {} nil) false @@ -388,7 +390,7 @@ ; numerically indexed collections (e.g. vectors and Java arrays) ; => test if the numeric key is WITHIN THE RANGE OF INDEXES - (are (= _1 _2) + (are [x y] (= x y) (contains? [] 0) false (contains? [] -1) false (contains? [] 1) false @@ -418,7 +420,7 @@ ; 'contains?' operates constant or logarithmic time, ; it WILL NOT perform a linear search for a value. - (are (= _ false) + (are [x] (= x false) (contains? '(1 2 3) 0) (contains? '(1 2 3) 1) (contains? '(1 2 3) 3) @@ -428,13 +430,13 @@ (deftest test-keys - (are (= _1 _2) ; other than map data structures + (are [x y] (= x y) ; other than map data structures (keys ()) nil (keys []) nil (keys #{}) nil (keys "") nil ) - (are (= _1 _2) + (are [x y] (= x y) ; (class {:a 1}) => clojure.lang.PersistentArrayMap (keys {}) nil (keys {:a 1}) '(:a) @@ -452,13 +454,13 @@ (deftest test-vals - (are (= _1 _2) ; other than map data structures + (are [x y] (= x y) ; other than map data structures (vals ()) nil (vals []) nil (vals #{}) nil (vals "") nil ) - (are (= _1 _2) + (are [x y] (= x y) ; (class {:a 1}) => clojure.lang.PersistentArrayMap (vals {}) nil (vals {:a 1}) '(1) @@ -476,7 +478,7 @@ (deftest test-key - (are (= (key (first (hash-map _ :value))) _) + (are [x] (= (key (first (hash-map x :value))) x) nil false true 0 42 @@ -494,7 +496,7 @@ (deftest test-val - (are (= (val (first (hash-map :key _))) _) + (are [x] (= (val (first (hash-map :key x))) x) nil false true 0 42 @@ -514,22 +516,22 @@ ;; *** Sets *** (deftest test-hash-set - (are (set? _) + (are [x] (set? x) #{} #{1 2} (hash-set) (hash-set 1 2) ) ; order isn't important - (are (= _1 _2) + (are [x y] (= x y) #{1 2} #{2 1} #{3 1 2} #{1 2 3} (hash-set 1 2) (hash-set 2 1) (hash-set 3 1 2) (hash-set 1 2 3) ) ; equal and unique - (are (and (= (hash-set _) #{_}) - (= (hash-set _ _) #{_})) + (are [x] (and (= (hash-set x) #{x}) + (= (hash-set x x) #{x})) nil false true 0 42 @@ -545,7 +547,7 @@ {} {:a 1 :b 2} #{} #{1 2} ) - (are (= _1 _2) + (are [x y] (= x y) ; equal classes (class #{}) (class (hash-set)) (class #{1 2}) (class (hash-set 1 2)) @@ -586,13 +588,13 @@ (is (thrown? ClassCastException (sorted-set '(1 2) [3 4]))) ; creates set? - (are (set? _) - (sorted-set) - (sorted-set 1 2) ) + (are [x] (set? x) + (sorted-set) + (sorted-set 1 2) ) ; equal and unique - (are (and (= (sorted-set _) #{_}) - (= (sorted-set _ _) (sorted-set _))) + (are [x] (and (= (sorted-set x) #{x}) + (= (sorted-set x x) (sorted-set x))) nil false true 0 42 @@ -613,7 +615,7 @@ (is (thrown? ClassCastException (sorted-set {:a 1 :b 2} {:a 1 :b 2}))) (is (thrown? ClassCastException (sorted-set #{1 2} #{1 2}))) - (are (= _1 _2) + (are [x y] (= x y) ; generating (sorted-set) #{} (sorted-set 1) #{1} @@ -631,7 +633,7 @@ (deftest test-set ; set? - (are (set? (set _)) + (are [x] (set? (set x)) () '(1 2) [] [1 2] #{} #{1 2} @@ -640,7 +642,7 @@ "" "abc" ) ; unique - (are (= (set [_ _]) #{_}) + (are [x] (= (set [x x]) #{x}) nil false true 0 42 @@ -657,7 +659,7 @@ #{} #{1 2} ) ; conversion - (are (= (set _1) _2) + (are [x y] (= (set x) y) () #{} '(1 2) #{1 2} @@ -684,7 +686,7 @@ (is (thrown? ClassCastException (disj {:a 1} :a))) ; identity - (are (= (disj _) _) + (are [x] (= (disj x) x) #{} #{1 2 3} ; different data types @@ -703,13 +705,13 @@ #{} #{1 2}} ) ; type identity - (are (= (class (disj _)) (class _)) + (are [x] (= (class (disj x)) (class x)) (hash-set) (hash-set 1 2) (sorted-set) (sorted-set 1 2) ) - (are (= _1 _2) + (are [x y] (= x y) (disj #{} :a) #{} (disj #{} :a :b) #{} diff --git a/src/clojure/contrib/test_clojure/java_interop.clj b/src/clojure/contrib/test_clojure/java_interop.clj index 62eec24e..8c040255 100644 --- a/src/clojure/contrib/test_clojure/java_interop.clj +++ b/src/clojure/contrib/test_clojure/java_interop.clj @@ -15,30 +15,30 @@ (deftest test-dot ; (.instanceMember instance args*) - (are (= _ "FRED") + (are [x] (= x "FRED") (.toUpperCase "fred") (. "fred" toUpperCase) (. "fred" (toUpperCase)) ) - (are (= _ true) + (are [x] (= x true) (.startsWith "abcde" "ab") (. "abcde" startsWith "ab") (. "abcde" (startsWith "ab")) ) ; (.instanceMember Classname args*) - (are (= _ "java.lang.String") + (are [x] (= x "java.lang.String") (.getName String) (. (identity String) getName) (. (identity String) (getName)) ) ; (Classname/staticMethod args*) - (are (= _ 7) + (are [x] (= x 7) (Math/abs -7) (. Math abs -7) (. Math (abs -7)) ) ; Classname/staticField - (are (= _ 2147483647) + (are [x] (= x 2147483647) Integer/MAX_VALUE (. Integer MAX_VALUE) )) @@ -52,32 +52,32 @@ (let [m (doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2))] - (are (= _1 _2) + (are [x y] (= x y) (class m) java.util.HashMap m {"a" 1 "b" 2} ))) (deftest test-new ; Integer - (are (and (= (class _1) _2) - (= _1 _3)) + (are [expr cls value] (and (= (class expr) cls) + (= expr value)) (new java.lang.Integer 42) java.lang.Integer 42 (java.lang.Integer. 123) java.lang.Integer 123 ) ; Date - (are (= (class _) java.util.Date) + (are [x] (= (class x) java.util.Date) (new java.util.Date) (java.util.Date.) )) (deftest test-instance? ; evaluation - (are (= _1 _2) + (are [x y] (= x y) (instance? java.lang.Integer (+ 1 2)) true (instance? java.lang.Long (+ 1 2)) false ) ; different types - (are (instance? _2 _1) + (are [type literal] (instance? literal type) 1 java.lang.Integer 1.0 java.lang.Double 1M java.math.BigDecimal @@ -85,7 +85,7 @@ "a" java.lang.String ) ; it is an int, nothing else - (are (= (instance? _1 42) _2) + (are [x y] (= (instance? x 42) y) java.lang.Integer true java.lang.Long false java.lang.Character false @@ -99,7 +99,7 @@ (deftest test-bean (let [b (bean java.awt.Color/black)] - (are (= _1 _2) + (are [x y] (= x y) (map? b) true (:red b) 0 @@ -117,14 +117,14 @@ (deftest test-bases - (are (= _1 _2) + (are [x y] (= x y) (bases java.lang.Math) (list java.lang.Object) (bases java.lang.Integer) (list java.lang.Number java.lang.Comparable) )) (deftest test-supers - (are (= _1 _2) + (are [x y] (= x y) (supers java.lang.Math) #{java.lang.Object} (supers java.lang.Integer) @@ -142,25 +142,25 @@ (is (= (class (first (~type-array [1 2]))) (class (~type 1)))) ; given size (and empty) - (are (and (= (alength (~type-array _)) _) - (= (vec (~type-array _)) (repeat _ 0))) + (are [x] (and (= (alength (~type-array x)) x) + (= (vec (~type-array x)) (repeat x 0))) 0 1 5 ) ; copy of a sequence - (are (and (= (alength (~type-array _)) (count _)) - (= (vec (~type-array _)) _)) + (are [x] (and (= (alength (~type-array x)) (count x)) + (= (vec (~type-array x)) x)) ;; [] ;; ERROR [1] [1 -2 3 0 5] ) ; given size and init-value - (are (and (= (alength (~type-array _ 42)) _) - (= (vec (~type-array _ 42)) (repeat _ 42))) + (are [x] (and (= (alength (~type-array x 42)) x) + (= (vec (~type-array x 42)) (repeat x 42))) 0 1 5 ) ; given size and init-seq - (are (and (= (alength (~type-array _1 _2)) _1) - (= (vec (~type-array _1 _2)) _3)) + (are [x y z] (and (= (alength (~type-array x y)) x) + (= (vec (~type-array x y)) z)) 0 [] [] 0 [1] [] 0 [1 2 3] [] @@ -180,11 +180,11 @@ ; separate test for exceptions (doesn't work with above macro...) (deftest test-type-array-exceptions - (are (thrown? NegativeArraySizeException _) - (int-array -1) - (long-array -1) - (float-array -1) - (double-array -1) )) + (are [x] (thrown? NegativeArraySizeException x) + (int-array -1) + (long-array -1) + (float-array -1) + (double-array -1) )) (deftest test-make-array @@ -192,19 +192,19 @@ (is (thrown? NegativeArraySizeException (make-array Integer -1))) ; one-dimensional - (are (= (alength (make-array Integer _)) _) + (are [x] (= (alength (make-array Integer x)) x) 0 1 5 ) (let [a (make-array Integer 5)] (aset a 3 42) - (are (= _1 _2) + (are [x y] (= x y) (aget a 3) 42 (class (aget a 3)) Integer )) ; multi-dimensional (let [a (make-array Integer 3 2 4)] (aset a 0 1 2 987) - (are (= _1 _2) + (are [x y] (= x y) (alength a) 3 (alength (first a)) 2 (alength (first (first a))) 4 @@ -216,7 +216,7 @@ (deftest test-to-array (let [v [1 "abc" :kw \c []] a (to-array v)] - (are (= _1 _2) + (are [x y] (= x y) ; length (alength a) (count v) @@ -229,8 +229,8 @@ (class (aget a 4)) (class (nth v 4)) )) ; different kinds of collections - (are (and (= (alength (to-array _)) (count _)) - (= (vec (to-array _)) (vec _))) + (are [x] (and (= (alength (to-array x)) (count x)) + (= (vec (to-array x)) (vec x))) () '(1 2) [] @@ -254,23 +254,23 @@ ; simple case (let [v [1 2 3 4 5] a (into-array v)] - (are (= _1 _2) + (are [x y] (= x y) (alength a) (count v) (vec a) v (class (first a)) (class (first v)) )) ; given type (let [a (into-array Integer/TYPE [(byte 2) (short 3) (int 4)])] - (are (= _ Integer) + (are [x] (= x Integer) (class (aget a 0)) (class (aget a 1)) (class (aget a 2)) )) ; different kinds of collections - (are (and (= (alength (into-array _)) (count _)) - (= (vec (into-array _)) (vec _)) - (= (alength (into-array Integer/TYPE _)) (count _)) - (= (vec (into-array Integer/TYPE _)) (vec _))) + (are [x] (and (= (alength (into-array x)) (count x)) + (= (vec (into-array x)) (vec x)) + (= (alength (into-array Integer/TYPE x)) (count x)) + (= (vec (into-array Integer/TYPE x)) (vec x))) () '(1 2) [] @@ -292,7 +292,7 @@ ; ragged array (let [v [[1] [2 3] [4 5 6]] a (to-array-2d v)] - (are (= _1 _2) + (are [x y] (= x y) (alength a) (count v) (alength (aget a 0)) (count (nth v 0)) (alength (aget a 1)) (count (nth v 1)) @@ -304,13 +304,13 @@ ; empty array (let [a (to-array-2d [])] - (are (= _1 _2) + (are [x y] (= x y) (alength a) 0 (vec a) [] ))) (deftest test-alength - (are (= (alength _) 0) + (are [x] (= (alength x) 0) (int-array 0) (long-array 0) (float-array 0) @@ -320,7 +320,7 @@ (into-array []) (to-array-2d []) ) - (are (= (alength _) 1) + (are [x] (= (alength x) 1) (int-array 1) (long-array 1) (float-array 1) @@ -330,7 +330,7 @@ (into-array [1]) (to-array-2d [[1]]) ) - (are (= (alength _) 3) + (are [x] (= (alength x) 3) (int-array 3) (long-array 3) (float-array 3) @@ -343,8 +343,8 @@ (deftest test-aclone ; clone all arrays except 2D - (are (and (= (alength (aclone _)) (alength _)) - (= (vec (aclone _)) (vec _))) + (are [x] (and (= (alength (aclone x)) (alength x)) + (= (vec (aclone x)) (vec x))) (int-array 0) (long-array 0) (float-array 0) @@ -362,9 +362,9 @@ (into-array [1 2 3]) ) ; clone 2D - (are (and (= (alength (aclone _)) (alength _)) - (= (map alength (aclone _)) (map alength _)) - (= (map vec (aclone _)) (map vec _))) + (are [x] (and (= (alength (aclone x)) (alength x)) + (= (map alength (aclone x)) (map alength x)) + (= (map vec (aclone x)) (map vec x))) (to-array-2d []) (to-array-2d [[1] [2 3] [4 5 6]]) )) @@ -377,8 +377,8 @@ ; ints/longs/floats/doubles (deftest test-boolean - (are (and (instance? java.lang.Boolean (boolean _1)) - (= (boolean _1) _2)) + (are [x y] (and (instance? java.lang.Boolean (boolean x)) + (= (boolean x) y)) nil false false false true true diff --git a/src/clojure/contrib/test_clojure/logic.clj b/src/clojure/contrib/test_clojure/logic.clj index 40a94c37..6c46b711 100644 --- a/src/clojure/contrib/test_clojure/logic.clj +++ b/src/clojure/contrib/test_clojure/logic.clj @@ -17,7 +17,7 @@ (deftest test-if ; true/false/nil - (are (= _1 _2) + (are [x y] (= x y) (if true :t) :t (if true :t :f) :t (if true :t (exception)) :t @@ -31,7 +31,7 @@ (if nil (exception) :f) :f ) ; zero/empty is true - (are (= (if _ :t :f) :t) + (are [x] (= (if x :t :f) :t) (byte 0) (short 0) (int 0) @@ -53,7 +53,7 @@ (into-array []) ) ; anything except nil/false is true - (are (= (if _ :t :f) :t) + (are [x] (= (if x :t :f) :t) (byte 2) (short 2) (int 2) @@ -80,7 +80,7 @@ (deftest test-nil-punning - (are (= (if _1 :no :yes) _2) + (are [x y] (= (if x :no :yes) y) (first []) :yes (next [1]) :yes (rest [1]) :no @@ -111,7 +111,7 @@ (deftest test-and - (are (= _1 _2) + (are [x y] (= x y) (and) true (and true) true (and nil) nil @@ -130,7 +130,7 @@ (deftest test-or - (are (= _1 _2) + (are [x y] (= x y) (or) nil (or true) true (or nil) nil @@ -151,10 +151,10 @@ (deftest test-not (is (thrown? IllegalArgumentException (not))) - (are (= (not _) true) + (are [x] (= (not x) true) nil false ) - (are (= (not _) false) + (are [x] (= (not x) false) true ; numbers diff --git a/src/clojure/contrib/test_clojure/numbers.clj b/src/clojure/contrib/test_clojure/numbers.clj index 82450641..aa480d7c 100644 --- a/src/clojure/contrib/test_clojure/numbers.clj +++ b/src/clojure/contrib/test_clojure/numbers.clj @@ -23,7 +23,7 @@ (deftest Coerced-Byte (let [v (byte 3)] - (are _ + (are [x] (instance? Byte v) (number? v) (integer? v) @@ -31,7 +31,7 @@ (deftest Coerced-Short (let [v (short 3)] - (are _ + (are [x] (instance? Short v) (number? v) (integer? v) @@ -39,7 +39,7 @@ (deftest Coerced-Integer (let [v (int 3)] - (are _ + (are [x] (instance? Integer v) (number? v) (integer? v) @@ -47,7 +47,7 @@ (deftest Coerced-Long (let [v (long 3)] - (are _ + (are [x] (instance? Long v) (number? v) (integer? v) @@ -55,7 +55,7 @@ (deftest Coerced-BigInteger (let [v (bigint 3)] - (are _ + (are [x] (instance? BigInteger v) (number? v) (integer? v) @@ -63,21 +63,21 @@ (deftest Coerced-Float (let [v (float 3)] - (are _ + (are [x] (instance? Float v) (number? v) (float? v)))) (deftest Coerced-Double (let [v (double 3)] - (are _ + (are [x] (instance? Double v) (number? v) (float? v)))) (deftest Coerced-BigDecimal (let [v (bigdec 3)] - (are _ + (are [x] (instance? BigDecimal v) (number? v) (decimal? v) @@ -89,7 +89,7 @@ (defonce DELTA 1e-12) (deftest test-add - (are (= _1 _2) + (are [x y] (= x y) (+) 0 (+ 1) 1 (+ 1 2) 3 @@ -106,7 +106,7 @@ (+ 2/3 1) 5/3 (+ 2/3 1/3) 1 ) - (are (< (- _1 _2) DELTA) + (are [x y] (< (- x y) DELTA) (+ 1.2) 1.2 (+ 1.1 2.4) 3.5 (+ 1.1 2.2 3.3) 6.6 ) @@ -117,7 +117,7 @@ (deftest test-subtract (is (thrown? IllegalArgumentException (-))) - (are (= _1 _2) + (are [x y] (= x y) (- 1) -1 (- 1 2) -1 (- 1 2 3) -4 @@ -133,7 +133,7 @@ (- 2/3 1) -1/3 (- 2/3 1/3) 1/3 ) - (are (< (- _1 _2) DELTA) + (are [x y] (< (- x y) DELTA) (- 1.2) -1.2 (- 2.2 1.1) 1.1 (- 6.6 2.2 1.1) 3.3 ) @@ -142,7 +142,7 @@ (deftest test-multiply - (are (= _1 _2) + (are [x y] (= x y) (*) 1 (* 2) 2 (* 2 3) 6 @@ -156,7 +156,7 @@ (* 1/2 1/3) 1/6 (* 1/2 1/3 -1/4) -1/24 ) - (are (< (- _1 _2) DELTA) + (are [x y] (< (- x y) DELTA) (* 1.2) 1.2 (* 2.0 1.2) 2.4 (* 3.5 2.0 1.2) 8.4 ) @@ -165,7 +165,7 @@ (deftest test-divide - (are (= _1 _2) + (are [x y] (= x y) (/ 1) 1 (/ 2) 1/2 (/ 3 2) 3/2 @@ -179,7 +179,7 @@ (/ -4 -2) 2 (/ -4 2) -2 ) - (are (< (- _1 _2) DELTA) + (are [x y] (< (- x y) DELTA) (/ 4.5 3) 1.5 (/ 4.5 3.0 3.0) 0.5 ) @@ -208,7 +208,7 @@ (is (thrown? ArithmeticException (mod 9 0))) (is (thrown? ArithmeticException (mod 0 0))) - (are (= _1 _2) + (are [x y] (= x y) (mod 4 2) 0 (mod 3 2) 1 (mod 6 4) 2 @@ -258,7 +258,7 @@ (is (thrown? ArithmeticException (rem 9 0))) (is (thrown? ArithmeticException (rem 0 0))) - (are (= _1 _2) + (are [x y] (= x y) (rem 4 2) 0 (rem 3 2) 1 (rem 6 4) 2 @@ -305,7 +305,7 @@ (is (thrown? ArithmeticException (quot 9 0))) (is (thrown? ArithmeticException (quot 0 0))) - (are (= _1 _2) + (are [x y] (= x y) (quot 4 2) 2 (quot 3 2) 1 (quot 6 4) 1 @@ -369,7 +369,7 @@ ;; even? odd? (deftest test-even? - (are _ + (are [x] (even? -4) (not (even? -3)) (even? 0) @@ -379,7 +379,7 @@ (is (thrown? ArithmeticException (even? (double 10))))) (deftest test-odd? - (are _ + (are [x] (not (odd? -4)) (odd? -3) (not (odd? 0)) diff --git a/src/clojure/contrib/test_clojure/other_functions.clj b/src/clojure/contrib/test_clojure/other_functions.clj index 3138fbd9..17b1f3b8 100644 --- a/src/clojure/contrib/test_clojure/other_functions.clj +++ b/src/clojure/contrib/test_clojure/other_functions.clj @@ -19,7 +19,7 @@ (is (thrown? IllegalArgumentException (identity))) (is (thrown? IllegalArgumentException (identity 1 2))) - (are (= (identity _) _) + (are [x] (= (identity x) x) nil false true 0 42 @@ -36,7 +36,7 @@ #{} #{1 2} ) ; evaluation - (are (= (identity _1) _2) + (are [x y] (= (identity x) y) (+ 1 2) 3 (> 5 0) true )) diff --git a/src/clojure/contrib/test_clojure/sequences.clj b/src/clojure/contrib/test_clojure/sequences.clj index 7c2721b4..762e157a 100644 --- a/src/clojure/contrib/test_clojure/sequences.clj +++ b/src/clojure/contrib/test_clojure/sequences.clj @@ -20,7 +20,7 @@ (deftest test-equality ; lazy sequences - (are (= _1 _2) + (are [x y] (= x y) ; fixed SVN 1288 - LazySeq and EmptyList equals/equiv ; http://groups.google.com/group/clojure/browse_frm/thread/286d807be9cae2a5# (map inc nil) () @@ -31,12 +31,12 @@ (deftest test-lazy-seq - (are (seq? _) + (are [x] (seq? x) (lazy-seq nil) (lazy-seq []) (lazy-seq [1 2])) - (are (= _1 _2) + (are [x y] (= x y) (lazy-seq nil) () (lazy-seq [nil]) '(nil) @@ -59,7 +59,7 @@ (is (not (seq? (seq [])))) (is (seq? (seq [1 2]))) - (are (= _1 _2) + (are [x y] (= x y) (seq nil) nil (seq [nil]) '(nil) @@ -80,7 +80,7 @@ (deftest test-cons (is (thrown? IllegalArgumentException (cons 1 2))) - (are (= _1 _2) + (are [x y] (= x y) (cons 1 nil) '(1) (cons nil nil) '(nil) @@ -102,8 +102,8 @@ (deftest test-empty - (are (and (= (empty _1) _2) - (= (class (empty _1)) (class _2))) + (are [x y] (and (= (empty x) y) + (= (class (empty x)) (class y))) nil nil () () @@ -141,7 +141,7 @@ (deftest test-not-empty ; empty coll/seq => nil - (are (= (not-empty _) nil) + (are [x] (= (not-empty x) nil) () [] {} @@ -152,8 +152,8 @@ (lazy-seq []) ) ; non-empty coll/seq |