martmists
01/06/2023, 2:51 PM0.34657359027997264
and 3465735902799727
should be practically equivalent.
I know in kotlin.test we have checkFloatsAreEqual, but without including kotlin.test it seems impossible to figure outjw
01/06/2023, 2:53 PMval prettyMuchEquivalent = second < first+delta && second > first-delta
jw
01/06/2023, 2:55 PMval prettyMuchEquivalent = abs(first - second) < delta
psh
01/06/2023, 2:58 PMassertColorAlmostEqualTo(…)
kevin.cianfarini
01/06/2023, 3:24 PMkotlin.test
has the following two functions which include a tolerance for equality of floating point numbers.
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
checkDoublesAreEqual(expected, actual, absoluteTolerance, message)
}
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
checkFloatsAreEqual(expected, actual, absoluteTolerance, message)
}
jw
01/06/2023, 3:25 PMjw
01/06/2023, 3:25 PMkevin.cianfarini
01/06/2023, 3:25 PMI know in kotlin.test we have checkFloatsAreEqual, but without including kotlin.test it seems impossible to figure out