Mercurial > lasercutter
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 ;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and | |
2 ;; distribution terms for this software are covered by the Eclipse Public | |
3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can | |
4 ;; be found in the file epl-v10.html at the root of this distribution. By | |
5 ;; using this software in any fashion, you are agreeing to be bound by the | |
6 ;; terms of this license. You must not remove this notice, or any other, | |
7 ;; from this software. | |
8 ;; | |
9 ;; test-util.clj | |
10 ;; | |
11 ;; A Clojure implementation of Datalog -- Utilities Tests | |
12 ;; | |
13 ;; straszheimjeffrey (gmail) | |
14 ;; Created 11 Feburary 2009 | |
15 | |
16 (ns clojure.contrib.datalog.tests.test-util | |
17 (:use clojure.test | |
18 clojure.contrib.datalog.util) | |
19 (:use [clojure.contrib.except :only (throwf)])) | |
20 | |
21 (deftest test-is-var? | |
22 (is (is-var? '?x)) | |
23 (is (is-var? '?)) | |
24 (is (not (is-var? '??x))) | |
25 (is (not (is-var? '??))) | |
26 (is (not (is-var? 'x))) | |
27 (is (not (is-var? "fred"))) | |
28 (is (not (is-var? :q)))) | |
29 | |
30 (deftest test-map-values | |
31 (let [map {:fred 1 :sally 2}] | |
32 (is (= (map-values #(* 2 %) map) {:fred 2 :sally 4})) | |
33 (is (= (map-values identity {}) {})))) | |
34 | |
35 (deftest test-keys-to-vals | |
36 (let [map {:fred 1 :sally 2 :joey 3}] | |
37 (is (= (set (keys-to-vals map [:fred :sally])) #{1 2})) | |
38 (is (= (set (keys-to-vals map [:fred :sally :becky])) #{1 2})) | |
39 (is (empty? (keys-to-vals map []))) | |
40 (is (empty? (keys-to-vals {} [:fred]))))) | |
41 | |
42 (deftest test-reverse-map | |
43 (let [map {:fred 1 :sally 2 :joey 3} | |
44 map-1 (assoc map :mary 3)] | |
45 (is (= (reverse-map map) {1 :fred 2 :sally 3 :joey})) | |
46 (is (or (= (reverse-map map-1) {1 :fred 2 :sally 3 :joey}) | |
47 (= (reverse-map map-1) {1 :fred 2 :sally 3 :mary}))))) | |
48 | |
49 (def some-maps | |
50 [ | |
51 { :a 1 :b 2 } | |
52 { :c 3 :b 3 } | |
53 { :d 4 :a 1 } | |
54 { :g 4 :b 4 } | |
55 { :a 2 :b 1 } | |
56 { :e 1 :f 1 } | |
57 ]) | |
58 | |
59 (def reduced (preduce + some-maps)) | |
60 (def merged (apply merge-with + some-maps)) | |
61 | |
62 (deftest test-preduce | |
63 (is (= reduced merged))) | |
64 | |
65 (comment | |
66 (run-tests) | |
67 ) | |
68 | |
69 ; End of file |