Created
April 20, 2015 21:14
-
-
Save whysoserious/22f7b85005e62311ed25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns prop-test.core | |
(:require [clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop] | |
[cheshire.core :as json])) | |
(def key-gen | |
(gen/such-that not-empty gen/string-alphanumeric)) | |
(def value-any (gen/one-of [gen/string-alphanumeric gen/boolean gen/int])) | |
(def value-list (gen/such-that not-empty (gen/vector value-any))) | |
(def value-gen (gen/one-of [value-list value-any])) | |
;; (map prn (gen/sample value-gen 10)) | |
(defn json-str [sexp] | |
(json/generate-string sexp {:pretty true})) | |
(defn to-json [str] | |
(json/parse-string str)) | |
(defn roundtrip [sexp] | |
(-> sexp json-str to-json)) | |
(def prop-roundtrip | |
(prop/for-all [v value-gen] | |
(= v (roundtrip v)))) | |
;; (tc/quick-check 100 prop-roundtrip) | |
(def map-gen (gen/such-that not-empty (gen/map key-gen value-gen))) | |
(def json-gen (gen/recursive-gen | |
(fn [inner] (gen/map key-gen inner)) | |
(gen/one-of [map-gen value-list]))) | |
;; (map (fn [sexp] | |
;; (println "--------------------------------------------") | |
;; (println (json-str sexp))) | |
;; (gen/sample json-gen 20)) | |
(def prop-roundtrip-full | |
(prop/for-all [v json-gen] | |
(= {} (roundtrip v)))) | |
;; (tc/quick-check 50 prop-roundtrip-full) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment