2017-07-27 164 views
0

我想比較雙值與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) 

爲什麼斷言失敗?

回答

0

昨天晚了,但7.256571590148141E-5不是我想象的那樣,7.25 ..,因爲E-5將點5移到左邊,所以它是0.0000725 ...