代码之家  ›  专栏  ›  技术社区  ›  Igor Brejc

比较双打最优雅的方式?

  •  4
  • Igor Brejc  · 技术社区  · 16 年前

    代码

    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.
    

    在MBUnit3.0中,比较两个双精度数是否相等是最优雅的方法?我知道我可以自己把它们围起来,但是有没有一些MBUnit构造?

    更新:我认为我目前的“解决方法”并不优雅:

    Assert.LessThan(
       Math.Abs(9.97320998018748d - observerPosition.CenterLongitude),
       0.0000001);
    
    1 回复  |  直到 14 年前
        1
  •  5
  •   Andy Dent    14 年前

    AreApproximatelyEqual 似乎是“MBUnit构造用于此”:

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

    这似乎与 Assert.AreEqual(double expected, double actual, double delta)

    推荐文章