Design by contract
ADS follows the design by contract of B. Meyer: each operation checks its
specification as a contract (Contract.h) of
one of four kinds, i.e.,
ADS_PRE for the preconditions of the book, ADS_POST for the
postconditions, ADS_INVARIANT for the invariant of a structure, and
ADS_AUDIT for a condition that costs more than the operation (e.g., that
a vector is sorted before a binary search, or that a write left the other
items as they were). The macro ADS_CONTRACTS chooses which of them are
evaluated (0 none, 1 the preconditions, which is the default, 2 also the
postconditions, 3 also the invariants and the audits); with NDEBUG
defined, as in a release build, the default is 0, as for assert. A violated contract
throws ADS::contract_violation, a std::logic_error naming the
condition, the function and the place. Tests are built at the level 3;
furthermore, the axioms of each abstract data type are checked on all its
realizations (contract_*.*-axioms), e.g., top( push( S , v ) ) = v and
pop( push( S , v ) ) = S for a stack.