Skip to content

Instantly share code, notes, and snippets.

@reiddraper
Last active December 17, 2015 23:09
Show Gist options
  • Save reiddraper/5686995 to your computer and use it in GitHub Desktop.
Save reiddraper/5686995 to your computer and use it in GitHub Desktop.
nested properties in simple-check
(defn gen-creator
[{:arbitrary arbitrary-fun :shrink shrink-fun}]
(reify Generator
(arbitrary [this]
(arbitrary-fun this)
(shrink [this value]
(shrink-fun this value)))
;; note, this will change how properties are defined a bit.
;; ie., with this change, you'll actually define a property,
;; which is an implementation of the Property protocol. Impl.s
;; of this are what you'll pass to simple-check.core/quick-check
(def my-property
;; v is a generator that generates
;; vectors of integers
(forall [v (gen/vector gen/int))]
;; inside this block, v will now be a realized
;; value, not a generator
;; and we can even put another property inside
(forall [i (gen/element v)]
;; so now i is a random element from a realized vector, v
(some #{i} v)))
(def my-test
(sc/quick-check 100 my-property))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment