Intrinsics for 'reversed': until

This commit is contained in:
Dmitry Petrov
2017-12-12 14:21:17 +03:00
parent 5f7460a8c7
commit 54cceac99b
9 changed files with 122 additions and 1 deletions
@@ -0,0 +1,24 @@
// WITH_RUNTIME
import kotlin.test.*
fun box(): String {
var sum = 0
for (i in (1 until 5).reversed()) {
sum = sum * 10 + i
}
assertEquals(4321, sum)
var sumL = 0L
for (i in (1L until 5L).reversed()) {
sumL = sumL * 10 + i
}
assertEquals(4321L, sumL)
var sumC = 0
for (i in ('1' until '5').reversed()) {
sumC = sumC * 10 + i.toInt() - '0'.toInt()
}
assertEquals(4321, sumC)
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Int.MIN_VALUE
fun box(): String {
var count = 0
for (i in (M until M + 1).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}