Mic*_*ner 5 double compare offset assertj
我想将双精度值与 AssertJ 进行比较。我不明白为什么我的测试失败。
@Test
public void testInterestToQuote() {
double result = BasicCalculator.accumulationFactorByYearsAndInterest(years, interest)
Assertions.assertThat(result).isCloseTo(expected, Assertions.offset(0.1d))
}
Run Code Online (Sandbox Code Playgroud)
例外是:
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)
Run Code Online (Sandbox Code Playgroud)
为什么断言失败?
昨天很晚了,但是7.256571590148141E-5并不像我想象的那样,7.25..,因为E-5将点5向左移动了,所以是0.0000725...
| 归档时间: |
|
| 查看次数: |
6623 次 |
| 最近记录: |