Re: Unit testing in Mathematica or Wolfram Workbench
- To: mathgroup at smc.vnet.net
- Subject: [mg80486] Re: Unit testing in Mathematica or Wolfram Workbench
- From: Andrew Moylan <andrew.j.moylan at gmail.com>
- Date: Thu, 23 Aug 2007 01:15:21 -0400 (EDT)
- References: <firstname.lastname@example.org>
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... at 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... > 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?