What to call assertEquals with Double Epsilon / Precision in Kotlin?

I was interested, in Kotlin there is an opportunity to call the equivalent of the java method:

assertEquals(double expected, double actual, double precision) 

because every time I get this method,

 assertEquals(expected: T, actual: T, message: String) 

And I cannot find one that has an accuracy parameter. Calling Java should be fine too, I think.

My method call:

 assertEquals(5000.00, calculateCouponAmount(basicFaceValue, basicInterestRate, amortizationBullet, couponNumber1), 0.01) 

I get an error because 0.01 gets into the "message" field

+5
source share
2 answers

I get it!

Here's how to do it.

 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 
+3
source

Just make sure you import the correct class that has the desired assertEquals method assertEquals . In addition, you can verify that the calculateCouponAmount() method returns Double .

+2
source

Source: https://habr.com/ru/post/1270713/


All Articles