Cryptography Reference
In-Depth Information
main()
{
testdist (1000000);
}
void testdist (int nooftests)
{
LINT a;
LINT b;
LINT c;
int i;
for (i = 1; i < nooftests; i++)
{
a = randl (CLINTRNDLN);
b = randl (CLINTRNDLN);
c = randl (CLINTRNDLN);
// test of + and * by application of the distributive law
if ((a + b)*c != (a*c + b*c))
report_error (a, b, c, __LINE__);
}
}
void report_error (LINT& a, LINT& b, LINT& c, int line)
{
LINTd=(a+b)*c;
LINTe=a*c+b*c;
cerr << "error in distributive law before line " << line << endl;
cerr << "a="<<a<<endl;
cerr << "b="<<b<<endl;
cerr << "(a + b)*c="<<d<<endl;
cerr << "a*c+b*c="<<e<<endl;
abort();
}
We now leave it to the reader as an exercise to test all the LINT operators in
this or a similar manner. For orientation, one may look at the test routines for the
C functions. However, there are some new aspects to consider, such as the prefix
and postfix operators ++ and -- , as well as the fact that == is also an operator that
must be tested. Here are some additional program notes:
Tests of the error routine panic() with all defined errors, with and without
exceptions ;
Tests of the I/O functions, stream operators, and manipulators;
Tests of the arithmetic and number-theoretic functions.
Search WWH ::




Custom Search