Assertions are not part of the interface to a routine. Rather, they are an internal consistency check within a piece of code, to ensure that the computation is proceeding as expected.
assert statements specify a boolean expression that must evaluate to true; otherwise it is a fatal error.
private attr arr:ARRAY{INT}; ... sum_of_elts is sum:INT := 0; loop e ::= arr.elt!; assert e > 0; sum := sum + e; end; return sum; end; |
In the above piece of code, we expect the class to only be storing postive values in the array 'arr' . To double check this, when adding the elements together, we check whether each element is positive.