diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/test_contrib/datalog/tests/test_magic.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,72 @@
     1.4 +;;  Copyright (c) Jeffrey Straszheim. All rights reserved.  The use and
     1.5 +;;  distribution terms for this software are covered by the Eclipse Public
     1.6 +;;  License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
     1.7 +;;  be found in the file epl-v10.html at the root of this distribution.  By
     1.8 +;;  using this software in any fashion, you are agreeing to be bound by the
     1.9 +;;  terms of this license.  You must not remove this notice, or any other,
    1.10 +;;  from this software.
    1.11 +;;
    1.12 +;;  test-magic.clj
    1.13 +;;
    1.14 +;;  A Clojure implementation of Datalog -- Magic Tests
    1.15 +;;
    1.16 +;;  straszheimjeffrey (gmail)
    1.17 +;;  Created 18 Feburary 2009
    1.18 +
    1.19 +(ns clojure.contrib.datalog.tests.test-magic
    1.20 +  (:use clojure.test)
    1.21 +  (:use clojure.contrib.datalog.magic
    1.22 +        clojure.contrib.datalog.rules))
    1.23 +
    1.24 +
    1.25 +
    1.26 +(def rs (rules-set
    1.27 +             (<- (:p :x ?x :y ?y) (:e :x ?x :y ?y))
    1.28 +             (<- (:p :x ?x :y ?y) (:e :x ?x :y ?z) (:p :x ?z :y ?y))
    1.29 +             (<- (:e :x ?x :y ?y) (:b :x ?x :y ?y))
    1.30 +             (<- (:e :x ?y :y ?y) (:c :x ?x :y ?y))))
    1.31 +
    1.32 +(def q (adorn-query (?- :p :x 1 :y ?y)))
    1.33 +
    1.34 +(def ars (adorn-rules-set rs q))
    1.35 +
    1.36 +(deftest test-adorn-rules-set
    1.37 +  (is (= ars
    1.38 +         (rules-set
    1.39 +          (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?y :x ?x))
    1.40 +          (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?z :x ?x)
    1.41 +                                                    ({:pred :p :bound #{:x}} :y ?y :x ?z))
    1.42 +          (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) (:c :y ?y :x ?x))
    1.43 +          (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) (:b :y ?y :x ?x))))))
    1.44 +
    1.45 +
    1.46 +(def m (magic-transform ars))
    1.47 +
    1.48 +(deftest test-magic-transform
    1.49 +  (is (= m
    1.50 +         (rules-set
    1.51 +          (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) ({:pred :e :magic true :bound #{:x}} :x ?y) (:c :y ?y :x ?x))
    1.52 +
    1.53 +          (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) ({:pred :e :magic true :bound #{:x}} :x ?x) (:b :y ?y :x ?x))
    1.54 +
    1.55 +          (<- ({:pred :p :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x)
    1.56 +                                                          ({:pred :e :bound #{:x}} :y ?z :x ?x))
    1.57 +
    1.58 +          (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
    1.59 +                                                    ({:pred :e :bound #{:x}} :y ?z :x ?x)
    1.60 +                                                    ({:pred :p :bound #{:x}} :y ?y :x ?z))
    1.61 +
    1.62 +          (<- ({:pred :e :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x))
    1.63 +
    1.64 +          (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)
    1.65 +                                                    ({:pred :e :bound #{:x}} :y ?y :x ?x))))))
    1.66 +
    1.67 +
    1.68 +
    1.69 +
    1.70 +(comment
    1.71 +  (run-tests)
    1.72 +)
    1.73 +
    1.74 +;; End of file
    1.75 +