MbUnit: The most elegant way to compare doubles?
Asked Answered
H

1

4

The code

Assert.AreEqual (9.97320998018748d, observerPosition.CenterLongitude);

produces

Expected Value & Actual Value : 9.97320998018748
Remark : Both values look the same when formatted but they 
are distinct instances.

What is the most elegant way to compare two doubles for equality in MbUnit 3.0? I know I could round them up myself, but is there some MbUnit construct for this?

UPDATE: I consider my current "workaround" to be non-elegant:

Assert.LessThan(
   Math.Abs(9.97320998018748d - observerPosition.CenterLongitude),
   0.0000001);
Heinrik answered 7/4, 2009 at 19:30 Comment(0)
I
5

AreApproximatelyEqual seems to be the "MbUnit construct for this":

Verifies that an actual value approximately equals some expected value to within a specified delta.

This seems to be similar to Assert.AreEqual(double expected, double actual, double delta)

Illdisposed answered 7/4, 2009 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.