improve test coverage

This commit is contained in:
2025-12-13 11:35:11 +01:00
parent a9f77d6211
commit 3ab2bea4f6
8 changed files with 308 additions and 40 deletions

View File

@@ -0,0 +1,61 @@
package com.infendro.bytearray
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `IntArray Test` {
@Test
fun `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(
intArrayOf(
0x12345678,
0x12345678,
).toByteArray(),
intArrayOf(
0x12345678,
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,
0x12U, 0x34U, 0x56U, 0x78U,
),
ubyteArrayOf(
0x78U, 0x56U, 0x34U, 0x12U,
0x78U, 0x56U, 0x34U, 0x12U,
),
)
val actual = arrayOf(
intArrayOf(
0x12345678,
0x12345678,
).toUByteArray(),
intArrayOf(
0x12345678,
0x12345678,
).toUByteArray(LITTLE_ENDIAN),
)
for (i in 0..1) {
assertContentEquals(expected[i], actual[i])
}
}
}