Add overflow-related tests for 'reversed'

This commit is contained in:
Dmitry Petrov
2017-12-13 15:37:50 +03:00
parent 65b5cdbb8d
commit 1aab4e643c
10 changed files with 233 additions and 0 deletions
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = 0.toChar()
fun box(): String {
var count = 0
for (i in (M downTo M).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Int.MIN_VALUE
fun box(): String {
var count = 0
for (i in (M downTo M).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Long.MIN_VALUE
fun box(): String {
var count = 0
for (i in (M downTo M).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = 0xFFFF.toChar()
fun box(): String {
var count = 0
for (i in (M .. M).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
const val M = Int.MAX_VALUE
fun box(): String {
var step = 0
for (i in (M .. M).reversed()) {
++step
if (step > 1) throw AssertionError("Should be executed once")
}
if (step != 1) throw AssertionError("Should be executed once")
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
const val M = Long.MAX_VALUE
fun box(): String {
var count = 0
for (i in (M .. M).reversed()) {
++count
if (count > 1) {
throw AssertionError("Loop should be executed once")
}
}
if (count != 1) throw AssertionError("Should be executed once")
return "OK"
}