Commits

Meikel Brandmeyer committed 34c73fe

Boolean generators

Comments (0)

Files changed (1)

src/main/clojure/clojurecheck/core.clj

   clojurecheck.core
   (:refer-clojure
     :exclude (long int double float
+              boolean
               list vec
               set sorted-set
               hash-map sorted-map))
   double)
 (alter-meta! #'float merge (meta #'double) (meta #'float))
 
-(def #^{:doc "Generates a random boolean value. Ignores the size guidance"
+;; ## Boolean generators
+(defn boolean
+  "Generates a boolean value which generates the value `true`
+  with probability `p`."
+  {:added "2.1"}
+  [p]
+  {:pre [(<= 0.0 p) (<= p 1.0)]}
+  (reify
+    Generator
+    (arbitrary [this _size] (SimpleValue. (< (rand) p)))))
+
+(def #^{:doc "Generates a random boolean value with 50% chance of
+  a `true` value."
         :added "2.0"}
   bool
-  (reify
-    Generator
-    (arbitrary [this _size] (DomainValue. this (< (rand) 0.5)))))
+  (boolean 0.5))
 
 (defn frequency
   "Chooses one of the given generators based on the associated