AssertJ比较双值

时间:2017-07-27 21:58:35

标签: compare double offset assertj

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

为什么断言失败?

1 个答案:

答案 0 :(得分:0)

昨天晚了,但是7.256571590148141E-5并不像我想象的那样,7.25 ..,因为E-5将点5移动到左边,所以它是0.0000725 ...