<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dealing With Rounding Errors in Numerical Unit Tests</title>
	<atom:link href="http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/?&amp;owa_from=feed&amp;owa_sid=</link>
	<description>Thinking about agile (small 'a') software development, patterns and practices for building Microsoft .NET applications.</description>
	<lastBuildDate>Fri, 05 Mar 2010 08:12:05 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eric Malamisura</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-1315</link>
		<dc:creator>Eric Malamisura</dc:creator>
		<pubDate>Tue, 24 Nov 2009 20:50:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-1315</guid>
		<description>Just in case anyone is curious, if you are using the Microsoft.VisualStudio.QualityTools.UnitTest framework the AreEquals will accept a delta for comparison purposes...

AreEqual(expected, actual, delta, message);</description>
		<content:encoded><![CDATA[<p>Just in case anyone is curious, if you are using the Microsoft.VisualStudio.QualityTools.UnitTest framework the AreEquals will accept a delta for comparison purposes&#8230;</p>
<p>AreEqual(expected, actual, delta, message);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dealing With Rounding Errors in Numerical Unit Tests Updated &#124; #2782 - Agile software development, patterns and practices for building Microsoft .NET applications.</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-661</link>
		<dc:creator>Dealing With Rounding Errors in Numerical Unit Tests Updated &#124; #2782 - Agile software development, patterns and practices for building Microsoft .NET applications.</dc:creator>
		<pubDate>Wed, 15 Apr 2009 05:08:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-661</guid>
		<description>[...] updated Dealing With Rounding Errors in Numerical Unit Tests to include some more features based on some of the comments I’ve received. If you used the [...]</description>
		<content:encoded><![CDATA[<div style="border-left: #bce1f4 5px solid; padding-left: 1em;">
<p>[...] updated Dealing With Rounding Errors in Numerical Unit Tests to include some more features based on some of the comments I’ve received. If you used the [...]</p>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ade Miller</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-660</link>
		<dc:creator>Ade Miller</dc:creator>
		<pubDate>Wed, 15 Apr 2009 03:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-660</guid>
		<description>Owen,

Good point. The current code doesn&#039;t deal with zero very well. Yes the general point is that xUnit is extensible but I know people copy/paste code so I&#039;ve updated the code and added some guidelines about where you might want to use the ApproximateComparer.

As you point out there&#039;s nothing to stop you writing something that better fits your needs.

Ade</description>
		<content:encoded><![CDATA[<p>Owen,</p>
<p>Good point. The current code doesn&#8217;t deal with zero very well. Yes the general point is that xUnit is extensible but I know people copy/paste code so I&#8217;ve updated the code and added some guidelines about where you might want to use the ApproximateComparer.</p>
<p>As you point out there&#8217;s nothing to stop you writing something that better fits your needs.</p>
<p>Ade</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Owen</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-657</link>
		<dc:creator>Owen</dc:creator>
		<pubDate>Tue, 14 Apr 2009 21:39:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-657</guid>
		<description>Ew it doesn&#039;t work well if x is close to 0, either.  For example, 0.01 and 0.0001 are obviously close.  However, (x - y) / x is 0.99 in this case, which would require a much larger &quot;margin of error&quot;.  It gets worse as x approaches 0.

However, this is irrelevant to what was the point of your post: that you can easily add an arbitrary comparison to xUnit.</description>
		<content:encoded><![CDATA[<p>Ew it doesn&#8217;t work well if x is close to 0, either.  For example, 0.01 and 0.0001 are obviously close.  However, (x &#8211; y) / x is 0.99 in this case, which would require a much larger &#8220;margin of error&#8221;.  It gets worse as x approaches 0.</p>
<p>However, this is irrelevant to what was the point of your post: that you can easily add an arbitrary comparison to xUnit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Owen</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-656</link>
		<dc:creator>Owen</dc:creator>
		<pubDate>Tue, 14 Apr 2009 21:26:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-656</guid>
		<description>The only problem with this approach is it&#039;s a bit naive; what happens when x is 0.0?  You divide by 0, the result is undefined (I got NaN once and Infinity another time, oddly enough), and the comparison returns false.

Petrik&#039;s response probably uses a technique that exploits the representation of double in memory and is more general-purpose.</description>
		<content:encoded><![CDATA[<p>The only problem with this approach is it&#8217;s a bit naive; what happens when x is 0.0?  You divide by 0, the result is undefined (I got NaN once and Infinity another time, oddly enough), and the comparison returns false.</p>
<p>Petrik&#8217;s response probably uses a technique that exploits the representation of double in memory and is more general-purpose.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ade Miller</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-383</link>
		<dc:creator>Ade Miller</dc:creator>
		<pubDate>Thu, 04 Dec 2008 21:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-383</guid>
		<description>Hi Petrik,

I prefer xUnit.NET over NUnit largely because it&#039;s written from the ground up to take advantage of lots of the newer features of .NET. NUnit started off around .NET 1.0 and has had these new things added over time.

I really like xUnit&#039;s extensibility. This is the second challenge to testing I&#039;ve been able to solve simply be extending the framework (see the &lt;a href=&quot;http://www.ademiller.com/blogs/tech/2008/07/no-slow-unit-tests-with-xunitnet/&quot; rel=&quot;nofollow&quot;&gt;StrictFact attribute &lt;/a&gt;for the other one).

I&#039;ll have to check out the dnAnalytics library when I get a chance.

Ade
</description>
		<content:encoded><![CDATA[<p>Hi Petrik,</p>
<p>I prefer xUnit.NET over NUnit largely because it&#8217;s written from the ground up to take advantage of lots of the newer features of .NET. NUnit started off around .NET 1.0 and has had these new things added over time.</p>
<p>I really like xUnit&#8217;s extensibility. This is the second challenge to testing I&#8217;ve been able to solve simply be extending the framework (see the <a href="http://www.ademiller.com/blogs/tech/2008/07/no-slow-unit-tests-with-xunitnet/" rel="nofollow">StrictFact attribute </a>for the other one).</p>
<p>I&#8217;ll have to check out the dnAnalytics library when I get a chance.</p>
<p>Ade</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petrik</title>
		<link>http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/comment-page-1/#comment-382</link>
		<dc:creator>Petrik</dc:creator>
		<pubDate>Thu, 04 Dec 2008 20:56:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.ademiller.com/blogs/tech/2008/12/dealing-with-rounding-errors-in-numerical-unit-tests/#comment-382</guid>
		<description>Hi Ade

This is a cool way of testing numeric values. I really have to look at what xUnit has to offer. Would you say it is better suited for numerical tests than NUnit etc?

Also I thought you might be interested to know that the dnAnalytics library (www.codeplex.com/dnanalytics) will have a Precision class in the next release (disclaimer I am a contributor to the dnAnalytics library). This class provides Equality and compare methods for floating point values. Comparisons can be made based on the number of significant decimals and on the number of floating point values between two numbers. 

For instance your example could be written as:

[Fact]
public void Energy()
{
    Universe target = new Universe(
        new TestSimpleUniverseInitializer(),
        new ForwardEulerIntegrator());

     target.Initialize();

    Assert.IsTrue(Precision.EqualsWithTolerance(target.Energy(), 1.99713333333333, 1);     
}

This checks if target.Energy() is within one floating point value from 1.99713333333333 (which may or may not be exactly what you want).

Petrik</description>
		<content:encoded><![CDATA[<p>Hi Ade</p>
<p>This is a cool way of testing numeric values. I really have to look at what xUnit has to offer. Would you say it is better suited for numerical tests than NUnit etc?</p>
<p>Also I thought you might be interested to know that the dnAnalytics library (www.codeplex.com/dnanalytics) will have a Precision class in the next release (disclaimer I am a contributor to the dnAnalytics library). This class provides Equality and compare methods for floating point values. Comparisons can be made based on the number of significant decimals and on the number of floating point values between two numbers. </p>
<p>For instance your example could be written as:</p>
<p>[Fact]<br />
public void Energy()<br />
{<br />
    Universe target = new Universe(<br />
        new TestSimpleUniverseInitializer(),<br />
        new ForwardEulerIntegrator());</p>
<p>     target.Initialize();</p>
<p>    Assert.IsTrue(Precision.EqualsWithTolerance(target.Energy(), 1.99713333333333, 1);<br />
}</p>
<p>This checks if target.Energy() is within one floating point value from 1.99713333333333 (which may or may not be exactly what you want).</p>
<p>Petrik</p>
]]></content:encoded>
	</item>
</channel>
</rss>
