4

我想将 double 值与 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)

为什么断言失败?

4

1 回答 1

1

It was late yesterday, but 7.256571590148141E-5 is not as I thought, 7.25.., because E-5 moves the point 5 to the left, so it is 0.0000725...

于 2017-07-28T17:33:06.400 回答