Mercurial > lasercutter
view 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 |
line wrap: on
line source
1 ; Copyright (c) Rich Hickey. All rights reserved.2 ; The use and distribution terms for this software are covered by the3 ; 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 by6 ; the terms of this license.7 ; You must not remove this notice, or any other, from this software.9 ; Author: Frantisek Sodomka12 (ns clojure.test-clojure.other-functions13 (:use clojure.test))15 ; http://clojure.org/other_functions17 ; [= not= (tests in data_structures.clj and elsewhere)]20 (deftest test-identity21 ; exactly 1 argument needed22 (is (thrown? IllegalArgumentException (identity)))23 (is (thrown? IllegalArgumentException (identity 1 2)))25 (are [x] (= (identity x) x)26 nil27 false true28 0 4229 0.0 3.1430 2/331 0M 1M32 \c33 "" "abc"34 'sym35 :kw36 () '(1 2)37 [] [1 2]38 {} {:a 1 :b 2}39 #{} #{1 2} )41 ; evaluation42 (are [x y] (= (identity x) y)43 (+ 1 2) 344 (> 5 0) true ))47 (deftest test-name48 (are [x y] (= x (name y))49 "foo" :foo50 "bar" 'bar51 "quux" "quux"))53 (deftest test-fnil54 (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) 4265 ((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]}))73 ; time assert comment doc75 ; partial76 ; comp77 ; complement78 ; constantly80 ; Printing81 ; pr prn print println newline82 ; pr-str prn-str print-str println-str [with-out-str (vars.clj)]84 ; Regex Support85 ; re-matcher re-find re-matches re-groups re-seq