Skip to content

Commit

Permalink
Add negative test cases for multiple rule sources
Browse files Browse the repository at this point in the history
This ensures that if something breaks that would end up always
returning a success, then we will catch that as a failure as well.
  • Loading branch information
JaceRockman committed Jun 20, 2024
1 parent 629b4e7 commit c551175
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions test/fluree/db/reasoner/datalog_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -204,35 +204,58 @@


(testing "multiple graphs as rule sources"
(let [reasoned-db @(fluree/reason db0 :datalog {:rule-graphs [uncle-rule aunt-rule]})]
(let [half-reasoned-db @(fluree/reason db0 :datalog {:rule-graphs [aunt-rule]})
full-reasoned-db @(fluree/reason db0 :datalog {:rule-graphs [uncle-rule aunt-rule]})]

(is (= [["ex:brian" "ex:janine"]]
@(fluree/query half-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"Without only the aunt-rule included, only one result is returned.")

(is (= [["ex:brian" "ex:holly"] ["ex:brian" "ex:janine"]]
@(fluree/query reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"Multiple rule graphs can be used to reason about data.")))
@(fluree/query full-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"With both graphs included, two results are returned.")))

(testing "multiple dbs as rule sources"
(let [reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1 rule-db-2]})]

(let [half-reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1]})
full-reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1 rule-db-2]})]

(is (= []
@(fluree/query half-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"With only the uncle-rule, no results are returned.")

(is (= [["ex:brian" "ex:holly"] ["ex:brian" "ex:janine"]]
@(fluree/query reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"Multiple rule dbs can be used to reason about data.")))
@(fluree/query full-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"With both rule dbs included, two results are returned.")))

(testing "a mixture of graphs and dbs as rule sources"
(let [reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1]
:rule-graphs [aunt-rule]})]

(let [half-reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1]})
full-reasoned-db @(fluree/reason db0 :datalog {:rule-dbs [rule-db-1]
:rule-graphs [aunt-rule]})]

(is (= []
@(fluree/query half-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"With only the uncle-rule, no results are returned.")
(is (= [["ex:brian" "ex:holly"] ["ex:brian" "ex:janine"]]
@(fluree/query reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"Multiple rule dbs can be used to reason about data."))))))
@(fluree/query full-reasoned-db {:context {"ex" "http://example.org/"}
:select ["?s" "?aunt"]
:where {"@id" "?s",
"ex:aunt" "?aunt"}}))
"With both sources included, two results are returned."))))))


(def has-subtask-rule
Expand Down

0 comments on commit c551175

Please sign in to comment.