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