blob: 7eabae78428d7d83823ba7c4cfb073308aa16714 (
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
70
71
72
|
;; 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-magic.clj
;;
;; A Clojure implementation of Datalog -- Magic Tests
;;
;; straszheimjeffrey (gmail)
;; Created 18 Feburary 2009
(ns clojure.contrib.datalog.tests.test-magic
(:use clojure.test)
(:use clojure.contrib.datalog.magic
clojure.contrib.datalog.rules))
(def rs (rules-set
(<- (:p :x ?x :y ?y) (:e :x ?x :y ?y))
(<- (:p :x ?x :y ?y) (:e :x ?x :y ?z) (:p :x ?z :y ?y))
(<- (:e :x ?x :y ?y) (:b :x ?x :y ?y))
(<- (:e :x ?y :y ?y) (:c :x ?x :y ?y))))
(def q (adorn-query (?- :p :x 1 :y ?y)))
(def ars (adorn-rules-set rs q))
(deftest test-adorn-rules-set
(is (= ars
(rules-set
(<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?y :x ?x))
(<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?z :x ?x)
({:pred :p :bound #{:x}} :y ?y :x ?z))
(<- ({:pred :e :bound #{:x}} :y ?y :x ?y) (:c :y ?y :x ?x))
(<- ({:pred :e :bound #{:x}} :y ?y :x ?x) (:b :y ?y :x ?x))))))
(def m (magic-transform ars))
(deftest test-magic-transform
(is (= m
(rules-set
(<- ({:pred :e :bound #{:x}} :y ?y :x ?y) ({:pred :e :magic true :bound #{:x}} :x ?y) (:c :y ?y :x ?x))
(<- ({:pred :e :bound #{:x}} :y ?y :x ?x) ({:pred :e :magic true :bound #{:x}} :x ?x) (:b :y ?y :x ?x))
(<- ({:pred :p :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x)
({:pred :e :bound #{:x}} :y ?z :x ?x))
(<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
({:pred :e :bound #{:x}} :y ?z :x ?x)
({:pred :p :bound #{:x}} :y ?y :x ?z))
(<- ({:pred :e :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x))
(<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
({:pred :e :bound #{:x}} :y ?y :x ?x))))))
(comment
(run-tests)
)
;; End of file
|