Skip to content

Combining checkers

marick edited this page Feb 25, 2013 · 3 revisions
Clone this wiki locally

If you want to make more than one check per checker, use one of the two combining checkers. The first, every-checker, passes only if all of its constituent checkers pass:

(fact
  4 => (every-checker odd? (roughly 3)))

That fact will fail like this:

FAIL at (t_combining.clj:103)
Actual result did not agree with the checking function.
        Actual result: 4
    Checking function: (every-checker odd? (roughly 3))
    During checking, these intermediate values were seen:
       odd? => false

Notice that every-checker prints which of the checkers failed. every-checker stops checking after the first checker fails.

every-checker can also take regular expressions, which are treated as with extended equality:

user=> (fact "aaab" => (every-checker #"a+b" #(= 4 (count %))))
true

In fact, every-checker can take any argument that can appear on the right-hand side of a checkable, including values to be compared with ordinary equality.

(fact 5 => (every-checker 5 odd? (roughly 5)))

The second function, some-checker, fails only if all of its constituent checkers fail. If any succeeds, some-checker stops checking and succeeds itself.

This fails:

user=> (fact 4 => (some-checker odd? (roughly 3)))
FAIL at (NO_SOURCE_FILE:2)
Actual result did not agree with the checking function.
        Actual result: 4
    Checking function: (some-checker odd? (roughly 3))
false

This succeeds:

user=> (fact 4 => (some-checker odd? (roughly 4)))
true
Something went wrong with that request. Please try again.