Skip to content

Commit

Permalink
[Issue #82] validate that :num-trials can only be set to 1+
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Baranosky committed Mar 15, 2012
1 parent e81ea73 commit 5906a1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions FORMULAS-BACKLOG-AND-FEATURE-IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/midje/ideas/formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
14 changes: 14 additions & 0 deletions test/midje/ideas/t_formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down

0 comments on commit 5906a1d

Please sign in to comment.