aboutsummaryrefslogtreecommitdiff
path: root/src/clojure
diff options
context:
space:
mode:
authorFrantisek Sodomka <fsodomka@gmail.com>2009-05-18 18:48:30 +0000
committerFrantisek Sodomka <fsodomka@gmail.com>2009-05-18 18:48:30 +0000
commit3d791b3a84a0b248a476d53abe5528951af9c5b0 (patch)
tree7a4be0c34a91b71a5742228fa78e5a304471b6c0 /src/clojure
parente043c0fc73c392d2ef6127c5f7c695bbd1947169 (diff)
test-clojure: test-utils: all-are; data-structures: rewritten tests using all-are
Diffstat (limited to 'src/clojure')
-rw-r--r--src/clojure/contrib/test_clojure/data_structures.clj51
-rw-r--r--src/clojure/contrib/test_clojure/test_utils.clj15
2 files changed, 45 insertions, 21 deletions
diff --git a/src/clojure/contrib/test_clojure/data_structures.clj b/src/clojure/contrib/test_clojure/data_structures.clj
index bdf5578e..8dda7182 100644
--- a/src/clojure/contrib/test_clojure/data_structures.clj
+++ b/src/clojure/contrib/test_clojure/data_structures.clj
@@ -8,7 +8,9 @@
;;
(ns clojure.contrib.test-clojure.data-structures
- (:use clojure.contrib.test-is))
+ (:use clojure.contrib.test-is
+ [clojure.contrib.test-clojure.test-utils :only (all-are)]))
+
;; *** Helper functions ***
@@ -67,30 +69,37 @@
'(1) #{1}
[1] #{1} )
- ; sorted-map, hash-map and array-map - classes differ, but maps they are equal
- (is (not= (class (sorted-map :a 1)) (class (hash-map :a 1))))
- (is (not= (class (sorted-map :a 1)) (class (array-map :a 1))))
- (is (not= (class (hash-map :a 1)) (class (array-map :a 1))))
- (are (= _1 _2 _3)
- (sorted-map) (hash-map) (array-map)
- (sorted-map :a 1) (hash-map :a 1) (array-map :a 1)
- (sorted-map :a 1 :z 3 :c 2) (hash-map :a 1 :z 3 :c 2) (array-map :a 1 :z 3 :c 2))
+ ; 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))
; struct-map vs. sorted-map, hash-map and array-map
- (is (not= (class (struct equality-struct 1 2)) (class (sorted-map :a 1 :b 2))))
- (is (not= (class (struct equality-struct 1 2)) (class (hash-map :a 1 :b 2))))
- (is (not= (class (struct equality-struct 1 2)) (class (array-map :a 1 :b 2))))
- (are (= (struct equality-struct 1 2) _)
- (sorted-map :a 1 :b 2)
- (hash-map :a 1 :b 2)
- (array-map :a 1 :b 2) )
-
- ; sorted-set and hash-set are equal
+ (are (and (not= (class (struct equality-struct 1 2)) (class _))
+ (= (struct equality-struct 1 2) _))
+ (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)
- (sorted-set) (hash-set)
- (sorted-set 1) (hash-set 1)
- (sorted-set 3 2 1) (hash-set 3 2 1) ))
+ (sorted-set) (hash-set)
+ (sorted-set 1) (hash-set 1)
+ (sorted-set 3 2 1) (hash-set 3 2 1) ))
;; *** Collections ***
diff --git a/src/clojure/contrib/test_clojure/test_utils.clj b/src/clojure/contrib/test_clojure/test_utils.clj
index 6fe22161..fc858f2d 100644
--- a/src/clojure/contrib/test_clojure/test_utils.clj
+++ b/src/clojure/contrib/test_clojure/test_utils.clj
@@ -16,3 +16,18 @@
[]
(throw (new Exception "Exception which should never occur")))
+
+(defmacro all-are
+ "Test all-with-all.
+ (all-are (= _1 _2)
+ a b c)
+ =>
+ (do
+ (is (= a b))
+ (is (= a c))
+ (is (= b c)))"
+ [expr & args]
+ (concat
+ (list 'clojure.contrib.template/do-template (list 'clojure.contrib.test-is/is expr))
+ (apply concat (combinations args 2))))
+