Intrinsics for 'reversed': generate in-const-bound ranges as countable
#KT-21323 In Progress
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
import kotlin.test.*
|
||||
|
||||
fun intLow() = 4
|
||||
fun intHigh() = 1
|
||||
fun longLow() = 4L
|
||||
fun longHigh() = 1L
|
||||
fun charLow() = '4'
|
||||
fun charHigh() = '1'
|
||||
|
||||
fun box(): String {
|
||||
for (i in (intLow() .. intHigh()).reversed()) {
|
||||
throw AssertionError("Loop should not be executed")
|
||||
}
|
||||
|
||||
for (i in (longLow() .. longHigh()).reversed()) {
|
||||
throw AssertionError("Loop should not be executed")
|
||||
}
|
||||
|
||||
for (i in (charLow() .. charHigh()).reversed()) {
|
||||
throw AssertionError("Loop should not be executed")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
import kotlin.test.*
|
||||
|
||||
fun intLow() = 1
|
||||
fun intHigh() = 4
|
||||
fun longLow() = 1L
|
||||
fun longHigh() = 4L
|
||||
fun charLow() = '1'
|
||||
fun charHigh() = '4'
|
||||
|
||||
fun box(): String {
|
||||
var sum = 0
|
||||
for (i in (intLow() .. intHigh()).reversed()) {
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
assertEquals(4321, sum)
|
||||
|
||||
var sumL = 0L
|
||||
for (i in (longLow() .. longHigh()).reversed()) {
|
||||
sumL = sumL * 10 + i
|
||||
}
|
||||
assertEquals(4321L, sumL)
|
||||
|
||||
var sumC = 0
|
||||
for (i in (charLow() .. charHigh()).reversed()) {
|
||||
sumC = sumC * 10 + i.toInt() - '0'.toInt()
|
||||
}
|
||||
assertEquals(4321, sumC)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user