Produces an error if the condition is not met.
assert
can be called in three different ways.
assert (
cond)
assert (
cond,
errmsg, ...)
assert (
cond,
msg_id,
errmsg, ...)
- Called with a single argument cond,
assert
produces an error if cond is zero. If called with a single argument a generic error message. With more than one argument, the additional arguments are passed to theerror
function.assert (
observed,
expected)
- Produce an error if observed is not the same as expected. Note that observed and expected can be strings, scalars, vectors, matrices, lists or structures.
assert(
observed,
expected,
tol)
- Accept a tolerance when comparing numbers. If tol is possitive use it as an absolute tolerance, will produce an error if
abs(
observed-
expected) > abs(
tol)
. If tol is negative use it as a relative tolerance, will produce an error ifabs(
observed-
expected) > abs(
tol*
expected)
. If expected is zero tol will always be used as an absolute tolerance.See also: test