implement tests
This commit is contained in:
87
src/commonTest/kotlin/com/infendro/bytearray/ByteArray.kt
Normal file
87
src/commonTest/kotlin/com/infendro/bytearray/ByteArray.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.infendro.bytearray
|
||||
|
||||
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
|
||||
class `ByteArray Test` {
|
||||
@Test
|
||||
fun `and() - size`() {
|
||||
assertFails {
|
||||
byteArrayOf() and byteArrayOf(0x00)
|
||||
}
|
||||
assertFails {
|
||||
byteArrayOf(0x00) and byteArrayOf()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `padStart()`() {
|
||||
val padded = byteArrayOf(0x02, 0x02).padStart(8, 0x01)
|
||||
assertEquals(8, padded.size)
|
||||
assertContentEquals(
|
||||
byteArrayOf(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02),
|
||||
padded
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `padEnd()`() {
|
||||
val padded = byteArrayOf(0x02, 0x02).padEnd(8, 0x01)
|
||||
assertEquals(8, padded.size)
|
||||
assertContentEquals(
|
||||
byteArrayOf(0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01),
|
||||
padded
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toInt()`() {
|
||||
assertEquals(
|
||||
0x12345678,
|
||||
byteArrayOf(0x12, 0x34, 0x56, 0x78).toInt()
|
||||
)
|
||||
assertEquals(
|
||||
0x12345678,
|
||||
byteArrayOf(0x78, 0x56, 0x34, 0x12).toInt(LITTLE_ENDIAN)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toLong()`() {
|
||||
assertEquals(
|
||||
0x1234567812345678L,
|
||||
byteArrayOf(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78).toLong()
|
||||
)
|
||||
assertEquals(
|
||||
0x1234567812345678L,
|
||||
byteArrayOf(0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12).toLong(LITTLE_ENDIAN)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toUInt()`() {
|
||||
assertEquals(
|
||||
0x12345678U,
|
||||
byteArrayOf(0x12, 0x34, 0x56, 0x78).toUInt()
|
||||
)
|
||||
assertEquals(
|
||||
0x12345678U,
|
||||
byteArrayOf(0x78, 0x56, 0x34, 0x12).toUInt(LITTLE_ENDIAN)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toULong()`() {
|
||||
assertEquals(
|
||||
0x1234567812345678UL,
|
||||
byteArrayOf(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78).toULong()
|
||||
)
|
||||
assertEquals(
|
||||
0x1234567812345678UL,
|
||||
byteArrayOf(0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12).toULong(LITTLE_ENDIAN)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user