[SciPy-user] unittests for scipy.stats: assert_almost_equal question

Louis Luangkesorn lluang at yahoo.com
Sun Jan 20 21:38:03 CST 2002


Hmmm, I think that I would like to be testing in terms of
significant digits as opposed to decimal places, especially when
working with floating point.  Since you are asking for such a test,
here it is.  The attached file has a function meant to go into the
scipy_test.py module.  I wrote assert_approx_equal following the
same form as assert_almost_equal
assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):
compares 'actual' and 'desired' and determines the first
'significant' significant digits and checks for accuracy.  Let's
see, I think I counted significant digits correctly.  Can anyone
tell?  

Louis
> From: "eric" <eric at scipy.org>
> To: <scipy-user at scipy.org>
> Subject: Re: [SciPy-user] unittests for scipy.stats:
> assert_almost_equal question
> Date: Sun, 20 Jan 2002 05:36:31 -0500
> Organization: enthought
> Reply-To: scipy-user at scipy.net
> 
> Hey Louis,
> 
<previous message snipped throughout> 
> A thousand blessing upon you.  I immediately commited it to the
> CVS!
> 
<snip> 
> >
> > The assert_almost_equal function is being called using the
> default
> > setting of decimal=7   Since here it seems I have 10 digits of
> > accuracy, why did this fail?
> 
> 7 decimals is not 7 significant digits but actually 7 decimal
> places to the
> left of 0.  The way almost_eqaul works is by using the following
> comparison:
>     round(abs(desired - actual),decimal) == 0
> In this case, abs(desired-actual) is 470. rounding it to the 7
> digits past the decimal leaves it as 470 which fails the test of 
> being equal to 0.
> Maybe a test function needs to be added that tests to a specified
> number of significant digits for cases like these.
> 
> Thanks tons for working on this,
> 
> eric
> 

=====
When I consider your heavens, the work of your fingers,
the moon and the stars, which you have set in place,
what is man that you are mindful of him, the son of man that you care for him?    Psalm 8:3-4
Y!M, AOL, jabber.com: lluang

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: assert_approx_equal.py
Url: http://projects.scipy.org/pipermail/scipy-user/attachments/20020120/fb1077bb/attachment.pl 


More information about the SciPy-user mailing list