<commit_before>(ns gigrig.powertree-test
  (:require [cljs.test :refer-macros [deftest is testing]]
            [clojure.zip :as zip]
            [gigrig.powertree :as ptree]))

(defn echo [arg]
  (.log js/console arg)
  arg)

(defn distributor-pedal [n]
  {:type :pedal
   :name (str "pedal" n)
   :distributor true})

(defn isolator-pedal [n]
  {:type :pedal
   :name (str "pedal" n)
   :distributor true
   :isolator true})

(deftest simplify
  (is (= {:power :distributor :name "pedal1"} (ptree/simplify (distributor-pedal 1))))
  (is (= {:power :isolator :name "pedal2"} (ptree/simplify (isolator-pedal 2)))))

(defn eql-zip [expected loc]
  (= expected (zip/root loc)))

(deftest insert
  (let [root (ptree/zipper)]
    (is (eql-zip [:distributor [:pedal "pedal1"]]
                 (ptree/insert root [:pedal "pedal1"])))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:pedal "pedal6"]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:pedal "pedal2"])
                     (ptree/insert [:pedal "pedal3"])
                     (ptree/insert [:pedal "pedal4"])
                     (ptree/insert [:pedal "pedal5"])
                     (ptree/insert [:pedal "pedal6"]))))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:distributor [:pedal "pedal6"] [:pedal "pedal7"]]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:pedal "pedal2"])
                     (ptree/insert [:pedal "pedal3"])
                     (ptree/insert [:pedal "pedal4"])
                     (ptree/insert [:pedal "pedal5"])
                     (ptree/insert [:pedal "pedal6"])
                     (ptree/insert [:pedal "pedal7"]))))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:isolator [:pedal "pedal2"]]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:isolator [:pedal "pedal2"]]))))))

(deftest build
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:pedal "pedal6"]]
               (ptree/build (for [n (range 1 7)] (distributor-pedal n)))))
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:distributor [:pedal "pedal6"] [:pedal "pedal7"]]]
               (ptree/build (for [n (range 1 8)] (distributor-pedal n)))))
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:isolator [:pedal "pedal3"] [:pedal "pedal4"]]]
               (ptree/build [(distributor-pedal 1) (distributor-pedal 2) (isolator-pedal 3) (isolator-pedal 4)]))))<commit_msg>Improve tests<commit_after>(ns gigrig.powertree-test
  (:require [cljs.test :refer-macros [deftest is testing]]
            [clojure.zip :as zip]
            [gigrig.powertree :as ptree]))

;; HELPERS
;; =======
(defn echo [arg]
  (.log js/console arg)
  arg)

(defn distributor-pedal [n]
  {:type :pedal
   :name (str "pedal" n)
   :distributor true})

(defn distributor-pedals [n]
  (for [i (range 1 (inc n))]
    (distributor-pedal i)))

(defn isolator-pedal [n]
  {:type :pedal
   :name (str "pedal" n)
   :distributor true
   :isolator true})

(defn isolator-pedals
  ([n] (isolator-pedals 1 n))
  ([from to] (for [i (range from (inc to))]
               (isolator-pedal i))))

(deftest simplify
  (is (= {:power :distributor :name "pedal1"} (ptree/simplify (distributor-pedal 1))))
  (is (= {:power :isolator :name "pedal2"} (ptree/simplify (isolator-pedal 2)))))

(defn eql-zip [expected loc]
  (= expected (zip/root loc)))

(deftest insert
  (let [root (ptree/zipper)]
    (is (eql-zip [:distributor [:pedal "pedal1"]]
                 (ptree/insert root [:pedal "pedal1"])))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:pedal "pedal6"]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:pedal "pedal2"])
                     (ptree/insert [:pedal "pedal3"])
                     (ptree/insert [:pedal "pedal4"])
                     (ptree/insert [:pedal "pedal5"])
                     (ptree/insert [:pedal "pedal6"]))))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:distributor [:pedal "pedal6"] [:pedal "pedal7"]]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:pedal "pedal2"])
                     (ptree/insert [:pedal "pedal3"])
                     (ptree/insert [:pedal "pedal4"])
                     (ptree/insert [:pedal "pedal5"])
                     (ptree/insert [:pedal "pedal6"])
                     (ptree/insert [:pedal "pedal7"]))))
    (is (eql-zip [:distributor [:pedal "pedal1"] [:isolator [:pedal "pedal2"]]]
                 (-> root
                     (ptree/insert [:pedal "pedal1"])
                     (ptree/insert [:isolator [:pedal "pedal2"]]))))))

(deftest build
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:pedal "pedal6"]]
               (ptree/build (distributor-pedals 6))))
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:distributor [:pedal "pedal6"] [:pedal "pedal7"]]]
               (ptree/build (distributor-pedals 7))))
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:isolator [:pedal "pedal3"] [:pedal "pedal4"]]]
               (ptree/build [(distributor-pedal 1) (distributor-pedal 2) (isolator-pedal 3) (isolator-pedal 4)])))
  (is (eql-zip [:distributor [:pedal "pedal7"] [:isolator [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"]] [:isolator [:pedal "pedal5"] [:pedal "pedal6"]]]
               (ptree/build (cons (distributor-pedal 7) (isolator-pedals 6)))))
  (is (eql-zip [:distributor [:pedal "pedal1"] [:pedal "pedal2"] [:pedal "pedal3"] [:pedal "pedal4"] [:pedal "pedal5"] [:isolator [:pedal "pedal6"] [:pedal "pedal7"]]]
               (ptree/build (concat (distributor-pedals 5) (isolator-pedals 6 7))))))
{'fraction_non_alphanumeric': 0.19323144104803494, 'fraction_numerical': 0.021990018714909545, 'mean_word_length': 2.60078607523863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5373041', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2463, 'n_words': 560}