In module Test§
See primary documentation in context for sub cmp-ok.
multi cmp-ok(Mu $got is raw, $op, Mu $expected is raw, $desc = '')
Compares $got
and $expected
with the given $op
comparator and passes the test if the comparison yields a True
value. The description of the test is optional.
The $op
comparator can be either a Callable
or a Str
containing an infix operator, such as '=='
, a '~~'
, or a user-defined infix.
cmp-ok 'my spelling is apperling', '~~', /perl/, "bad speller";
Metaoperators cannot be given as a string; pass them as a Callable
instead:
cmp-ok <a b c>, &[!eqv], <b d e>, 'not equal';
A Callable
$op
lets you use custom comparisons:
sub my-comp { $^a / $^b < rand }; cmp-ok 1, &my-comp, 2, 'the dice giveth and the dice taketh away' cmp-ok 2, -> $a, $b { $a.is-prime and $b.is-prime and $a < $b }, 7, 'we got primes, one larger than the other!';