c7435ba760
We are going to deprecate `WITH_RUNTIME` directive. The main reason behind this change is that `WITH_STDLIB` directive better describes its meaning, specifically it will add kotlin stdlib to test's classpath.
36 lines
905 B
Kotlin
Vendored
36 lines
905 B
Kotlin
Vendored
// WITH_STDLIB
|
|
|
|
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
|
|
@kotlin.jvm.JvmInline
|
|
value class UInt(private val value: Int) {
|
|
fun asInt() = value
|
|
}
|
|
|
|
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
|
|
@kotlin.jvm.JvmInline
|
|
value class UIntArray(private val intArray: IntArray) {
|
|
operator fun get(index: Int): UInt = UInt(intArray[index])
|
|
|
|
operator fun set(index: Int, value: UInt) {
|
|
intArray[index] = value.asInt()
|
|
}
|
|
}
|
|
|
|
fun UIntArray.swap(i: Int, j: Int) {
|
|
this[j] = this[i].also { this[i] = this[j] }
|
|
}
|
|
|
|
fun uIntArrayOf(vararg elements: Int) = UIntArray(intArrayOf(*elements))
|
|
|
|
fun box(): String {
|
|
val a = uIntArrayOf(1, 2, 3, 4)
|
|
a.swap(0, 3)
|
|
a.swap(1, 2)
|
|
|
|
if (a[0].asInt() != 4) return "fail"
|
|
if (a[1].asInt() != 3) return "fail"
|
|
if (a[2].asInt() != 2) return "fail"
|
|
if (a[3].asInt() != 1) return "fail"
|
|
|
|
return "OK"
|
|
} |