/
test.clj
57 lines (48 loc) · 1.65 KB
/
test.clj
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
(ns knowledge.test
(:refer-clojure :exclude [==])
(:require [clojure.test :as test])
(:use clojure.core.logic
meta.meta
entities.albert_einstein))
(refer-to ["axioms.kinship"])
(println (map first (run* [q]
(fresh [x]
(Person x)
(== q [x])))))
(println (distinct (run* [q]
(fresh [x y z]
(conde
[(Person x) (Person y) (Person z) (claim x "father" y) (claim y "father" z)]
[(Person x) (Person y) (Person z) (claim x "father" y) (claim z "child" y)]
[(Person x) (Person y) (Person z) (claim y "child" x) (claim y "father" z)]
[(Person x) (Person y) (Person z) (claim y "child" x) (claim z "child" y)])
(== q [x y z])))))
(println (run* [q]
(fresh [x]
(claim "Albert Einstein" "place-of-birth" x)
(== q [x]))))
(println (run* [q]
(fresh [x]
(claim "Hermann Einstein" "grandchild" x)
(== q [x]))))
(println (run* [q]
(fresh [x]
(claim "Hans Albert Einstein" "grandfather" x)
(== q [x]))))
(test/deftest test-facts
(let [results (set (map first (run* [q] (fresh [x] (Person x) (== q [x])))))]
(test/is
(and (not (empty? results))
(empty? (disj results
"Elsa Einstein" "Hans Albert Einstein" "Albert Einstein" "Hermann Einstein"))))))
(test/deftest test-place-of-death
(test/is (= (first (first (run* [q]
(fresh [x]
(claim "Albert Einstein" "place-of-birth" x)
(== q [x]))))) "Ulm")))
(test/deftest test-grandfather
(let [results (set (map first (run* [q] (fresh [x] (claim "Hans Albert Einstein" "grandfather" x) (== q [x])))))]
(test/is
(and (not (empty? results))
(empty? (disj results
"Hermann Einstein"))))))