Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unit testing in Mathematica or Wolfram Workbench

36 views
Skip to first unread message

Andrew Moylan

unread,
Aug 21, 2007, 5:14:19 AM8/21/07
to
I want to set up unit tests for a numerical algorithm. I'd like to test the
timing of the algorithm (and consider 1.00 seconds and 1.02 seconds as the
same, etc) and the numerical result (and consider 5.6000000000 and
5.6000000002 to be the same result, etc).

1. Is the testing system in Wolfram Workbench adequate for this purpose? Can
it do the kind of "fuzzy" comparisons I sometimes require? I can't find much
documentation on this testing system beyond the screencast at
http://www.wolfram.com/products/workbench/workflow/WorkbenchTesterDemo.html
and the small amount of written how-to type information in the Workbench
help. Can someone point me to more documentation?

2. Is there an existing add-on package that is good for this purpose?

3. What does Wolfram use internally for unit testing of Mathematica code?


Andrew Moylan

unread,
Aug 23, 2007, 1:33:52 AM8/23/07
to
Adam Berry at Wolfram responded directly to me about this post,
confirming that the answer to question 1 is Yes. Test[] has an option
called EquivalenceFunction that has default value SameQ but can be
modified arbitrarily. It's easy enough to write a custom
EquivalenceFunction to compare numbers to a given precision or
accuracy. Adam gave the example:

Define

MyEquivalenceFunc[actual_,expected_]:= expected - 0.2 < actual <
expected + 0.2

then use

Test[..., EquivalenceFunction->MyEquivalenceFunc]

If you want it to look neater, or if you often have a need for this
sort of fuzzy comparison when writing your own numerical algorithms,
you might find a use for my (trivial, almost one-line) package
ApproximatelyEqual`. I've uploaded it to http://andrew.j.moylan.googlepages.com/mathematica.
Just look at ApproximatelyEqual.nb to see precisely how it defines
approximate equality (it's based on what I gather Mathematica does in
its own algorithms).

Test[] also has a bunch of other options and arguments that you might
want, such as for testing which messages are generated while
evaluating an expression. Evaluate Options[Test] in a test file, or
just browse the simple source code for MUnit` (located in the
Workbench installation folder).


On Aug 21, 7:14 pm, "Andrew Moylan" <andrew.j.moy...@gmail.com> wrote:
> I want to set up unit tests for a numerical algorithm. I'd like to test the
> timing of the algorithm (and consider 1.00 seconds and 1.02 seconds as the
> same, etc) and the numerical result (and consider 5.6000000000 and
> 5.6000000002 to be the same result, etc).
>
> 1. Is the testing system in Wolfram Workbench adequate for this purpose? Can
> it do the kind of "fuzzy" comparisons I sometimes require? I can't find much

> documentation on this testing system beyond the screencast athttp://www.wolfram.com/products/workbench/workflow/WorkbenchTesterDem...

0 new messages