7.5 Assertions

Assertions are used to find errors in algorithms. They test whether intermediate results conform to required conditions and issue an error if not.

  • SetAssertionLevel(lev) F

    assigns the global assertion level to lev. By default it is zero.

  • AssertionLevel() F

    returns the current assertion level.

  • Assert(lev,cond) F

    if the global assertion level is at least lev, condition cond is tested and if it does not return true an error is raised. Thus Assert(lev, code) is equivalent to the code

    if AssertionLevel() >= lev and not <code> then
      Error("Assertion failure");
    fi;
    

  • Assert(lev, cond, message ) F

    In this version of the Assert statement, if the global assertion level is at least lev, condition cond is tested and if it does not return true then message is evaluated and printed.

    Assertions are used at various places in the library. Thus turning assertions on can slow code execution significantly.

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000