Mercurial > hg > octave-lyh
changeset 7027:3e2a59c78b9d
[project @ 2007-10-15 08:22:54 by dbateman]
author | dbateman |
---|---|
date | Mon, 15 Oct 2007 08:22:54 +0000 |
parents | b60eeac5ac38 |
children | ecd6347f7d1c |
files | scripts/ChangeLog scripts/testfun/assert.m |
diffstat | 2 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2007-10-15 Kim Hansen i<kimhanse@gmail.com> + + * testfun/assert.m: Correct documentation of absolution versus + relative error tolerance and add tests. + 2007-10-14 David Bateman <dbateman@free.fr> * pkg/pkg.m (pkg:configure_make): Treat case of no files to install in
--- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -35,10 +35,12 @@ ## lists or structures. ## ## @item assert(@var{observed}, @var{expected}, @var{tol}) -## Produce an error if relative error is less than tolerance. That is, -## @code{abs(@var{observed} - @var{expected}) > @var{tol} * @var{expected}}. -## Absolute error @code{abs(@var{observed} - @var{expected}) > abs(@var{tol})} -## will be used when tolerance is negative or when the expected value is zero. +## Accept a tolerance when comparing numbers. +## If @var{tol} is possitive use it as an absolute tolerance, will produce an error if +## @code{abs(@var{observed} - @var{expected}) > abs(@var{tol})}. +## If @var{tol} is negative use it as a relative tolerance, will produce an error if +## @code{abs(@var{observed} - @var{expected}) > abs(@var{tol} * @var{expected})}. +## If @var{expected} is zero @var{tol} will always be used as an absolute tolerance. ## @end table ## @seealso{test} ## @end deftypefn @@ -249,7 +251,7 @@ %!error assert(3+2*eps, 3, eps); %!error assert(3, 3+2*eps, eps); -%## must give a little space for floating point errors on relative +## must give a little space for floating point errors on relative %!assert(100+100*eps, 100, -2*eps); %!assert(100, 100+100*eps, -2*eps); %!error assert(100+300*eps, 100, -2*eps); @@ -257,6 +259,12 @@ %!error assert(3, [3,3]); %!error assert(3,4); +## test relative vs. absolute tolerances +%!test assert (0.1+eps, 0.1, 2*eps); # accept absolute +%!error assert (0.1+eps, 0.1, -2*eps); # fail relative +%!test assert (100+100*eps, 100, -2*eps); # accept relative +%!error assert (100+100*eps, 100, 2*eps); # fail absolute + ## structures %!shared x,y %! x.a = 1; x.b=[2, 2];