Check for index-out-of-bound in elementAt function (KT-30051)

This commit is contained in:
Abduqodiri Qurbonzoda
2019-03-07 22:10:29 +03:00
parent 584137121b
commit ba61695a45
16 changed files with 496 additions and 60 deletions
@@ -1490,6 +1490,16 @@ class ArraysTest {
array.sortWith(comparator)
array.iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 }
}
@Test
fun elementAt() {
expect(0) { byteArrayOf(0, 1, 2).elementAt(0) }
expect(1) { shortArrayOf(0, 1, 2).elementAt(1) }
expect(2) { intArrayOf(0, 1, 2).elementAt(2) }
assertFailsWith<IndexOutOfBoundsException> { arrayOf<String>().elementAt(0) }
assertFailsWith<IndexOutOfBoundsException> { longArrayOf(0, 1, 2).elementAt(-1) }
}
}