rlm@10
|
1 ; Copyright (c) Rich Hickey. All rights reserved.
|
rlm@10
|
2 ; The use and distribution terms for this software are covered by the
|
rlm@10
|
3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
rlm@10
|
4 ; which can be found in the file epl-v10.html at the root of this distribution.
|
rlm@10
|
5 ; By using this software in any fashion, you are agreeing to be bound by
|
rlm@10
|
6 ; the terms of this license.
|
rlm@10
|
7 ; You must not remove this notice, or any other, from this software.
|
rlm@10
|
8
|
rlm@10
|
9 ; Author: Frantisek Sodomka
|
rlm@10
|
10
|
rlm@10
|
11
|
rlm@10
|
12 (ns clojure.test-clojure.other-functions
|
rlm@10
|
13 (:use clojure.test))
|
rlm@10
|
14
|
rlm@10
|
15 ; http://clojure.org/other_functions
|
rlm@10
|
16
|
rlm@10
|
17 ; [= not= (tests in data_structures.clj and elsewhere)]
|
rlm@10
|
18
|
rlm@10
|
19
|
rlm@10
|
20 (deftest test-identity
|
rlm@10
|
21 ; exactly 1 argument needed
|
rlm@10
|
22 (is (thrown? IllegalArgumentException (identity)))
|
rlm@10
|
23 (is (thrown? IllegalArgumentException (identity 1 2)))
|
rlm@10
|
24
|
rlm@10
|
25 (are [x] (= (identity x) x)
|
rlm@10
|
26 nil
|
rlm@10
|
27 false true
|
rlm@10
|
28 0 42
|
rlm@10
|
29 0.0 3.14
|
rlm@10
|
30 2/3
|
rlm@10
|
31 0M 1M
|
rlm@10
|
32 \c
|
rlm@10
|
33 "" "abc"
|
rlm@10
|
34 'sym
|
rlm@10
|
35 :kw
|
rlm@10
|
36 () '(1 2)
|
rlm@10
|
37 [] [1 2]
|
rlm@10
|
38 {} {:a 1 :b 2}
|
rlm@10
|
39 #{} #{1 2} )
|
rlm@10
|
40
|
rlm@10
|
41 ; evaluation
|
rlm@10
|
42 (are [x y] (= (identity x) y)
|
rlm@10
|
43 (+ 1 2) 3
|
rlm@10
|
44 (> 5 0) true ))
|
rlm@10
|
45
|
rlm@10
|
46
|
rlm@10
|
47 (deftest test-name
|
rlm@10
|
48 (are [x y] (= x (name y))
|
rlm@10
|
49 "foo" :foo
|
rlm@10
|
50 "bar" 'bar
|
rlm@10
|
51 "quux" "quux"))
|
rlm@10
|
52
|
rlm@10
|
53 (deftest test-fnil
|
rlm@10
|
54 (let [f1 (fnil vector :a)
|
rlm@10
|
55 f2 (fnil vector :a :b)
|
rlm@10
|
56 f3 (fnil vector :a :b :c)]
|
rlm@10
|
57 (are [result input] (= result [(apply f1 input) (apply f2 input) (apply f3 input)])
|
rlm@10
|
58 [[1 2 3 4] [1 2 3 4] [1 2 3 4]] [1 2 3 4]
|
rlm@10
|
59 [[:a 2 3 4] [:a 2 3 4] [:a 2 3 4]] [nil 2 3 4]
|
rlm@10
|
60 [[:a nil 3 4] [:a :b 3 4] [:a :b 3 4]] [nil nil 3 4]
|
rlm@10
|
61 [[:a nil nil 4] [:a :b nil 4] [:a :b :c 4]] [nil nil nil 4]
|
rlm@10
|
62 [[:a nil nil nil] [:a :b nil nil] [:a :b :c nil]] [nil nil nil nil]))
|
rlm@10
|
63 (are [x y] (= x y)
|
rlm@10
|
64 ((fnil + 0) nil 42) 42
|
rlm@10
|
65 ((fnil conj []) nil 42) [42]
|
rlm@10
|
66 (reduce #(update-in %1 [%2] (fnil inc 0)) {}
|
rlm@10
|
67 ["fun" "counting" "words" "fun"])
|
rlm@10
|
68 {"words" 1, "counting" 1, "fun" 2}
|
rlm@10
|
69 (reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {}
|
rlm@10
|
70 [[:a 1] [:a 2] [:b 3]])
|
rlm@10
|
71 {:b [3], :a [1 2]}))
|
rlm@10
|
72
|
rlm@10
|
73 ; time assert comment doc
|
rlm@10
|
74
|
rlm@10
|
75 ; partial
|
rlm@10
|
76 ; comp
|
rlm@10
|
77 ; complement
|
rlm@10
|
78 ; constantly
|
rlm@10
|
79
|
rlm@10
|
80 ; Printing
|
rlm@10
|
81 ; pr prn print println newline
|
rlm@10
|
82 ; pr-str prn-str print-str println-str [with-out-str (vars.clj)]
|
rlm@10
|
83
|
rlm@10
|
84 ; Regex Support
|
rlm@10
|
85 ; re-matcher re-find re-matches re-groups re-seq
|
rlm@10
|
86
|