Fork me on GitHub
#clojure-europe
<
2021-04-23
>
dharrigan05:04:34

Good Morning!

RAMart05:04:08

☀️ 😎

slipset08:04:11

This mornings little fun:

(s/def ::json-number
  (s/with-gen
    number?
    #(sgen/one-of [(sgen/large-integer) (sgen/double* {:infinite? false :NaN? false})])))

(s/def ::json-scalar (s/or :boolean boolean?
                           :number ::json-number
                           :string string?
                           :nil nil?))

(s/def ::json-value (s/or :object ::json-object
                          :array ::json-array
                          :scalar ::json-scalar))

(s/def ::json-array (s/coll-of ::json-value))
(s/def ::json-object (s/map-of string? ::json-value
                               :gen-max 10))

(s/fdef json/write-str
  :args (s/cat :json ::json-value)
  :ret string?
  :fn #(= (->> % :args :json (s/unform ::json-value))
          (json/read-str (-> % :ret))))

(deftest roundtrip
  (let [results (stest/check `json/write-str)]
    (is (every? nil? (mapv :failure results)))))

👍 3
slipset08:04:31

functions with inverses are really nice for generative testing.