<commit_before>(ns ctia.stores.atom.verdict-test
  (:require [ctia.stores.atom.store :as as]
            [ctia.store :as store :refer [verdict-store]]
            [clojure.test :refer :all]
            [schema.test :as st]
            [schema-generators.generators :as g]
            [ctia.test-helpers.core :as test-helpers]
            [ctia.schemas.verdict :refer [Verdict StoredVerdict realize-verdict]]))

(use-fixtures :once st/validate-schemas)
(use-fixtures :each (join-fixtures [test-helpers/fixture-properties:clean
                                    test-helpers/fixture-properties:atom-store
                                    test-helpers/fixture-ctia-fast]))

(deftest store-test
  (let [verdicts (g/sample 5 StoredVerdict)]
    (doseq [v verdicts]
      (println "Realizing " v)
      (let [verdict (select-keys v [:type :disposition :judgement_id :disposition_name])
            realized-verdict (realize-verdict verdict (:owner v))]
        (store/create-verdict @verdict-store realized-verdict)))))<commit_msg>Added read test<commit_after>(ns ctia.stores.atom.verdict-test
  (:require [ctia.stores.atom.store :as as]
            [ctia.store :as store :refer [verdict-store]]
            [clojure.test :refer :all]
            [schema.test :as st]
            [schema-generators.generators :as g]
            [ctia.test-helpers.core :as test-helpers]
            [ctia.schemas.verdict :refer [Verdict StoredVerdict realize-verdict]])
  (:import [java.util Date]))

(use-fixtures :once st/validate-schemas)
(use-fixtures :each (join-fixtures [test-helpers/fixture-properties:clean
                                    test-helpers/fixture-properties:atom-store
                                    test-helpers/fixture-ctia-fast]))

(defn- test-equiv
  [a b]
  (let [a' (dissoc a :created :id)
        b' (dissoc b :created :id :owner)]
    (is (= a' b'))))

(def one-second 1000)

(defn time-since
  [^Date d]
  (- (.getTime (Date.)) (.getTime d)))

(deftest store-test
  (let [verdicts (g/sample 5 StoredVerdict)]
    (doseq [v verdicts]
      (let [verdict (select-keys v [:type :disposition :judgement_id :disposition_name])
            realized-verdict (realize-verdict verdict (:owner v))]
        (store/create-verdict @verdict-store realized-verdict)))))

(deftest read-test
  (let [verdicts (g/sample 5 StoredVerdict)]
    (doseq [v verdicts]
      (let [verdict (select-keys v [:type :disposition :judgement_id :disposition_name])
            realized-verdict (realize-verdict verdict (:owner v))
            {id :id} (store/create-verdict @verdict-store realized-verdict)
            {created :created :as read-verdict} (store/read-verdict @verdict-store id)]
        (test-equiv verdict read-verdict)
        (is (> one-second (time-since created)))))))
{'fraction_non_alphanumeric': 0.1348435814455232, 'fraction_numerical': 0.0025170801869830997, 'mean_word_length': 2.562099871959027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6256464', 'n_tokens_mistral': 938, 'n_tokens_neox': 914, 'n_words': 205}