Typed arrays API (#1398)

This commit is contained in:
Nikolay Igotti
2018-03-15 10:02:35 +03:00
committed by GitHub
parent dba7041965
commit 204fde4bf1
5 changed files with 252 additions and 0 deletions
+14
View File
@@ -1257,6 +1257,20 @@ task array3(type: RunKonanTest) {
source = "runtime/collections/array3.kt"
}
task typed_array0(type: RunKonanTest) {
// MIPS target is big-endian.
disabled = (project.testTarget == 'linux_mips32')
goldValue = "OK\n"
source = "runtime/collections/typed_array0.kt"
}
task typed_array1(type: RunKonanTest) {
disabled = (project.testTarget == 'wasm32') // No exceptions on WASM.
goldValue = "OK\n"
source = "runtime/collections/typed_array1.kt"
}
task sort0(type: RunKonanTest) {
goldValue = "[a, b, x]\n[-1, 0, 42, 239, 100500]\n"
source = "runtime/collections/sort0.kt"
@@ -0,0 +1,14 @@
package runtime.collections.typed_array0
import kotlin.test.*
@Test fun runTest() {
// Those tests assume little endian bit ordering.
val array = ByteArray(42)
array.setLongAt(5, 0x1234_5678_9abc_def0)
expect(0xdef0.toInt()) { array.charAt(5).toInt() }
expect(0x9abc.toShort()) { array.shortAt(7) }
expect(0x1234_5678) { array.intAt(9) }
println("OK")
}
@@ -0,0 +1,74 @@
package runtime.collections.typed_array1
import kotlin.test.*
@Test fun runTest() {
val array = ByteArray(17)
val results = mutableSetOf<Any>()
var counter = 0
try {
results += array.shortAt(16)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
results += array.charAt(22)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
results += array.intAt(15)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
results += array.longAt(14)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
results += array.floatAt(14)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
results += array.doubleAt(13)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setShortAt(16, 2.toShort())
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setCharAt(22, 'a')
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setIntAt(15, 1234)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setLongAt(14, 1.toLong())
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setFloatAt(14, 1.0f)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
try {
array.setDoubleAt(13, 3.0)
} catch (e: ArrayIndexOutOfBoundsException) {
counter++
}
expect(12) { counter }
expect(0) { results.size }
println("OK")
}