Click here to make these examples interactive with ClojureScript.
clojure.test.check
quick-check
(quick-check num-tests property & {:keys [seed max-size reporter-fn], :or {max-size 200, reporter-fn (constantly nil)}})
Tests property
num-tests
times.
Takes several optional keys:
:seed
Can be used to re-run previous tests, as the seed used is returned after a test is run.
:max-size
. can be used to control the ‘size’ of generated values. The size will start at 0, and grow up to max-size, as the number of tests increases. Generators will use the size parameter to bound their growth. This prevents, for example, generating a five-thousand element vector on the very first test.
:reporter-fn
A callback function that will be called at various points in the test run, with a map like:
;; called after a passing trial
{:type :trial
:property #<...>
:so-far <number of tests run so far>
:num-tests <total number of tests>}
;; called after each failing trial
{:type :failure
:property #<...>
:result ...
:trial-number <tests ran before failure found>
:failing-args [...]}
It will also be called on :complete, :shrink-step and :shrunk.
Examples:
Check that the square of a positive number is always greater than itself:
(def p (prop/for-all [a gen/pos-int] (> (* a a) a)))
(quick-check 100 p)
Another example using reporter-fn
:
(quick-check 200 p
:seed 42
:max-size 50
:reporter-fn (fn [m]
(when (= :failure (:type m))
(println "Uh oh..."))))