Macaulay2 » Documentation
Packages » Macaulay2Doc :: assert
next | previous | forward | backward | up | index | toc

assert -- check whether something is true, raise an error if not

Synopsis

Description

assert x raises an error if x isn't true.

i1 : stopIfError = false;
i2 : assert( (2+2) === 4)
i3 : assert(rank matrix {{1, 2}, {2, 4}} == 2)
stdio:3:1:(3): error: assertion failed

If x is an Expression that evaluates to false, then a partially evaluated form is printed with the error message to assist in debugging.

i4 : assert Equation(rank matrix {{1, 2}, {2, 4}}, 2)
stdio:4:1:(3): error: assertion failed:
1 == 2 is false

See also

Ways to use assert :

For the programmer

The object assert is a method function.