Skip to content

Commit

Permalink
test: Add CONDITIONED BY * EXCEPT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingMob committed Apr 15, 2024
1 parent 0398706 commit b5e9461
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
20 changes: 13 additions & 7 deletions test/inferenceql/query/plan_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@
(plan/plan)
(plan/plan?))
"table GENERATIVE JOIN model"
"table GENERATIVE JOIN model CONDITIONED BY *"
"table GENERATIVE JOIN model CONDITIONED BY * EXCEPT (VAR x)"
"table GENERATIVE JOIN model CONDITIONED BY * EXCEPT VAR x, VAR y"
"table GENERATIVE JOIN model CONDITIONED BY VAR x = 0"
"table GENERATIVE JOIN model CONSTRAINED BY VAR x > 0"))

Expand All @@ -311,10 +314,13 @@
"table GENERATIVE JOIN model"
"table GENERATIVE JOIN model GIVEN x"))

#?(:clj (deftest generative-join
(are [query tbl expected] (let [env {"table" tbl "model" model}]
(= expected (eval query env)))
"table GENERATIVE JOIN model CONDITIONED BY VAR x = x" [{"x" "yes"}] [{"x" "yes" "y" "yes"}]
"table GENERATIVE JOIN model CONDITIONED BY VAR x = x" [{"x" "no"}] [{"x" "no" "y" "no"}]
"table GENERATIVE JOIN model CONDITIONED BY *" [{"x" "yes"}] [{"x" "yes" "y" "yes"}]
"table GENERATIVE JOIN model CONDITIONED BY *" [{"x" "no"}] [{"x" "no" "y" "no"}])))
#?(:clj
(deftest generative-join
(are [query tbl expected] (let [env {"table" tbl "model" model}]
(= expected (eval query env)))
"table GENERATIVE JOIN model CONDITIONED BY VAR x = x" [{"x" "yes"}] [{"x" "yes" "y" "yes"}]
"table GENERATIVE JOIN model CONDITIONED BY VAR x = x" [{"x" "no"}] [{"x" "no" "y" "no"}]
"table GENERATIVE JOIN model CONDITIONED BY *" [{"x" "yes"}] [{"x" "yes" "y" "yes"}]
"table GENERATIVE JOIN model CONDITIONED BY *" [{"x" "no"}] [{"x" "no" "y" "no"}]
"table GENERATIVE JOIN model CONDITIONED BY * EXCEPT VAR x" [{"y" "yes"}] [{"x" "yes" "y" "yes"}]
"table GENERATIVE JOIN model CONDITIONED BY * EXCEPT (VAR x)" [{"y" "yes"}] [{"x" "yes" "y" "yes"}])))
6 changes: 5 additions & 1 deletion test/inferenceql/query/strict/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
(are [s] (not (insta/failure? (parser/parse s)))
"data GENERATIVE JOIN model"
"data GENERATIVE JOIN model CONDITIONED BY VAR x = 0"
"data GENERATIVE JOIN model CONDITIONED BY *"
"data GENERATIVE JOIN model CONDITIONED BY * EXCEPT (VAR x)"
"data GENERATIVE JOIN model CONSTRAINED BY VAR x > 0"))

(deftest generate-valid
Expand All @@ -51,4 +53,6 @@
(deftest conditioned-by-valid
(are [s] (not (insta/failure? (parser/parse s)))
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY VAR x = x)"
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY *)"))
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY *)"
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY * EXCEPT (VAR x))"
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY * EXCEPT VAR x)"))
13 changes: 13 additions & 0 deletions test/inferenceql/query/strict_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
"y" {"yes" 0.0 "no" 1.0}}}]]})
q1 (comp first vals first #(q %1 %2 %3))]
(is (= 0.5 (q1 "SELECT (PROBABILITY DENSITY OF VAR y = 'yes' UNDER model CONDITIONED BY VAR x = x) FROM data;"
(with-meta [{}] {:iql/columns ["x" "y"]})
{"model" model})))
(is (= 0.5 (q1 "SELECT (PROBABILITY DENSITY OF VAR y = 'yes' UNDER (model CONDITIONED BY * EXCEPT VAR y)) FROM data;"
(with-meta [{}] {:iql/columns ["x" "y"]})
{"model" model})))))

Expand Down Expand Up @@ -498,5 +501,15 @@
(is (= 0.75 (q "SELECT PROBABILITY DENSITY OF VAR x = 'yes' UNDER model CONDITIONED BY VAR y = y FROM data"
(with-meta [{}]
{:iql/columns ["x" "y"]})))))

(testing "* except"
(is (= 0.75 (q "SELECT PROBABILITY DENSITY OF VAR x = 'yes' UNDER model CONDITIONED BY * EXCEPT VAR x FROM data"
(with-meta [{}]
{:iql/columns ["x" "y"]}))))

(is (= 0.75 (q "SELECT PROBABILITY DENSITY OF VAR x = 'yes' UNDER model CONDITIONED BY * EXCEPT (VAR x) FROM data"
(with-meta [{}]
{:iql/columns ["x" "y"]})))))

(testing "in with"
(is (= 0.0 (q "WITH model CONDITIONED BY VAR y = 'no' AS model: SELECT PROBABILITY DENSITY OF VAR x = x UNDER model FROM data" [{"x" "yes"}]))))))))

0 comments on commit b5e9461

Please sign in to comment.