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