aboutsummaryrefslogtreecommitdiff
path: root/src/test/clojure/clojure/contrib
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-05-05 09:32:59 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-05-05 09:32:59 -0400
commit95dddbbdd748b0cc6d9c8486b8388836e6418848 (patch)
tree5c852b3a71a45408b015c350ef5fdba66320fc4c /src/test/clojure/clojure/contrib
parent48b81e07256c697c23a1aff896596300e7d0115b (diff)
keep deprecated version of seq fns, safe(r) now that we have "last var wins"
Diffstat (limited to 'src/test/clojure/clojure/contrib')
-rw-r--r--src/test/clojure/clojure/contrib/test_seq.clj67
1 files changed, 56 insertions, 11 deletions
diff --git a/src/test/clojure/clojure/contrib/test_seq.clj b/src/test/clojure/clojure/contrib/test_seq.clj
index 2a7b5ef7..eacd9b73 100644
--- a/src/test/clojure/clojure/contrib/test_seq.clj
+++ b/src/test/clojure/clojure/contrib/test_seq.clj
@@ -1,10 +1,10 @@
(ns clojure.contrib.test-seq
- (:use clojure.test
- clojure.contrib.seq))
+ (:use clojure.test)
+ (:require [clojure.contrib.seq :as seq]))
(deftest test-positions
- (are [expected pred coll] (= expected (positions pred coll))
+ (are [expected pred coll] (= expected (seq/positions pred coll))
[2] string? [:a :b "c"]
() :d [:a :b :c]
[0 2] #{:d} [:d :a :d :a]))
@@ -12,7 +12,7 @@
;Upon further inspection, flatten behaves... wierd.
;These tests are what passes on August 7, 2009
(deftest test-flatten-present
- (are [expected nested-val] (= (flatten nested-val) expected)
+ (are [expected nested-val] (= (seq/flatten nested-val) expected)
;simple literals
[] nil
[] 1
@@ -48,36 +48,81 @@
[count even? odd?] [count even? odd?]))
(deftest test-separate
- (are [test-seq] (= (separate even? test-seq) [[2 4] [1 3 5]])
+ (are [test-seq] (= (seq/separate even? test-seq) [[2 4] [1 3 5]])
[1 2 3 4 5]
#{1 2 3 4 5}
'(1 2 3 4 5)))
;Note - this does not make sense for maps and sets, because order is expected
(deftest test-indexed
- (are [expected test-seq] (= (indexed test-seq) expected)
+ (are [expected test-seq] (= (seq/indexed test-seq) expected)
[[0 :a] [1 :b] [2 :c] [3 :d]] [:a :b :c :d]
[[0 :a] [1 :b] [2 :c] [3 :d]] '(:a :b :c :d)
[[0 \1] [1 \2] [2 \3] [3 \4]] "1234"))
+(deftest test-group-by
+ (is (= (seq/group-by even? [1 2 3 4 5])
+ {false [1 3 5], true [2 4]})))
+
+;Note - this does not make sense for maps and sets, because order is expected
+(deftest test-partition-by
+ (are [test-seq] (= (seq/partition-by (comp even? count) test-seq)
+ [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]])
+ ["a" "bb" "cccc" "dd" "eee" "f" "" "hh"]
+ '("a" "bb" "cccc" "dd" "eee" "f" "" "hh"))
+ (is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
+ [[\a] [\b \c \d] [\e] [\f \g \h] [\i] [\j \k \l \m]])))
+
+(deftest test-frequencies
+ (are [expected test-seq] (= (seq/frequencies test-seq) expected)
+ {\p 2, \s 4, \i 4, \m 1} "mississippi"
+ {1 4 2 2 3 1} [1 1 1 1 2 2 3]
+ {1 4 2 2 3 1} '(1 1 1 1 2 2 3)))
+
+;Note - this does not make sense for maps and sets, because order is expected
+;This is a key differnce between reductions and reduce.
+(deftest test-reductions
+ (is (= (seq/reductions + [1 2 3 4 5])
+ [1 3 6 10 15]))
+ (is (= (reductions + 10 [1 2 3 4 5])
+ [10 11 13 16 20 25])))
+
;Note - this does not make sense for maps and sets, because order is expected
(deftest test-rotations
- (is (= (rotations [1 2 3 4])
+ (is (= (seq/rotations [1 2 3 4])
[[1 2 3 4]
[2 3 4 1]
[3 4 1 2]
[4 1 2 3]])))
;Note - this does not make sense for maps and sets, because order is expected
+(deftest test-partition-all
+ (is (= (seq/partition-all 4 [1 2 3 4 5 6 7 8 9])
+ [[1 2 3 4] [5 6 7 8] [9]]))
+ (is (= (seq/partition-all 4 2 [1 2 3 4 5 6 7 8 9])
+ [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]])))
+
+;Thanks to Andy Fingerhut for the idea of testing invariants
+(deftest test-shuffle-invariants
+ (is (= (count (seq/shuffle [1 2 3 4])) 4))
+ (let [shuffled-seq (seq/shuffle [1 2 3 4])]
+ (is (every? #{1 2 3 4} shuffled-seq))))
+
+;Thanks to Andy Fingerhut for the idea of testing invariants
+(deftest test-rand-elt-invariants
+ (let [elt (seq/rand-elt [:a :b :c :d])]
+ (is (#{:a :b :c :d} elt))))
+
+;Note - this does not make sense for maps and sets, because order is expected
(deftest test-find-first
- (is (= (find-first even? [1 2 3 4 5]) 2))
- (is (= (find-first even? '(1 2 3 4 5)) 2)))
+ (is (= (seq/find-first even? [1 2 3 4 5]) 2))
+ (is (= (seq/find-first even? '(1 2 3 4 5)) 2)))
(deftest test-includes
- (are [coll k] (false? (includes? coll k))
+ (are [coll k] (false? (seq/includes? coll k))
[1 2 3] 0
[] nil
[:a :b] :c)
- (are [coll k] (true? (includes? coll k))
+ (are [coll k] (true? (seq/includes? coll k))
[1 2 3] 1
[:a :b] :b))