How do I find if two variables are approximately equals?

后端 未结 5 1239
夕颜
夕颜 2020-12-03 16:44

I am writing unit tests that verify calculations in a database and there is a lot of rounding and truncating and stuff that mean that sometimes figures are slightly off.

5条回答
  •  [愿得一人]
    2020-12-03 17:14

    The question was asking how to assert something was almost equal in unit testing. You assert something is almost equal by using the built-in Assert.AreEqual function. For example:

    Assert.AreEqual(expected: 3.5, actual : 3.4999999, delta:0.1);

    This test will pass. Problem solved and without having to write your own function!

提交回复
热议问题