rlm@10
|
1 ;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and
|
rlm@10
|
2 ;; distribution terms for this software are covered by the Eclipse Public
|
rlm@10
|
3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
|
rlm@10
|
4 ;; be found in the file epl-v10.html at the root of this distribution. By
|
rlm@10
|
5 ;; using this software in any fashion, you are agreeing to be bound by the
|
rlm@10
|
6 ;; terms of this license. You must not remove this notice, or any other,
|
rlm@10
|
7 ;; from this software.
|
rlm@10
|
8 ;;
|
rlm@10
|
9 ;; test-magic.clj
|
rlm@10
|
10 ;;
|
rlm@10
|
11 ;; A Clojure implementation of Datalog -- Magic Tests
|
rlm@10
|
12 ;;
|
rlm@10
|
13 ;; straszheimjeffrey (gmail)
|
rlm@10
|
14 ;; Created 18 Feburary 2009
|
rlm@10
|
15
|
rlm@10
|
16 (ns clojure.contrib.datalog.tests.test-magic
|
rlm@10
|
17 (:use clojure.test)
|
rlm@10
|
18 (:use clojure.contrib.datalog.magic
|
rlm@10
|
19 clojure.contrib.datalog.rules))
|
rlm@10
|
20
|
rlm@10
|
21
|
rlm@10
|
22
|
rlm@10
|
23 (def rs (rules-set
|
rlm@10
|
24 (<- (:p :x ?x :y ?y) (:e :x ?x :y ?y))
|
rlm@10
|
25 (<- (:p :x ?x :y ?y) (:e :x ?x :y ?z) (:p :x ?z :y ?y))
|
rlm@10
|
26 (<- (:e :x ?x :y ?y) (:b :x ?x :y ?y))
|
rlm@10
|
27 (<- (:e :x ?y :y ?y) (:c :x ?x :y ?y))))
|
rlm@10
|
28
|
rlm@10
|
29 (def q (adorn-query (?- :p :x 1 :y ?y)))
|
rlm@10
|
30
|
rlm@10
|
31 (def ars (adorn-rules-set rs q))
|
rlm@10
|
32
|
rlm@10
|
33 (deftest test-adorn-rules-set
|
rlm@10
|
34 (is (= ars
|
rlm@10
|
35 (rules-set
|
rlm@10
|
36 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?y :x ?x))
|
rlm@10
|
37 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?z :x ?x)
|
rlm@10
|
38 ({:pred :p :bound #{:x}} :y ?y :x ?z))
|
rlm@10
|
39 (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) (:c :y ?y :x ?x))
|
rlm@10
|
40 (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) (:b :y ?y :x ?x))))))
|
rlm@10
|
41
|
rlm@10
|
42
|
rlm@10
|
43 (def m (magic-transform ars))
|
rlm@10
|
44
|
rlm@10
|
45 (deftest test-magic-transform
|
rlm@10
|
46 (is (= m
|
rlm@10
|
47 (rules-set
|
rlm@10
|
48 (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) ({:pred :e :magic true :bound #{:x}} :x ?y) (:c :y ?y :x ?x))
|
rlm@10
|
49
|
rlm@10
|
50 (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) ({:pred :e :magic true :bound #{:x}} :x ?x) (:b :y ?y :x ?x))
|
rlm@10
|
51
|
rlm@10
|
52 (<- ({:pred :p :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x)
|
rlm@10
|
53 ({:pred :e :bound #{:x}} :y ?z :x ?x))
|
rlm@10
|
54
|
rlm@10
|
55 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
|
rlm@10
|
56 ({:pred :e :bound #{:x}} :y ?z :x ?x)
|
rlm@10
|
57 ({:pred :p :bound #{:x}} :y ?y :x ?z))
|
rlm@10
|
58
|
rlm@10
|
59 (<- ({:pred :e :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x))
|
rlm@10
|
60
|
rlm@10
|
61 (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
|
rlm@10
|
62 ({:pred :e :bound #{:x}} :y ?y :x ?x))))))
|
rlm@10
|
63
|
rlm@10
|
64
|
rlm@10
|
65
|
rlm@10
|
66
|
rlm@10
|
67 (comment
|
rlm@10
|
68 (run-tests)
|
rlm@10
|
69 )
|
rlm@10
|
70
|
rlm@10
|
71 ;; End of file
|
rlm@10
|
72
|