From db9bfc7730b0d38726284ac5a5ad2b4482e56fdc Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 6 Aug 2021 11:50:54 -0700 Subject: [PATCH 1/2] Transfer projection tests from Zuko --- test/asami/projection_test.cljc | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/asami/projection_test.cljc diff --git a/test/asami/projection_test.cljc b/test/asami/projection_test.cljc new file mode 100644 index 0000000..6814fd8 --- /dev/null +++ b/test/asami/projection_test.cljc @@ -0,0 +1,53 @@ +(ns asami.projection-test + (:require [asami.projection :as projection] + #?(:clj [clojure.test :as t] + :cljs [cljs.test :as t :include-macros true])) + #?(:clj (:import [clojure.lang ExceptionInfo]))) + +(t/deftest test-project-tuple + (let [tuple '[?a ?b ?c] + columns '[?q ?t ?c ?b ?z ?a] + data [[1 2 3 4 5 6] [7 8 9 10 11 12]]] + (t/is (= [6 4 3] (projection/project-tuple tuple columns data))) + (t/is (= nil (projection/project-tuple tuple columns nil))) + (t/is (= nil (projection/project-tuple tuple columns '()))) + (t/is (thrown-with-msg? ExceptionInfo #"Projection variables not found in the selected data: \[\?a\]" + (projection/project-tuple tuple '[?q ?t ?c ?b ?z ?d] data))) + + (let [mdata (with-meta data {:cols columns})] + (t/is (= [6 4 3] (projection/project {} [tuple] mdata))) + (t/is (= [3] (projection/project {} '[[?c]] mdata))) + (t/is (= nil (projection/project {} '[[?c]] (with-meta '() {:cols columns}))))))) + +(t/deftest test-project-single + (let [columns '[?q ?t ?c ?b ?z ?a] + data [[1 2 3 4 5 6] [7 8 9 10 11 12]]] + (t/is (= 3 (projection/project-single '?c columns data))) + (t/is (thrown-with-msg? ExceptionInfo #"Projection variable was not in the selected data: \?c" + (projection/project-single '?c '[?q ?t ?a ?b ?z ?d] data))) + + (let [mdata (with-meta data {:cols columns})] + (t/is (= 3 (projection/project {} '[?c .] mdata)))))) + +(t/deftest test-project-collection + (let [columns '[?q ?t ?c ?b ?z ?a] + data [[1 2 3 4 5 6] [7 8 9 10 11 12]]] + (t/is (= [3 9] (projection/project-collection '?c columns data))) + (t/is (thrown-with-msg? ExceptionInfo #"Projection variable was not in the selected data: \?c" + (projection/project-single '?c '[?q ?t ?a ?b ?z ?d] data))) + + (let [mdata (with-meta data {:cols columns})] + (t/is (= [3 9] + (projection/project {} '[[?c ...]] mdata)))))) + +(t/deftest test-project-results + (let [selection '[?a ?b ?c] + columns '[?q ?t ?c ?b ?z ?a] + data [[1 2 3 4 5 6] [7 8 9 10 11 12]]] + (t/is (= [[6 4 3] [12 10 9]] (projection/project-results {} selection columns data))) + + (let [mdata (with-meta data {:cols columns})] + (t/is (= [[6 4 3] [12 10 9]] (projection/project {} selection mdata)))))) + + +#?(:cljs (run-tests)) From b79606061c22d64e88f2eeaa258255ed5097fb55 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Mon, 9 Aug 2021 11:02:46 -0700 Subject: [PATCH 2/2] Correction to call to run-tests --- test/asami/projection_test.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/asami/projection_test.cljc b/test/asami/projection_test.cljc index 6814fd8..3a4dd9a 100644 --- a/test/asami/projection_test.cljc +++ b/test/asami/projection_test.cljc @@ -50,4 +50,4 @@ (t/is (= [[6 4 3] [12 10 9]] (projection/project {} selection mdata)))))) -#?(:cljs (run-tests)) +#?(:cljs (t/run-tests))