diff --git a/src/milkwood_clj/analyse.clj b/src/milkwood_clj/analyse.clj index 013c923..37ec9fe 100644 --- a/src/milkwood_clj/analyse.clj +++ b/src/milkwood_clj/analyse.clj @@ -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 diff --git a/test/milkwood_clj/analyse_test.clj b/test/milkwood_clj/analyse_test.clj new file mode 100644 index 0000000..247dcda --- /dev/null +++ b/test/milkwood_clj/analyse_test.clj @@ -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}}}})))) diff --git a/test/milkwood_clj/core_test.clj b/test/milkwood_clj/core_test.clj new file mode 100644 index 0000000..1c0e0d4 --- /dev/null +++ b/test/milkwood_clj/core_test.clj @@ -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))))