Files
kotlin-fork/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt
T
Ilya Matveev 85827b4880 tests: Copy stdlib tests from Kotlin/JVM
This patch copies Kotlin/JVM stdlib tests (libraries/stdlib/test)
excepting ones with explicit java dependencies. It also transforms
the tests to use them as box-tests.
2017-04-07 17:21:11 +07:00

26 lines
804 B
Kotlin

import kotlin.test.*
fun box() {
expect(5L) { 5L.coerceAtLeast(1L) }
expect(5L) { 1L.coerceAtLeast(5L) }
expect(1L) { 5L.coerceAtMost(1L) }
expect(1L) { 1L.coerceAtMost(5L) }
for (value in 0L..10L) {
expect(value) { value.coerceIn(null, null) }
val min = 2L
val max = 5L
val range = min..max
expect(value.coerceAtLeast(min)) { value.coerceIn(min, null) }
expect(value.coerceAtMost(max)) { value.coerceIn(null, max) }
expect(value.coerceAtLeast(min).coerceAtMost(max)) { value.coerceIn(min, max) }
expect(value.coerceAtMost(max).coerceAtLeast(min)) { value.coerceIn(range) }
assertTrue((value.coerceIn(range)) in range)
}
assertFails { 1L.coerceIn(1L, 0L) }
assertFails { 1L.coerceIn(1L..0L) }
}