Files
kotlin-fork/compiler/testData/codegen/box/ranges/contains/inOptimizableFloatRange.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

38 lines
1.2 KiB
Kotlin
Vendored

// WITH_STDLIB
import kotlin.test.*
fun check(x: Float, left: Float, right: Float): Boolean {
val result = x in left..right
val manual = x >= left && x <= right
val range = left..right
assertTrue(result == manual, "Failed: optimized === manual for $range")
assertTrue(result == checkUnoptimized(x, range), "Failed: optimized === unoptimized for $range")
return result
}
fun checkUnoptimized(x: Float, range: ClosedRange<Float>): Boolean {
return x in range
}
fun box(): String {
assertTrue(check(1.0f, 0.0f, 2.0f))
assertTrue(!check(1.0f, -1.0f, 0.0f))
assertTrue(check(Float.MIN_VALUE, 0.0f, 1.0f))
assertTrue(check(Float.MAX_VALUE, Float.MAX_VALUE - Float.MIN_VALUE, Float.MAX_VALUE))
assertTrue(!check(Float.NaN, Float.NaN, Float.NaN))
assertTrue(!check(0.0f, Float.NaN, Float.NaN))
assertTrue(check(-0.0f, -0.0f, +0.0f))
assertTrue(check(-0.0f, -0.0f, -0.0f))
assertTrue(check(-0.0f, +0.0f, +0.0f))
assertTrue(check(+0.0f, -0.0f, -0.0f))
assertTrue(check(+0.0f, +0.0f, +0.0f))
assertTrue(check(+0.0f, -0.0f, +0.0f))
var value = 0.0f
assertTrue(++value in 1.0f..1.0f)
assertTrue(++value !in 1.0f..1.0f)
return "OK"
}