Skip to content

Commit

Permalink
[Issue #82] clarifying renames - part #2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBaranosky committed Mar 18, 2012
1 parent fff931e commit 74effe7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/midje/ideas/formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
`(midje.sweet/fact ~docstring
~@body :formula :formula-in-progress))

(defmacro shrink-failure-case [docstring binding-names failed-binding-vals body]
`(loop [shrunk-vectors# (map midje.ideas.formulas/shrink ~failed-binding-vals)]
(let [cur-shrunks# (map first shrunk-vectors#)]
(defmacro shrink-failure-case [docstring binding-leftsides failed-binding-rightsides body]
`(loop [shrunk-binding-rightsides# (map midje.ideas.formulas/shrink ~failed-binding-rightsides)]
(let [cur-shrunks# (map first shrunk-binding-rightsides#)]
(when (and (first cur-shrunks#)
(let [~binding-names cur-shrunks#]
(let [~binding-leftsides cur-shrunks#]
~(formula-fact docstring body)))
(recur (map rest shrunk-vectors#))))))
(recur (map rest shrunk-binding-rightsides#))))))

(defn- deconstruct-formula-args [args]
(let [[docstring? more-args] (pop-docstring args)
[opts bindings body] (if (map? (first more-args))
[(first more-args) (second more-args) (rest (rest more-args))]
[{} (first more-args) (rest more-args)])]
[docstring? opts bindings body]))
[opts-map bindings body] (if (map? (first more-args))
[(first more-args) (second more-args) (rest (rest more-args))]
[{} (first more-args) (rest more-args)])]
[docstring? opts-map bindings body]))

(defmacro formula
"ALPHA/EXPERIMENTAL (subject to change) - Generative-style fact macro.
Expand Down Expand Up @@ -71,13 +71,13 @@
`(try
(loop [num-trials-left# (or (:num-trials ~opts-map) midje.ideas.formulas/*num-trials*)]
(when (pos? num-trials-left#)
(let [bindings-rhss# ~(vec (take-nth 2 (rest bindings)))
~(vec (take-nth 2 bindings)) bindings-rhss#]
(let [binding-rightsides# ~(vec (take-nth 2 (rest bindings)))
~(vec (take-nth 2 bindings)) binding-rightsides#]
(if ~fact
(recur (dec num-trials-left#))
(shrink-failure-case ~docstring?
~(vec (take-nth 2 bindings))
bindings-rhss#
binding-rightsides#
~body)))))
(finally
~conclusion-signal))))
Expand Down
2 changes: 1 addition & 1 deletion test/midje/ideas/t_formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@


;; shrunken failure case is in the same domain as the generator
;; used to create the input case in the forst place.
;; used to create the input case in the first place.
(after-silently
(formula [x (gen-int odd?)] ;;(guard (gs/int) odd?)]
x => neg?))
Expand Down

0 comments on commit 74effe7

Please sign in to comment.