|
40 | 40 | (is (= '{Bar 2, Foo 1} (#'clojure.core.unify/garner-unifiers CAPS '(Foo Bar) '(1 2))))
|
41 | 41 | (is (= '{?y a, ?x ?y} (#'clojure.core.unify/garner-unifiers '(?x ?y a) '(?y ?x ?x)))))
|
42 | 42 |
|
43 |
| -(deftest test-norvig-bug-cases |
44 |
| - (testing "that the unification of the problem cases in Norvig's paper |
45 |
| - 'Correcting A Widespread Error in Unification Algorithms'. An |
46 |
| - incorrect unifier will return nil or loop forever." |
47 |
| - (is (= '{?x ?y} (unify '(p ?x ?y) '(p ?y ?x)))) |
48 |
| - (is (= '{?y a, ?x ?y} (unify '(p ?x ?y a) '(p ?y ?x ?x)))) |
49 |
| - ;; higher-order predicates! |
50 |
| - (is (= '{?x ?y, ?z (p ?x ?y)} (unify '(q (p ?x ?y) (p ?y ?x)) '(q ?z ?z)))))) |
51 |
| - |
52 | 43 | (deftest test-range-variables
|
53 | 44 | (is (= '{?x 1 ?y (2 3)} (#'clojure.core.unify/garner-unifiers '(?x & ?y) [1 2 3])))
|
54 | 45 | (is (= '{?x 1 ?y 2 ?z (3)} (#'clojure.core.unify/garner-unifiers '(?x ?y & ?z) [1 2 3])))
|
|
69 | 60 | (is (= '(a a a) (#'clojure.core.unify/unifier* CAPS '(X Y a) '(Y X X))))
|
70 | 61 | (is (= '((?a * 5 ** 2) + (4 * 5) + 3) (#'clojure.core.unify/unifier* '((?a * ?x ** 2) + (?b * ?x) + ?c) '(?z + (4 * 5) + 3)))))
|
71 | 62 |
|
72 |
| - |
73 | 63 | (deftest test-unifier
|
74 | 64 | (is (= '((?a * 5 ** 2) + (4 * 5) + 3) (#'clojure.core.unify/unifier '((?a * ?x ** 2) + (?b * ?x) + ?c) '(?z + (4 * 5) + 3))))
|
75 | 65 | (is (= 42 (#'clojure.core.unify/unifier '?x 42)))
|
76 | 66 | (is (= '{a 2} (#'clojure.core.unify/unifier (hash-map 'a '?x) (hash-map 'a 2))))
|
77 | 67 | (is (= #{2 3 4} (#'clojure.core.unify/unifier #{'?a '?b '?c} #{2 3 4}))))
|
78 | 68 |
|
79 |
| - |
80 | 69 | (deftest test-unifier-no-occurs
|
81 | 70 | (is (= '((?a * 5 ** 2) + (4 * 5) + 3) (#'clojure.core.unify/unifier- '((?a * ?x ** 2) + (?b * ?x) + ?c) '(?z + (4 * 5) + 3))))
|
82 | 71 | (is (= 42 (#'clojure.core.unify/unifier- '?x 42)))
|
83 | 72 | (is (= '{a 2} (#'clojure.core.unify/unifier- (hash-map 'a '?x) (hash-map 'a 2))))
|
84 | 73 | (is (= #{2 3 4} (#'clojure.core.unify/unifier- #{'?a '?b '?c} #{2 3 4}))))
|
85 | 74 |
|
86 |
| - |
87 | 75 | (deftest test-mk-unifier
|
88 | 76 | (let [u (#'clojure.core.unify/make-occurs-unifier-fn #(and (symbol? %)
|
89 | 77 | (re-matches #"^\?.*" (name %))))]
|
90 | 78 | (is (= '((?a * 5 ** 2) + (4 * 5) + 3) (u '((?a * ?x ** 2) + (?b * ?x) + ?c) '(?z + (4 * 5) + 3))))))
|
91 | 79 |
|
92 | 80 | (deftest test-aux
|
93 | 81 | (is (#'clojure.core.unify/composite? "foo")))
|
| 82 | + |
| 83 | +(deftest test-norvig-bug-cases |
| 84 | + (testing "that the unification of the problem cases in Norvig's paper |
| 85 | + 'Correcting A Widespread Error in Unification Algorithms'. An |
| 86 | + incorrect unifier will return nil or loop forever." |
| 87 | + (is (= '{?x ?y} (unify '(p ?x ?y) '(p ?y ?x)))) |
| 88 | + (is (= '{?y a, ?x ?y} (unify '(p ?x ?y a) '(p ?y ?x ?x)))) |
| 89 | + ;; higher-order predicates! |
| 90 | + (is (= '{?x ?y, ?z (p ?x ?y)} (unify '(q (p ?x ?y) (p ?y ?x)) '(q ?z ?z)))))) |
| 91 | + |
| 92 | +(deftest regressions |
| 93 | + (testing "That seqs of different lengths do not unify per UNIFY-4" |
| 94 | + (is (= {} (unify '[1 ?x] '[1]))) |
| 95 | + (is (= {} (unify '[1 ?x ?y ?z] '[1]))))) |
| 96 | + |
0 commit comments