Mercurial > lasercutter
view 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 source
1 ;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and2 ;; distribution terms for this software are covered by the Eclipse Public3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can4 ;; be found in the file epl-v10.html at the root of this distribution. By5 ;; using this software in any fashion, you are agreeing to be bound by the6 ;; terms of this license. You must not remove this notice, or any other,7 ;; from this software.8 ;;9 ;; test-util.clj10 ;;11 ;; A Clojure implementation of Datalog -- Utilities Tests12 ;;13 ;; straszheimjeffrey (gmail)14 ;; Created 11 Feburary 200916 (ns clojure.contrib.datalog.tests.test-util17 (:use clojure.test18 clojure.contrib.datalog.util)19 (:use [clojure.contrib.except :only (throwf)]))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))))30 (deftest test-map-values31 (let [map {:fred 1 :sally 2}]32 (is (= (map-values #(* 2 %) map) {:fred 2 :sally 4}))33 (is (= (map-values identity {}) {}))))35 (deftest test-keys-to-vals36 (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])))))42 (deftest test-reverse-map43 (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})))))49 (def some-maps50 [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 ])59 (def reduced (preduce + some-maps))60 (def merged (apply merge-with + some-maps))62 (deftest test-preduce63 (is (= reduced merged)))65 (comment66 (run-tests)67 )69 ; End of file