MbUnit:比较双打的最优雅的方式?
该代码
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AreApproximatelyEqual
似乎是“MbUnit 构造这”:这似乎类似于
Assert.AreEqual(双预期,双实际,双增量)
AreApproximatelyEqual
seems to be the "MbUnit construct for this":This seems to be similar to
Assert.AreEqual(double expected, double actual, double delta)