implement tests
This commit is contained in:
@@ -17,6 +17,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
linuxX64()
|
linuxX64()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonTest.dependencies {
|
||||||
|
implementation(libs.test)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes")
|
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,6 @@ kotlin = "2.1.20"
|
|||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||||
|
|||||||
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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/commonTest/kotlin/com/infendro/bytearray/Int.kt
Normal file
31
src/commonTest/kotlin/com/infendro/bytearray/Int.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.infendro.bytearray
|
||||||
|
|
||||||
|
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
|
|
||||||
|
class `Int Test` {
|
||||||
|
@Test
|
||||||
|
fun `toByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x12, 0x34, 0x56, 0x78),
|
||||||
|
0x12345678.toByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x78, 0x56, 0x34, 0x12),
|
||||||
|
0x12345678.toByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toUByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U),
|
||||||
|
0x12345678.toUByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U),
|
||||||
|
0x12345678.toUByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/commonTest/kotlin/com/infendro/bytearray/Long.kt
Normal file
31
src/commonTest/kotlin/com/infendro/bytearray/Long.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.infendro.bytearray
|
||||||
|
|
||||||
|
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
|
|
||||||
|
class `Long Test` {
|
||||||
|
@Test
|
||||||
|
fun `toByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78),
|
||||||
|
0x1234567812345678L.toByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12),
|
||||||
|
0x1234567812345678L.toByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toUByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U),
|
||||||
|
0x1234567812345678L.toUByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U),
|
||||||
|
0x1234567812345678L.toUByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/commonTest/kotlin/com/infendro/bytearray/UByteArray.kt
Normal file
87
src/commonTest/kotlin/com/infendro/bytearray/UByteArray.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 `UByteArray Test` {
|
||||||
|
@Test
|
||||||
|
fun `and() - size`() {
|
||||||
|
assertFails {
|
||||||
|
ubyteArrayOf() and ubyteArrayOf(0x00U)
|
||||||
|
}
|
||||||
|
assertFails {
|
||||||
|
ubyteArrayOf(0x00U) and ubyteArrayOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `padStart()`() {
|
||||||
|
val padded = ubyteArrayOf(0x02U, 0x02U).padStart(8, 0x01U)
|
||||||
|
assertEquals(8, padded.size)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x02U, 0x02U),
|
||||||
|
padded
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `padEnd()`() {
|
||||||
|
val padded = ubyteArrayOf(0x02U, 0x02U).padEnd(8, 0x01U)
|
||||||
|
assertEquals(8, padded.size)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x02U, 0x02U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U),
|
||||||
|
padded
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toInt()`() {
|
||||||
|
assertEquals(
|
||||||
|
0x12345678,
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U).toInt()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
0x12345678,
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U).toInt(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toLong()`() {
|
||||||
|
assertEquals(
|
||||||
|
0x1234567812345678L,
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U).toLong()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
0x1234567812345678L,
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U).toLong(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toUInt()`() {
|
||||||
|
assertEquals(
|
||||||
|
0x12345678U,
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U).toUInt()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
0x12345678U,
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U).toUInt(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toULong()`() {
|
||||||
|
assertEquals(
|
||||||
|
0x1234567812345678UL,
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U).toULong()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
0x1234567812345678UL,
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U).toULong(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/commonTest/kotlin/com/infendro/bytearray/UInt.kt
Normal file
31
src/commonTest/kotlin/com/infendro/bytearray/UInt.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.infendro.bytearray
|
||||||
|
|
||||||
|
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
|
|
||||||
|
class `UInt Test` {
|
||||||
|
@Test
|
||||||
|
fun `toByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x12, 0x34, 0x56, 0x78),
|
||||||
|
0x12345678U.toByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x78, 0x56, 0x34, 0x12),
|
||||||
|
0x12345678U.toByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toUByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U),
|
||||||
|
0x12345678U.toUByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U),
|
||||||
|
0x12345678U.toUByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/commonTest/kotlin/com/infendro/bytearray/ULong.kt
Normal file
31
src/commonTest/kotlin/com/infendro/bytearray/ULong.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.infendro.bytearray
|
||||||
|
|
||||||
|
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
|
|
||||||
|
class `ULong Test` {
|
||||||
|
@Test
|
||||||
|
fun `toByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78),
|
||||||
|
0x1234567812345678UL.toByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
byteArrayOf(0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12),
|
||||||
|
0x1234567812345678UL.toByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `toUByteArray()`() {
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U),
|
||||||
|
0x1234567812345678UL.toUByteArray()
|
||||||
|
)
|
||||||
|
assertContentEquals(
|
||||||
|
ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U),
|
||||||
|
0x1234567812345678UL.toUByteArray(LITTLE_ENDIAN)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user