switch to signed-first approach
All checks were successful
/ test (pull_request) Successful in 2m47s
All checks were successful
/ test (pull_request) Successful in 2m47s
It turns out signed math is more performant
This commit is contained in:
37
src/commonTest/kotlin/com/infendro/bytes/int/Conversion.kt
Normal file
37
src/commonTest/kotlin/com/infendro/bytes/int/Conversion.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.infendro.bytes.int
|
||||
|
||||
import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
|
||||
class IntConversionTest {
|
||||
@Test
|
||||
fun toByteArray() {
|
||||
val expected = arrayOf(
|
||||
byteArrayOf(0x12, 0x34, 0x56, 0x78),
|
||||
byteArrayOf(0x78, 0x56, 0x34, 0x12),
|
||||
)
|
||||
val actual = arrayOf(
|
||||
0x12345678.toByteArray(),
|
||||
0x12345678.toByteArray(LITTLE_ENDIAN),
|
||||
)
|
||||
for (i in 0..1) {
|
||||
assertContentEquals(expected[i], actual[i])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toUByteArray() {
|
||||
val expected = arrayOf(
|
||||
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U),
|
||||
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U),
|
||||
)
|
||||
val actual = arrayOf(
|
||||
0x12345678.toUByteArray(),
|
||||
0x12345678.toUByteArray(LITTLE_ENDIAN),
|
||||
)
|
||||
for (i in 0..1) {
|
||||
assertContentEquals(expected[i], actual[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user