Last active
December 17, 2015 23:09
-
-
Save reiddraper/5686995 to your computer and use it in GitHub Desktop.
nested properties in simple-check
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
(defn gen-creator | |
[{:arbitrary arbitrary-fun :shrink shrink-fun}] | |
(reify Generator | |
(arbitrary [this] | |
(arbitrary-fun this) | |
(shrink [this value] | |
(shrink-fun this value))) |
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
;; 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