[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-12 13:30:53 +01:00
committed by Space Team
parent a1d13f54cb
commit a5f3d5b737
269 changed files with 2207 additions and 0 deletions
@@ -0,0 +1,96 @@
package codegen.arithmetic.basic
import kotlin.test.*
// Check that compiler doesn't optimize it to `true`
fun selfCmp1(x: Int) = x + 1 > x
fun selfCmp2(x: Int) = x - 1 < x
@Test
fun selfComparison() {
assertFalse(selfCmp1(Int.MAX_VALUE))
assertFalse(selfCmp2(Int.MIN_VALUE))
}
private fun charCornersMinus(): Int {
val a: Char = 0xFFFF.toChar()
val b: Char = 0.toChar()
return a - b
}
private fun charCornersComparison(): Boolean {
val a = 0xFFFF.toChar()
val b = 0.toChar()
return a < b
}
@Test
fun charCornerCases() {
assertEquals(65535, charCornersMinus())
assertFalse(charCornersComparison())
}
@Test
fun shifts() {
assertEquals(-2147483648, 1 shl -1)
assertEquals(0, 1 shr -1)
assertEquals(1, 1 shl 32)
assertEquals(1073741823, -1 ushr 2)
assertEquals(-1, -1 shr 2)
}
@Test
@kotlin.ExperimentalUnsignedTypes
fun uintTests() {
assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u)
}
@Test
fun charConversions() {
assertEquals(97.0, 'a'.toDouble())
assertEquals(-1, Char.MAX_VALUE.toShort())
assertEquals(32768, Short.MIN_VALUE.toChar().toInt())
assertEquals(-1, Char.MAX_VALUE.toByte())
assertEquals(65408, Byte.MIN_VALUE.toChar().toInt())
assertEquals(0, Float.MIN_VALUE.toChar().toInt())
}
@Test
fun doubleBasic() {
assertEquals(1, 0f.compareTo(-0f))
assertEquals(1, 0.0.compareTo(-0.0))
assertEquals(1.0, Double.fromBits(1.0.toBits()))
assertEquals(1.0f, Float.fromBits(1.0f.toBits()))
assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits()))
assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits()))
}
@Test
fun integralToFloat() {
assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat())
assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat())
assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble())
assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble())
assertEquals(2147483647, Double.MAX_VALUE.toInt())
assertEquals(0, Float.MIN_VALUE.toLong())
assertEquals(9223372036854775807, Float.MAX_VALUE.toLong())
assertEquals(0, Double.MIN_VALUE.toInt())
}
@Test
fun compareIntToFloat() {
assertEquals(1, 0.compareTo(-0.0f))
assertEquals(0, 0.compareTo(+0.0f))
}
@Test
fun testKt37412() {
val two = 2.0
assertEquals(2, two.toInt())
}
@@ -0,0 +1,11 @@
package codegen.arithmetic.division
import kotlin.test.*
@Test
fun divisionByZero() {
assertFailsWith(ArithmeticException::class, { 5 / 0 })
assertFailsWith(ArithmeticException::class, { 5 % 0 })
assertEquals(1, 5 / try { 0 / 0; 1 } catch (e: ArithmeticException) { 5 })
assertEquals(Double.NaN, 0.0 / 0.0)
}
@@ -0,0 +1,26 @@
package codegen.arithmetic.github1856
import kotlin.test.*
object RGBA {
fun packFast(r: Int, g: Int, b: Int, a: Int) = (r shl 0) or (g shl 8) or (b shl 16) or (a shl 24)
fun getFastR(v: Int): Int = (v ushr 0) and 0xFF
fun getFastG(v: Int): Int = (v ushr 8) and 0xFF
fun getFastB(v: Int): Int = (v ushr 16) and 0xFF
fun getFastA(v: Int): Int = (v ushr 24) and 0xFF
fun premultiplyFastInt(v: Int): Int {
val A = getFastA(v) + 1
val RB = (((v and 0x00FF00FF) * A) ushr 8) and 0x00FF00FF
val G = (((v and 0x0000FF00) * A) ushr 8) and 0x0000FF00
return (v and 0x00FFFFFF.inv()) or RB or G
}
}
@Test
fun main() {
val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt())
val expect = listOf(-1, -137, 2000107383, 2000107319)
assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) })
}