When you use Assert.AreEqual(1, double.NaN) , it tries the equality test on numbers and, of course, fails, because double.NaN not equal to anything.
When you execute Assert.AreEqual(1, double.NaN, 1E-1) , it should do arithmetic by numbers. In particular, it calculates
Math.Abs((double) (expected - actual)) > delta Math.Abs(1 - double.NaN) > 1E-1 Math.Abs(double.NaN) > 1E-1
which is false. It looks like the actual delta is no bigger than the delta you passed in, but only because it is trying to indicate that you cannot perform the comparison.
The moral of the story: NaN's behavior is pretty crazy (but the best smart people can come up with). Do your best to check NaN before performing any calculations in which you cannot miss the error, as shown below.
Mike graham
source share