Search code examples
javatestingjunitkotlin

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


I was wondering, in Kotlin, is there the possibility to call the equivalent of the java method:

assertEquals(double expected, double actual, double precision)

because everytime I'm getting this method instead

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

And i can't find the one with the precision parameter. Calling the Java one should be fine too I guess.

My call to the method:

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

I'm getting an error because 0.01 gets in the "message" field


Solution

  • I have figured it out!

    This is how it's done

    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