Various ways to define checkers.
Various ways to define checkers.
(as-checker function)
Label a function as a checker. This is only required if
the checker is to be used on the left-hand-side of a prerequisite.
See (guide checkers-within-prerequisites)
.
Example:
(fact (f 3) => "odd number received" (provided (g (as-checker odd?)) => "odd number received"))
Label a function as a checker. This is only required if the checker is to be used on the left-hand-side of a prerequisite. See `(guide checkers-within-prerequisites)`. Example: (fact (f 3) => "odd number received" (provided (g (as-checker odd?)) => "odd number received"))
(checker args & body)
Creates an anonymous function tagged as a checker. Such tagging is only
needed if the checker is to be used on the left-hand-side of a
prerequisite. See (guide checkers-within-prerequisites)
.
Example:
(provided
(f (checker [x] (and (pos? x) (even? x)))) => 3)
Creates an anonymous function tagged as a checker. Such tagging is only needed if the checker is to be used on the left-hand-side of a prerequisite. See `(guide checkers-within-prerequisites)`. Example: (provided (f (checker [x] (and (pos? x) (even? x)))) => 3)
(defchecker name docstring? attr-map? bindings+bodies)
Like defn, but tags the variable created and the function it refers to as checkers. This is only required if the checker is to be used in the left-hand side of a prerequisite, but it never hurts to define checkers using this. Here is a checker for positive even numbers:
(defchecker twosie [actual]
(and (pos? actual) (even? actual)))
(fact 2 => twosie)
Here is the definition of a simple version of the roughly
checker:
(defchecker roughly [expected delta] (checker [actual] (and (number? actual) ...))) (fact 1.1 => (roughly 1 0.2))
See also (doc chatty-checker)
.
Like defn, but tags the variable created and the function it refers to as checkers. This is only required if the checker is to be used in the left-hand side of a prerequisite, but it never hurts to define checkers using this. Here is a checker for positive even numbers: (defchecker twosie [actual] (and (pos? actual) (even? actual))) (fact 2 => twosie) Here is the definition of a simple version of the `roughly` checker: (defchecker roughly [expected delta] (checker [actual] (and (number? actual) ...))) (fact 1.1 => (roughly 1 0.2)) See also `(doc chatty-checker)`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close