implement optimizations

This commit is contained in:
2026-01-14 15:36:50 +01:00
parent 9391009403
commit cc9961084c
31 changed files with 1025 additions and 1037 deletions

View File

@@ -0,0 +1,91 @@
package com.infendro.bytes.uint
import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `UInt Conversion Test` {
@Test
fun toUByteArray() {
val expected = arrayOf(
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U),
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U),
)
val actual = arrayOf(
0x12345678U.toUByteArray(),
0x12345678U.toUByteArray(LITTLE_ENDIAN),
)
for (i in 0..1) {
assertContentEquals(expected[i], actual[i])
}
}
@Test
fun toByteArray() {
val expected = arrayOf(
byteArrayOf(0x12, 0x34, 0x56, 0x78),
byteArrayOf(0x78, 0x56, 0x34, 0x12),
)
val actual = arrayOf(
0x12345678U.toByteArray(),
0x12345678U.toByteArray(LITTLE_ENDIAN),
)
for (i in 0..1) {
assertContentEquals(expected[i], actual[i])
}
}
@Test
fun `Array toUByteArray`() {
val expected = arrayOf(
ubyteArrayOf(
0x12U, 0x34U, 0x56U, 0x78U,
0x12U, 0x34U, 0x56U, 0x78U,
),
ubyteArrayOf(
0x78U, 0x56U, 0x34U, 0x12U,
0x78U, 0x56U, 0x34U, 0x12U,
),
)
val actual = arrayOf(
uintArrayOf(
0x12345678U,
0x12345678U,
).toUByteArray(),
uintArrayOf(
0x12345678U,
0x12345678U,
).toUByteArray(LITTLE_ENDIAN),
)
for (i in 0..1) {
assertContentEquals(expected[i], actual[i])
}
}
@Test
fun `Array toByteArray`() {
val expected = arrayOf(
byteArrayOf(
0x12, 0x34, 0x56, 0x78,
0x12, 0x34, 0x56, 0x78,
),
byteArrayOf(
0x78, 0x56, 0x34, 0x12,
0x78, 0x56, 0x34, 0x12,
),
)
val actual = arrayOf(
uintArrayOf(
0x12345678U,
0x12345678U,
).toByteArray(),
uintArrayOf(
0x12345678U,
0x12345678U,
).toByteArray(LITTLE_ENDIAN),
)
for (i in 0..1) {
assertContentEquals(expected[i], actual[i])
}
}
}