On Sat, Jul 18, 2009 at 10:49 PM, william
ratcliff<[email protected]> wrote:
> Related to this, how have people done unit testing of sympy related code?
> If for example, we expect a calculation to result in,
> 8.0*J*S*(1-cos(q)),
> and it instead results in:
> 7.999999*J*S*(1-cos(q))
> then unit tests will fail. I assume that cmp is comparing hashes and as the
> floating point numbers are different, the hashes must be different. Is
> there something close to the AssertAlmostEqual in unitTest. My current
> solution is to punt and just insert values for the symbols and test
> numerically, but it would be nicer to test symbolically....
In general we try to avoid floating point numbers as much as possible,
e.g. instead of 8.0, we use just 8 and we don't have any problems.
For floating point tests (e.g. if testing a numeric evaluation), you
need to create (or reuse) a function like
def eq(a, b, eps=1e-8):
return abs(a-b) < eps
and use it like:
assert eq(8, 7.999)
That's a general approach for comparing floating point numbers, e.g.
this is not specific to sympy.
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---