MbUnit:比较双打的最优雅的方式?

发布于 2024-07-16 02:56:11 字数 527 浏览 5 评论 0原文

该代码

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-07-23 02:56:11

AreApproximatelyEqual 似乎是“MbUnit 构造这”:

验证实际值
大约等于一些预期
值在指定的增量之内。

这似乎类似于 Assert.AreEqual(双预期,双实际,双增量)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文