Files
kotlin-fork/kotlin-native/backend.native/tests/codegen/boxing/box_cache0.kt
T
Abduqodiri Qurbonzoda 193aa0f935 Align the Boolean.hashCode() value across platforms
Boolean.hashCode() should return 1231/1237 for true/false correspondingly.

As a part of efforts to stabilize Native stdlib.
2023-06-14 08:19:46 +00:00

58 lines
1.2 KiB
Kotlin

/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.boxing.box_cache0
import kotlin.test.*
fun <T> areSame(arg1: T, arg2: T): Boolean {
return arg1 === arg2
}
fun Boolean.oneIfTrueElseZero(): Int {
return if (this) 1 else 0
}
@Test fun runTest() {
var acc = 0
val range = 1000
for (i in arrayOf(false, true)) {
for (j in arrayOf(false, true)) {
acc += areSame(i, j).oneIfTrueElseZero()
}
}
println(acc)
acc = 0
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in 0.toChar()..range.toChar()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in -range..range) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
acc = 0
for (i in -range.toLong()..range.toLong()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
println(acc)
}