我想使用AssertJ比较双精度数值,但是我不知道为什么我的测试失败了。
@Test
public void testInterestToQuote() {
double result = BasicCalculator.accumulationFactorByYearsAndInterest(years, interest)
Assertions.assertThat(result).isCloseTo(expected, Assertions.offset(0.1d))
}
异常是:
java.lang.AssertionError:
Expecting:
<7.256571590148141E-5>
to be close to:
<7.25>
by less than <0.1> but difference was <7.249927434284099>.
(a difference of exactly <0.1> being considered valid)
断言为什么会失败?
assertThat(result).isEqualTo(expected, withPrecision(2d))
- atavio