<commit_before>(ns libx.deflogical-test
    (:require [clojure.test :refer [deftest run-tests is testing]]
              [libx.tuplerules :refer [deflogical]]
              [clara.rules :refer [defrule]]))

(defn rule-props [expansion]
  (second (nth expansion 2)))

(deftest deflogical-test
  (testing "Single fact"
    (is (=
          (rule-props
            (macroexpand
               '(deflogical
                  [-1 :foo "bar"] :-
                  [[?e :baz]]
                  [[?e :quux]])))
          (rule-props
            (macroexpand
              '(defrule x
                 [:baz (= ?e (:e this))]
                 [:quux (= ?e (:e this))]
                 =>
                 (libx.util/insert! [-1 :foo "bar"]))))))))
  ;(testing "Multiple facts"
  ;  (let [output   (macroexpand
  ;                   '(deflogical
  ;                      [[-1 :foo "bar"] [-2 :foo "baz"]]
  ;                      [[?e :baz]]
  ;                      [[?e :quux]]))
  ;        expected (macroexpand
  ;                   '(defrule my-logical
  ;                      [:baz (= ?e (:e this))]
  ;                      [:quux (= ?e (:e this))]
  ;                      =>
  ;                      (insert-all! [[-1 :foo "bar"] [-2 :foo "baz"]])))]
  ;    (is (= output expected)))))

(run-tests)<commit_msg>Update deflogical test for insert multiple facts<commit_after>(ns libx.deflogical-test
    (:require [clojure.test :refer [deftest run-tests is testing]]
              [libx.tuplerules :refer [deflogical]]
              [clara.rules :refer [defrule]]))

(defn rule-props [expansion]
  (second (nth expansion 2)))

;; Because names for deflogical are generated we skip the part of the
;; expansion that includes the name
(deftest deflogical-test
  (testing "Single fact"
    (is (=
          (rule-props
            (macroexpand
               '(deflogical
                  [-1 :foo "bar"] :-
                  [[?e :baz]]
                  [[?e :quux]])))
          (rule-props
            (macroexpand
              '(defrule some-generated-name
                 [:baz (= ?e (:e this))]
                 [:quux (= ?e (:e this))]
                 =>
                 (libx.util/insert! [-1 :foo "bar"])))))))
  (testing "Multiple facts"
    (is (=
          (rule-props
            (macroexpand
             '(deflogical
                [[-1 :foo "bar"] [-2 :foo "baz"]] :-
                [[?e :baz]]
                [[?e :quux]])))
          (rule-props
            (macroexpand
              '(defrule some-generated-name
                 [:baz (= ?e (:e this))]
                 [:quux (= ?e (:e this))]
                 =>
                 (libx.util/insert! [[-1 :foo "bar"] [-2 :foo "baz"]]))))))))

(run-tests)

{'fraction_non_alphanumeric': 0.16477480776272427, 'fraction_numerical': 0.005126327352618088, 'mean_word_length': 1.3093829247675401, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421478', 'n_tokens_mistral': 893, 'n_tokens_neox': 809, 'n_words': 207}