Mercurial > lasercutter
view src/clojure/contrib/test_contrib/test_fnmap.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 (ns clojure.contrib.test-fnmap2 (:use clojure.contrib.fnmap3 clojure.test))5 (deftest acts-like-map6 (let [m1 (fnmap get assoc :key1 1 :key2 2)]7 (are [k v] (= v (get m1 k))8 :key1 19 :key2 210 :nonexistent-key nil)11 (are [k v] (= v (k m1))12 :key1 113 :key2 214 :nonexistent-key nil)15 (let [m2 (assoc m1 :key3 3 :key4 4)]16 (are [k v] (= v (get m2 k))17 :key1 118 :key2 219 :key3 320 :key4 421 :nonexistent-key nil))))23 (defn assoc-validate [m key value]24 (if (integer? value)25 (assoc m key value)26 (throw (Exception. "Only integers allowed in this map!"))))28 (deftest validators29 (let [m (fnmap get assoc-validate)]30 (is (= 2 (:key2 (assoc m :key2 2))))31 (is (thrown? Exception (assoc m :key3 3.14)))))33 (defn get-transform [m key]34 (when-let [value (m key)]35 (- value)))37 (deftest transforms38 (let [m (fnmap get-transform assoc)]39 (is (= -2 (:key2 (assoc m :key2 2))))))