diff --git a/FORMULAS-BACKLOG-AND-FEATURE-IDEAS.md b/FORMULAS-BACKLOG-AND-FEATURE-IDEAS.md index e1125c210..cfa5beb61 100644 --- a/FORMULAS-BACKLOG-AND-FEATURE-IDEAS.md +++ b/FORMULAS-BACKLOG-AND-FEATURE-IDEAS.md @@ -27,9 +27,9 @@ * [x] validate that opt-map is only used with valid keys. -* [ ] validate that :num-trials is 1+ +* [x] validate that :num-trials is 1+ -* [ ] more formula syntax valiidation cases inspired by the new opt map +* [ ] more formula syntax validation cases inspired by the new opt map * [ ] Work with Meikel Brandmeyer to combine ClojureCheck's Generators with Shrink. implement shrinking. Report only the first fully shrunken failure diff --git a/src/midje/ideas/formulas.clj b/src/midje/ideas/formulas.clj index 51b8fed62..26a477dec 100644 --- a/src/midje/ideas/formulas.clj +++ b/src/midje/ideas/formulas.clj @@ -104,5 +104,9 @@ (not (empty? invalid-keys)) (simple-report-validation-error form (format "Invalid keys (%s) in formula's options map. Valid keys are: :num-trials" (join ", " invalid-keys))) + (and (:num-trials opt-map) + (not (pos? (:num-trials opt-map)))) + (simple-report-validation-error form (str ":num-trials must be an integer 1 or greater. You tried to set it to: " (:num-trials opt-map))) + :else args))) \ No newline at end of file diff --git a/test/midje/ideas/t_formulas.clj b/test/midje/ideas/t_formulas.clj index d7bdf44dd..55efe4c77 100644 --- a/test/midje/ideas/t_formulas.clj +++ b/test/midje/ideas/t_formulas.clj @@ -48,6 +48,13 @@ (causes-validation-error #"Invalid keys \(:foo, :bar\) in formula's options map. Valid keys are: :num-trials" (formula {:foo 5 :bar 6} [a 1] a => 1)) +(each-causes-validation-error #":num-trials must be an integer 1 or greater" + (formula {:num-trials 0 } [a 1] a => 1) + (formula {:num-trials -1} [a 1] a => 1) + (formula {:num-trials -2} [a 1] a => 1) + (formula {:num-trials -3} [a 1] a => 1) + (formula {:num-trials -4} [a 1] a => 1)) + (defn z [x] ) (causes-validation-error #"background cannot be used inside of formula" (formula [a 1] @@ -61,6 +68,13 @@ (against-background (h 1) => 5) (k a) => 10) +;; :num-trials can be any number 1+ +(formula {:num-trials 1 } [a 1] a => 1) +(formula {:num-trials 2} [a 1] a => 1) +(formula {:num-trials 3} [a 1] a => 1) +(formula {:num-trials 4} [a 1] a => 1) +(formula {:num-trials 10000} [a 1] a => 1) + ;; *num-trials* binding validation