summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/clojure/test_clojure/sequences.clj80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/clojure/test_clojure/sequences.clj b/test/clojure/test_clojure/sequences.clj
index 51d379b1..6cc5c47f 100644
--- a/test/clojure/test_clojure/sequences.clj
+++ b/test/clojure/test_clojure/sequences.clj
@@ -1079,3 +1079,83 @@
:a (some #{:a} '(:a :b))
:a (some #{:a} #{:a :b})
))
+
+(deftest test-flatten-present
+ (are [expected nested-val] (= (flatten nested-val) expected)
+ ;simple literals
+ [] nil
+ [] 1
+ [] 'test
+ [] :keyword
+ [] 1/2
+ [] #"[\r\n]"
+ [] true
+ [] false
+ ;vectors
+ [1 2 3 4 5] [[1 2] [3 4 [5]]]
+ [1 2 3 4 5] [1 2 3 4 5]
+ [#{1 2} 3 4 5] [#{1 2} 3 4 5]
+ ;sets
+ [] #{}
+ [] #{#{1 2} 3 4 5}
+ [] #{1 2 3 4 5}
+ [] #{#{1 2} 3 4 5}
+ ;lists
+ [] '()
+ [1 2 3 4 5] `(1 2 3 4 5)
+ ;maps
+ [] {:a 1 :b 2}
+ [:a 1 :b 2] (seq {:a 1 :b 2})
+ [] {[:a :b] 1 :c 2}
+ [:a :b 1 :c 2] (seq {[:a :b] 1 :c 2})
+ [:a 1 2 :b 3] (seq {:a [1 2] :b 3})
+ ;Strings
+ [] "12345"
+ [\1 \2 \3 \4 \5] (seq "12345")
+ ;fns
+ [] count
+ [count even? odd?] [count even? odd?]))
+
+(deftest test-group-by
+ (is (= (group-by even? [1 2 3 4 5])
+ {false [1 3 5], true [2 4]})))
+
+(deftest test-partition-by
+ (are [test-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] (= (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)))
+
+(deftest test-reductions
+ (is (= (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])))
+
+(deftest test-rand-nth-invariants
+ (let [elt (rand-nth [:a :b :c :d])]
+ (is (#{:a :b :c :d} elt))))
+
+(deftest test-seq-contains?
+ (is (seq-contains? [1 2 3 4 5] 5))
+ (is (not (seq-contains? [1 2 3 4 5] 6))))
+
+(deftest test-partition-all
+ (is (= (partition-all 4 [1 2 3 4 5 6 7 8 9])
+ [[1 2 3 4] [5 6 7 8] [9]]))
+ (is (= (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]])))
+
+(deftest test-shuffle-invariants
+ (is (= (count (shuffle [1 2 3 4])) 4))
+ (let [shuffled-seq (shuffle [1 2 3 4])]
+ (is (every? #{1 2 3 4} shuffled-seq))))
+