Created
December 20, 2013 00:00
-
-
Save shepmaster/8048392 to your computer and use it in GitHub Desktop.
Example of simple-check output when the input data are functions.
This file contains 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
(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