function success = testsmall(x, tol) %TESTSMALL verbosely check input has small absolute size. Use in test cases. % % success = testsmall(x, tol) % checks whether max(abs(x(:))) < tol. % % This function is verbose, outputting a result suitable for use in test cases. % Also returns true/false for further processing, e.g. assert(testsmall(...)) to % force stopping a test case. % % tol = 1e-9 by default % Iain Murray, November 2007 if nargin < 2 tol = 1e-9; end assert(tol >= 0); max_err = max(abs(x(:))); success = max_err < tol; if success fprintf('OK (mismatch of %0.3g < (tol=%0.3g))\n', max_err, tol); else fprintf('FAILURE: difference of %g exceeds tolerance of %0.3g\n', max_err, tol); end