Mercurial > lasercutter
comparison src/clojure/contrib/test_contrib/datalog/tests/test_magic.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-magic.clj | |
10 ;; | |
11 ;; A Clojure implementation of Datalog -- Magic Tests | |
12 ;; | |
13 ;; straszheimjeffrey (gmail) | |
14 ;; Created 18 Feburary 2009 | |
15 | |
16 (ns clojure.contrib.datalog.tests.test-magic | |
17 (:use clojure.test) | |
18 (:use clojure.contrib.datalog.magic | |
19 clojure.contrib.datalog.rules)) | |
20 | |
21 | |
22 | |
23 (def rs (rules-set | |
24 (<- (:p :x ?x :y ?y) (:e :x ?x :y ?y)) | |
25 (<- (:p :x ?x :y ?y) (:e :x ?x :y ?z) (:p :x ?z :y ?y)) | |
26 (<- (:e :x ?x :y ?y) (:b :x ?x :y ?y)) | |
27 (<- (:e :x ?y :y ?y) (:c :x ?x :y ?y)))) | |
28 | |
29 (def q (adorn-query (?- :p :x 1 :y ?y))) | |
30 | |
31 (def ars (adorn-rules-set rs q)) | |
32 | |
33 (deftest test-adorn-rules-set | |
34 (is (= ars | |
35 (rules-set | |
36 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?y :x ?x)) | |
37 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?z :x ?x) | |
38 ({:pred :p :bound #{:x}} :y ?y :x ?z)) | |
39 (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) (:c :y ?y :x ?x)) | |
40 (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) (:b :y ?y :x ?x)))))) | |
41 | |
42 | |
43 (def m (magic-transform ars)) | |
44 | |
45 (deftest test-magic-transform | |
46 (is (= m | |
47 (rules-set | |
48 (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) ({:pred :e :magic true :bound #{:x}} :x ?y) (:c :y ?y :x ?x)) | |
49 | |
50 (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) ({:pred :e :magic true :bound #{:x}} :x ?x) (:b :y ?y :x ?x)) | |
51 | |
52 (<- ({:pred :p :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x) | |
53 ({:pred :e :bound #{:x}} :y ?z :x ?x)) | |
54 | |
55 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) | |
56 ({:pred :e :bound #{:x}} :y ?z :x ?x) | |
57 ({:pred :p :bound #{:x}} :y ?y :x ?z)) | |
58 | |
59 (<- ({:pred :e :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)) | |
60 | |
61 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) | |
62 ({:pred :e :bound #{:x}} :y ?y :x ?x)))))) | |
63 | |
64 | |
65 | |
66 | |
67 (comment | |
68 (run-tests) | |
69 ) | |
70 | |
71 ;; End of file | |
72 |