Interesting! Unit tests show the bug is not in merge-rules, as thought,

but in add-rule.
This commit is contained in:
Simon Brooke 2013-11-08 14:18:02 +00:00
parent 68fafdab99
commit aad3cd6b58
3 changed files with 46 additions and 1 deletions

View file

@ -23,7 +23,6 @@
rules: a rule tree (i.e. a recursively nested map token => rule-tree);
path: a flat sequence of tokens."
[rules path]
(prn "Rule: " path)
(cond
;; if we have no more path, we're done.
(empty? path) nil

View file

@ -0,0 +1,39 @@
(ns milkwood-clj.analyse-test
(:require [clojure.test :refer :all]
[milkwood-clj.analyse :refer :all]))
(deftest flat-rule-test
(testing "Create a rule set with a single rule"
(is (= (add-rule nil '("a" "b" "c" "d")) '{"a" {"b" {"c" {"d" nil}}}}))))
(deftest two-distinct-rule-test
(testing "Create a set of two rules with no common tokens"
(is
(=
(add-rule (add-rule nil '("a" "b" "c" "d")) '("a" "b" "e" "f"))
'{"a" {"b" {"c" {"d" nil} "e" {"f" nil}}}}))))
(deftest two-fork-rule-test
(testing "Create a set of two rules with common initial tokens"
(is
(=
(add-rule (add-rule nil '("a" "b" "c" "d")) '("p" "q" "r" "s"))
'{"a" {"b" {"c" {"d" nil}}} "p" {"q" {"r" {"s" nil}}}}))))
(deftest merge-two-rules
(testing "Merge two rule trees each comprising a single rule, with no tokens common between trees"
(is
(=
(merge-rules
(add-rule nil '("a" "b" "c" "d"))
(add-rule nil '("p" "q" "r" "s")))
'{"a" {"b" {"c" {"d" nil}}} "p" {"q" {"r" {"s" nil}}}}))))
(deftest merge-fork-rules
(testing "Merge two rule tees each comprising a single rule, with common initial tokens"
(is
(=
(merge-rules
(add-rule nil '("a" "b" "c" "d"))
(add-rule nil '("a" "b" "e" "f")))
'{"a" {"b" {"c" {"d" nil} "e" {"f" nil}}}}))))

View file

@ -0,0 +1,7 @@
(ns milkwood-clj.core-test
(:require [clojure.test :refer :all]
[milkwood-clj.core :refer :all]))
(deftest a-test
(testing "Nothing worth testing in core, yet."
(is (= 1 1))))