unittest: Proposal to add failUnlessNear

John Roth newsgroups at jhrothjr.com
Tue Jul 20 17:30:28 EDT 2004


"Antoon Pardon" <apardon at forel.vub.ac.be> wrote in message
news:slrncfpk65.m9.apardon at trout.vub.ac.be...
> Op 2004-07-19, John Roth schreef <newsgroups at jhrothjr.com>:
> >
> > An example may help. Let's say I want to
> > test against '6.23e14'. This method would
> > establish bounds of 6.235e14 and 6.225e14
> > and then test whether the other number was
> > within those bounds. (Note that the '5' is
> > appended before the numbers are converted
> > to float, however the second bound is calculated
> > after the conversion.)
>
> Why don't you just test whether the second
> number lies within a fault tolerance of
> 5e11 of 6.23e14

For one blatently obvious reason. It's harder
to calculate that in the character form than it
is to insert the '5', and you don't have the
information to tell what you wanted if you
convert from character to float first.

My objective here is to ***not have to***
separately enter a precision. The semantics
of saying I want something to be treated as equal
if it's "close enough" to 6.23e14 is that it should
be closer to that than to either 6.24e14 or
6.22e14.

John Roth
>
>
> -- 
> Antoon Pardon





More information about the Python-list mailing list