MbUnit:比较双打的最优雅方法是什么? [英] MbUnit: The most elegant way to compare doubles?
问题描述
代码
Assert.AreEqual (9.97320998018748d, observerPosition.CenterLongitude);
产生
Expected Value & Actual Value : 9.97320998018748
Remark : Both values look the same when formatted but they
are distinct instances.
在MbUnit 3.0中比较两个双精度是否相等的最优雅方法是什么?我知道我可以自己将它们四舍五入,但是为此有一些MbUnit构造吗?
更新:我认为我当前的解决方法"不佳:
Assert.LessThan(
Math.Abs(9.97320998018748d - observerPosition.CenterLongitude),
0.0000001);
AreApproximatelyEqual
似乎是为此的MbUnit构造":
验证实际值 大约等于一些预期 值在指定的增量内.
这似乎类似于 Assert.AreEqual(double expected, double actual, double delta)
>
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);
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)
这篇关于MbUnit:比较双打的最优雅方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!