Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Midje `formula`
;; This first swipe at generative-style testing in Midje was super easy:
;; first a use of it
(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
(formula [a (make-string) b (make-string)]
(str a b) => #(.startsWith % a))
;; How its defined
(def ^:dynamic *num-generations* 100)
(defmacro formula [bindings & body]
(macro-for [_ (range *num-generations*)]
`(let ~bindings
;; * just borrow some generator functions from test.generative, and voila
;; a stripped down generative test framework.
;; * this version makes a fact for every generation which would quickly
;; make the fact count in the report meaningless.
;; * doc-strings can be added later.
;; * how can we make the reporting of these really nice?
;; * is this it? There has to be more to this kind of thing than simply
;; generating 100 of each formula. What do you think?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment