如何在Kotlin中使用Double Epsilon/Precision调用assertEquals?

Ste*_*llo 5 java testing junit kotlin

我想知道,在Kotlin中,是否有可能调用java方法的等价物:

assertEquals(double expected, double actual, double precision)
Run Code Online (Sandbox Code Playgroud)

因为每次我都会得到这种方法

assertEquals(expected: T, actual: T, message: String)
Run Code Online (Sandbox Code Playgroud)

我找不到具有精度参数的那个.我猜,调用Java也应该没问题.

我对方法的调用:

assertEquals(5000.00, calculateCouponAmount(basicFaceValue, basicInterestRate, amortizationBullet, couponNumber1), 0.01)
Run Code Online (Sandbox Code Playgroud)

我收到错误,因为0.01进入"消息"字段

Ste*_*llo 5

我想通了!

这是怎么做的

import org.junit.*
import Kotlin.Test.assertEquals

Assert.assertEquals(expected, actual, precision) // to use the jUnit standard one
assertEquals(expected, actual, message) // to use the Kotlin one
Run Code Online (Sandbox Code Playgroud)

  • `// 使用 Kotlin one` 意味着当它不是时它是等效的,所以我认为它应该改变 (5认同)