Mercurial > lasercutter
diff src/clojure/contrib/test_contrib/datalog/tests/test_util.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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/test_contrib/datalog/tests/test_util.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,69 @@ 1.4 +;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 1.5 +;; distribution terms for this software are covered by the Eclipse Public 1.6 +;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 1.7 +;; be found in the file epl-v10.html at the root of this distribution. By 1.8 +;; using this software in any fashion, you are agreeing to be bound by the 1.9 +;; terms of this license. You must not remove this notice, or any other, 1.10 +;; from this software. 1.11 +;; 1.12 +;; test-util.clj 1.13 +;; 1.14 +;; A Clojure implementation of Datalog -- Utilities Tests 1.15 +;; 1.16 +;; straszheimjeffrey (gmail) 1.17 +;; Created 11 Feburary 2009 1.18 + 1.19 +(ns clojure.contrib.datalog.tests.test-util 1.20 + (:use clojure.test 1.21 + clojure.contrib.datalog.util) 1.22 + (:use [clojure.contrib.except :only (throwf)])) 1.23 + 1.24 +(deftest test-is-var? 1.25 + (is (is-var? '?x)) 1.26 + (is (is-var? '?)) 1.27 + (is (not (is-var? '??x))) 1.28 + (is (not (is-var? '??))) 1.29 + (is (not (is-var? 'x))) 1.30 + (is (not (is-var? "fred"))) 1.31 + (is (not (is-var? :q)))) 1.32 + 1.33 +(deftest test-map-values 1.34 + (let [map {:fred 1 :sally 2}] 1.35 + (is (= (map-values #(* 2 %) map) {:fred 2 :sally 4})) 1.36 + (is (= (map-values identity {}) {})))) 1.37 + 1.38 +(deftest test-keys-to-vals 1.39 + (let [map {:fred 1 :sally 2 :joey 3}] 1.40 + (is (= (set (keys-to-vals map [:fred :sally])) #{1 2})) 1.41 + (is (= (set (keys-to-vals map [:fred :sally :becky])) #{1 2})) 1.42 + (is (empty? (keys-to-vals map []))) 1.43 + (is (empty? (keys-to-vals {} [:fred]))))) 1.44 + 1.45 +(deftest test-reverse-map 1.46 + (let [map {:fred 1 :sally 2 :joey 3} 1.47 + map-1 (assoc map :mary 3)] 1.48 + (is (= (reverse-map map) {1 :fred 2 :sally 3 :joey})) 1.49 + (is (or (= (reverse-map map-1) {1 :fred 2 :sally 3 :joey}) 1.50 + (= (reverse-map map-1) {1 :fred 2 :sally 3 :mary}))))) 1.51 + 1.52 +(def some-maps 1.53 + [ 1.54 + { :a 1 :b 2 } 1.55 + { :c 3 :b 3 } 1.56 + { :d 4 :a 1 } 1.57 + { :g 4 :b 4 } 1.58 + { :a 2 :b 1 } 1.59 + { :e 1 :f 1 } 1.60 + ]) 1.61 + 1.62 +(def reduced (preduce + some-maps)) 1.63 +(def merged (apply merge-with + some-maps)) 1.64 + 1.65 +(deftest test-preduce 1.66 + (is (= reduced merged))) 1.67 + 1.68 +(comment 1.69 + (run-tests) 1.70 +) 1.71 + 1.72 +; End of file