[SciPy-user] unittests for scipy.stats: assert_almost_equal question
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
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
> 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
> > The assert_almost_equal function is being called using the
> > 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
> 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,
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!
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the SciPy-user