<commit_before>(ns validation-benchmark.lib.schema
  (:require [schema.core :as s]
            [validation-benchmark.common :refer [in-range?
                                                 prime?
                                                 map->Person]])
  (:import [validation_benchmark.common Person]))


(defn atomic-keyword [v]
  (s/validate s/Keyword v))


(defn atomic-number [v]
  (s/validate s/Num v))


(defn nil-allowed-bool [v]
  (s/validate (s/maybe s/Bool) v))


(defn nil-allowed-number [v]
  (s/validate (s/maybe s/Num) v))


(defn nil-allowed-string [v]
  (s/validate (s/maybe s/Str) v))


(defn person-map [v]
  (s/validate {:name s/Str, :saiyan? s/Bool, :age s/Int} v))


(defn person-record [v]
  (s/validate (s/record Person
                        {:name s/Str, :saiyan? s/Bool, :age s/Int}
                        map->Person) v))


(defn primes [v]
  (s/validate (s/pred prime?) v))


(defn range-check [v]
  (s/validate [(s/one (s/pred (partial in-range? 0.0 1.0)) "f")
               (s/one (s/pred (partial in-range? 1 10)) "g")
               (s/one (s/pred (partial in-range? 1 100)) "h")] v))


(defn set-of-keywords [v]
  (s/validate #{s/Keyword} v))


(defn three-tuple [v]
  (s/validate [(s/one s/Keyword "k")
               (s/one s/Str "s")
               (s/one s/Num "n")]
              v))


(defn vector-of-two-elements [v]
  (s/validate [(s/one s/Any "first") (s/one s/Any "second")] v))


(defn vector-of-variable-length [v]
  (s/validate (s/conditional vector? [s/Any]) v))


(defn wrapper [f valid?]
  (fn [v]
    (= (try
         (f v)
         true
         (catch Exception e false))
       valid?)))<commit_msg>Update schema benchmarks to use s/checker over s/validate<commit_after>(ns validation-benchmark.lib.schema
  (:require [schema.core :as s]
            [validation-benchmark.common :refer [in-range?
                                                 prime?
                                                 map->Person]])
  (:import [validation_benchmark.common Person]))


(def atomic-keyword
  (s/checker s/Keyword))


(def atomic-number
  (s/checker s/Num))


(def nil-allowed-bool
  (s/checker (s/maybe s/Bool)))


(def nil-allowed-number
  (s/checker (s/maybe s/Num)))


(def nil-allowed-string
  (s/checker (s/maybe s/Str)))


(def person-map
  (s/checker {:name s/Str, :saiyan? s/Bool, :age s/Int}))


(def person-record
  (s/checker (s/record Person
                       {:name s/Str, :saiyan? s/Bool, :age s/Int}
                       map->Person)))


(def primes
  (s/checker (s/pred prime?)))


(def range-check
  (s/checker [(s/one (s/pred (partial in-range? 0.0 1.0)) "f")
              (s/one (s/pred (partial in-range? 1 10)) "g")
              (s/one (s/pred (partial in-range? 1 100)) "h")]))


(def set-of-keywords
  (s/checker #{s/Keyword}))


(def three-tuple
  (s/checker [(s/one s/Keyword "k")
              (s/one s/Str "s")
              (s/one s/Num "n")]))


(def vector-of-two-elements
  (s/checker [(s/one s/Any "first") (s/one s/Any "second")]))


(def vector-of-variable-length
  (s/checker (s/conditional vector? [s/Any])))


(defn wrapper [f valid?]
  (fn [v]
    (= (not (f v))
       valid?)))
{'fraction_non_alphanumeric': 0.1755485893416928, 'fraction_numerical': 0.006896551724137931, 'mean_word_length': 1.9656133828996283, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2258699', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1159, 'n_words': 293}