MbUnit: The most elegant way to compare doubles?

≯℡__Kan透↙ 提交于 2019-12-10 07:06:02

问题


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);

回答1:


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)



来源:https://stackoverflow.com/questions/727260/mbunit-the-most-elegant-way-to-compare-doubles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!