computing integrals solving problem without numerical errors the best unit tests for numerical algorithms involve mathematical problems where we know the numerical result beforehand usuallynumerical results contain unknown approximation errorsso knowing the numerical result implies that we have problem where the approximation errors vanish this feature may be present in very simple mathematical problems for examplethe trapezoidal method is exact for integration of linear functions xd ax we can therefore pick some linear function and construct test function that checks equality between the exact analytical expression for the integral and the number computed by the implementation of the trapezoidal method : specific test case can be : /dx this integral involves an "arbitraryinterval oe : : and an "arbitrarylinear function xd by "arbitrarywe mean expressions where we avoid the special numbers and since these have special properties in arithmetic operations ( forgetting to multiply is equivalent to multiplying by and forgetting to add is equivalent to adding demonstrating correct convergence rates normallyunit tests must be based on problems where the numerical approximation errors in our implementation remain unknown howeverwe often know or may assume certain asymptotic behavior of the error we can do some experimental runs with the test problem dt where is doubled in each runn the corresponding errors are then % and %respectively these numbers indicate that the error is roughly reduced by factor of when doubling thusthe error converges to zero as and we say that the convergence rate is in factthis result can also be shown mathematically for the trapezoidal and midpoint method numerical integration methods usually have an error that converge to zero as np for some that depends on the method with such resultit does not matter if we do not know what the actual approximation error iswe know at what rate it is reducedso running the implementation for two or more different values will put us in position to measure the expected rate and see if it is achieved the idea of corresponding unit test is then to run the algorithm for some valuescompute the error (the absolute value of the difference between the exact analytical result and the one produced by the numerical method)and check that the error has approximately correct asymptotic behaviori that the error is proportional to in case of the trapezoidal and midpoint method let us develop more precise method for such unit tests based on convergence rates we assume that the error depends on according to nr where is an unknown constant and is the convergence rate consider set of experiments with various nn nq we compute the corresponding errors eq for two consecutive experimentsnumber and we have the error model ei nri ei nri ( (