Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Created December 20, 2013 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shepmaster/8048392 to your computer and use it in GitHub Desktop.
Save shepmaster/8048392 to your computer and use it in GitHub Desktop.
Example of simple-check output when the input data are functions.
(require '[simple-check.core :as sc])
(require '[simple-check.generators :as gen])
(require '[simple-check.properties :as prop])
(def gen-inc
(gen/bind gen/pos-int #(gen/return (partial + %))))
(def gen-dec
(gen/bind gen/pos-int #(gen/return (partial - %))))
(def gen-command
(gen/one-of [gen-inc gen-dec]))
;; Starting at 5, is there a sequence of increments / decrements that
;; causes our value to become negative?
(def prop-always-positive
(prop/for-all [commands (gen/list gen-command)]
(let [combined-command (apply comp commands)]
(pos? (combined-command 5)))))
(sc/quick-check 100 prop-always-positive)
;; {:result false,
;; :failing-size 3,
;; :num-tests 4,
;; :fail [(#<core$partial$fn__4190 clojure.core$partial$fn__4190@10c3db68>)],
;; :shrunk {:total-nodes-visited 4,
;; :depth 1,
;; :result false,
;; :smallest [(#<core$partial$fn__4190 clojure.core$partial$fn__4190@2a799171>)]}}
;; I'd love to have a better output than:
;; #<core$partial$fn__4190 clojure.core$partial$fn__4190@10c3db68>
;; Perhaps there is a way to annotate the generator with user-specified data?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment