Skip to content

Commit

Permalink
test: Add GENERATE * EXCEPT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingMob committed Apr 15, 2024
1 parent 3823297 commit 274b5fe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions test/inferenceql/query/base/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@

(deftest parse-generative-join-success
(parses "table GENERATIVE JOIN model" :generative-join-expr))

(deftest parse-generate-star
(parses "GENERATE * UNDER model" :generate-expr))
6 changes: 6 additions & 0 deletions test/inferenceql/query/permissive/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@
"data GENERATIVE JOIN model CONDITIONED BY x = 0"
"data GENERATIVE JOIN model CONSTRAINED BY x > 0"
"data GENERATIVE JOIN model GIVEN x = 0"))

(deftest generate-valid
(are [s] (not (insta/failure? (parser/parse s :start :generate-expr)))
"GENERATE * UNDER model"
"GENERATE foo, bar UNDER model"
"GENERATE * EXCEPT (foo, bar) UNDER model"))
5 changes: 4 additions & 1 deletion test/inferenceql/query/permissive_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@
"GENERATE VAR x, VAR y UNDER model"

"GENERATE x, y, z UNDER model"
"GENERATE VAR x, VAR y, VAR z UNDER model"))
"GENERATE VAR x, VAR y, VAR z UNDER model"

"GENERATE * EXCEPT (x, y) UNDER model"
"GENERATE * EXCEPT (VAR x, VAR y) UNDER model"))

(deftest approximate-mutual-info
(are [permissive strict] (= (strict.parser/parse strict :start :scalar-expr)
Expand Down
3 changes: 2 additions & 1 deletion test/inferenceql/query/plan_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"GENERATE VAR x UNDER model" ["x"]
"GENERATE VAR x, VAR y UNDER model" ["x" "y"]
"GENERATE VAR y, VAR x UNDER model" ["y" "x"]
"GENERATE VAR x, VAR y, VAR z UNDER model" ["x" "y" "z"]))
"GENERATE * EXCEPT (VAR x) UNDER model" ["y"]
"GENERATE * EXCEPT (VAR x, VAR y) UNDER model" nil))
(testing "values"
(let [rel (eval "GENERATE VAR x UNDER model" {"model" model})]
(doseq [tup (relation/tuples (take 1 #_ 5 rel))]
Expand Down
6 changes: 6 additions & 0 deletions test/inferenceql/query/strict/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"data GENERATIVE JOIN model CONDITIONED BY VAR x = 0"
"data GENERATIVE JOIN model CONSTRAINED BY VAR x > 0"))

(deftest generate-valid
(are [s] (not (insta/failure? (parser/parse s :start :generate-expr)))
"GENERATE * UNDER model"
"GENERATE VAR foo, VAR bar UNDER model"
"GENERATE * EXCEPT (VAR foo, VAR bar) UNDER model"))

(deftest conditioned-by-valid
(are [s] (not (insta/failure? (parser/parse s)))
"SELECT * FROM (GENERATE * UNDER model CONDITIONED BY VAR x = x)"
Expand Down
7 changes: 5 additions & 2 deletions test/inferenceql/query/strict_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,17 @@

;;; Generate

#_

(deftest generate-generates-correct-columns
(testing "generate"
(testing "GENERATE"
(let [model simple-model
q #(q % [] {"model" model})]
(testing "with star "
(doseq [result (q "SELECT * FROM (GENERATE * UNDER model) LIMIT 10")]
(is (= #{"x" "y"} (set (keys result))))))
(testing "with star except"
(doseq [result (q "SELECT * FROM (GENERATE * EXCEPT (VAR x) UNDER model) LIMIT 10")]
(is (= #{"y"} (set (keys result))))))
(testing "with a single variable"
(doseq [result (q "SELECT * FROM (GENERATE VAR y UNDER model) LIMIT 10")]
(is (= #{"y"} (set (keys result))))))
Expand Down

0 comments on commit 274b5fe

Please sign in to comment.