Once you have determined what inputs are
needed to test the program, you need to decide if the
outputs are correct.
Sometimes you can verify output by calculating
the correct values by hand.
Sometimes a computation does a lot of work, and
it is not practical to do the computation manually.
double squareroot(double a)
{
if (a == 0) return 0;
double xnew = a;
double xold;
do
{
xold = xnew;
xnew = (xold + a / xold) / 2;
}
while (not approx_equal(xnew, xold));
return xnew;
}
We could write a test program that verifies
that the output values fulfill certain properties.
Here we test the squareroot() function
by comparing the square of the returned number with the original
input. (See sqrtest4.cpp).
Another method is to use a slower but reliable
procedure (called an oracle) to verify the results. (In this
case, we will use pow() as an oracle). (See
sqrtest5.cpp)