Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Issue #82] validate that :num-trials can only be set to 1+

  • Loading branch information...
commit 5906a1de48ebffc2be1355d20479d5d4530f2f59 1 parent e81ea73
@AlexBaranosky AlexBaranosky authored
View
4 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
View
4 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)))
View
14 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
Please sign in to comment.
Something went wrong with that request. Please try again.