diff --git a/src/commonTest/kotlin/com/infendro/bytearray/Int.kt b/src/commonTest/kotlin/com/infendro/bytearray/Int.kt index 356b847..453090f 100644 --- a/src/commonTest/kotlin/com/infendro/bytearray/Int.kt +++ b/src/commonTest/kotlin/com/infendro/bytearray/Int.kt @@ -7,25 +7,31 @@ import kotlin.test.assertContentEquals class `Int Test` { @Test fun `toByteArray()`() { - assertContentEquals( + val expected = arrayOf( byteArrayOf(0x12, 0x34, 0x56, 0x78), - 0x12345678.toByteArray() - ) - assertContentEquals( byteArrayOf(0x78, 0x56, 0x34, 0x12), - 0x12345678.toByteArray(LITTLE_ENDIAN) ) + val actual = arrayOf( + 0x12345678.toByteArray(), + 0x12345678.toByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } @Test fun `toUByteArray()`() { - assertContentEquals( + val expected = arrayOf( ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U), - 0x12345678.toUByteArray() - ) - assertContentEquals( ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U), - 0x12345678.toUByteArray(LITTLE_ENDIAN) ) + val actual = arrayOf( + 0x12345678.toUByteArray(), + 0x12345678.toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } } diff --git a/src/commonTest/kotlin/com/infendro/bytearray/IntArray.kt b/src/commonTest/kotlin/com/infendro/bytearray/IntArray.kt new file mode 100644 index 0000000..5663dcf --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/bytearray/IntArray.kt @@ -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]) + } + } +} diff --git a/src/commonTest/kotlin/com/infendro/bytearray/Long.kt b/src/commonTest/kotlin/com/infendro/bytearray/Long.kt index 0cba1b4..baf25a6 100644 --- a/src/commonTest/kotlin/com/infendro/bytearray/Long.kt +++ b/src/commonTest/kotlin/com/infendro/bytearray/Long.kt @@ -7,25 +7,31 @@ import kotlin.test.assertContentEquals class `Long Test` { @Test fun `toByteArray()`() { - assertContentEquals( + val expected = arrayOf( 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) ) + val actual = arrayOf( + 0x1234567812345678L.toByteArray(), + 0x1234567812345678L.toByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } @Test fun `toUByteArray()`() { - assertContentEquals( + val expected = arrayOf( 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) ) + val actual = arrayOf( + 0x1234567812345678L.toUByteArray(), + 0x1234567812345678L.toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } } diff --git a/src/commonTest/kotlin/com/infendro/bytearray/LongArray.kt b/src/commonTest/kotlin/com/infendro/bytearray/LongArray.kt new file mode 100644 index 0000000..169e3e1 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/bytearray/LongArray.kt @@ -0,0 +1,61 @@ +package com.infendro.bytearray + +import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `LongArray Test` { + @Test + fun `toByteArray()`() { + val expected = arrayOf( + byteArrayOf( + 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + ), + byteArrayOf( + 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, + 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, + ), + ) + val actual = arrayOf( + longArrayOf( + 0x1234567812345678L, + 0x1234567812345678L, + ).toByteArray(), + longArrayOf( + 0x1234567812345678L, + 0x1234567812345678L, + ).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, + 0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U, + ), + ubyteArrayOf( + 0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U, + 0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U, + ), + ) + val actual = arrayOf( + longArrayOf( + 0x1234567812345678L, + 0x1234567812345678L, + ).toUByteArray(), + longArrayOf( + 0x1234567812345678L, + 0x1234567812345678L, + ).toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } + } +} diff --git a/src/commonTest/kotlin/com/infendro/bytearray/UInt.kt b/src/commonTest/kotlin/com/infendro/bytearray/UInt.kt index cfdd28f..747769d 100644 --- a/src/commonTest/kotlin/com/infendro/bytearray/UInt.kt +++ b/src/commonTest/kotlin/com/infendro/bytearray/UInt.kt @@ -7,25 +7,31 @@ import kotlin.test.assertContentEquals class `UInt Test` { @Test fun `toByteArray()`() { - assertContentEquals( + val expected = arrayOf( byteArrayOf(0x12, 0x34, 0x56, 0x78), - 0x12345678U.toByteArray() - ) - assertContentEquals( byteArrayOf(0x78, 0x56, 0x34, 0x12), - 0x12345678U.toByteArray(LITTLE_ENDIAN) ) + val actual = arrayOf( + 0x12345678U.toByteArray(), + 0x12345678U.toByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } @Test fun `toUByteArray()`() { - assertContentEquals( + val expected = arrayOf( ubyteArrayOf(0x12U, 0x34U, 0x56U, 0x78U), - 0x12345678U.toUByteArray() - ) - assertContentEquals( ubyteArrayOf(0x78U, 0x56U, 0x34U, 0x12U), - 0x12345678U.toUByteArray(LITTLE_ENDIAN) ) + val actual = arrayOf( + 0x12345678U.toUByteArray(), + 0x12345678U.toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } } diff --git a/src/commonTest/kotlin/com/infendro/bytearray/UIntArray.kt b/src/commonTest/kotlin/com/infendro/bytearray/UIntArray.kt new file mode 100644 index 0000000..347344f --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/bytearray/UIntArray.kt @@ -0,0 +1,61 @@ +package com.infendro.bytearray + +import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `UIntArray 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( + uintArrayOf( + 0x12345678U, + 0x12345678U, + ).toByteArray(), + uintArrayOf( + 0x12345678U, + 0x12345678U, + ).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( + uintArrayOf( + 0x12345678U, + 0x12345678U, + ).toUByteArray(), + uintArrayOf( + 0x12345678U, + 0x12345678U, + ).toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } + } +} diff --git a/src/commonTest/kotlin/com/infendro/bytearray/ULong.kt b/src/commonTest/kotlin/com/infendro/bytearray/ULong.kt index e3e50f4..7543bd1 100644 --- a/src/commonTest/kotlin/com/infendro/bytearray/ULong.kt +++ b/src/commonTest/kotlin/com/infendro/bytearray/ULong.kt @@ -7,25 +7,31 @@ import kotlin.test.assertContentEquals class `ULong Test` { @Test fun `toByteArray()`() { - assertContentEquals( + val expected = arrayOf( 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) ) + val actual = arrayOf( + 0x1234567812345678UL.toByteArray(), + 0x1234567812345678UL.toByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } @Test fun `toUByteArray()`() { - assertContentEquals( + val expected = arrayOf( 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) ) + val actual = arrayOf( + 0x1234567812345678UL.toUByteArray(), + 0x1234567812345678UL.toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } } } diff --git a/src/commonTest/kotlin/com/infendro/bytearray/ULongArray.kt b/src/commonTest/kotlin/com/infendro/bytearray/ULongArray.kt new file mode 100644 index 0000000..94c423a --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/bytearray/ULongArray.kt @@ -0,0 +1,61 @@ +package com.infendro.bytearray + +import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `ULongArray Test` { + @Test + fun `toByteArray()`() { + val expected = arrayOf( + byteArrayOf( + 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + ), + byteArrayOf( + 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, + 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12, + ), + ) + val actual = arrayOf( + ulongArrayOf( + 0x1234567812345678UL, + 0x1234567812345678UL, + ).toByteArray(), + ulongArrayOf( + 0x1234567812345678UL, + 0x1234567812345678UL, + ).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, + 0x12U, 0x34U, 0x56U, 0x78U, 0x12U, 0x34U, 0x56U, 0x78U, + ), + ubyteArrayOf( + 0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U, + 0x78U, 0x56U, 0x34U, 0x12U, 0x78U, 0x56U, 0x34U, 0x12U, + ), + ) + val actual = arrayOf( + ulongArrayOf( + 0x1234567812345678UL, + 0x1234567812345678UL, + ).toUByteArray(), + ulongArrayOf( + 0x1234567812345678UL, + 0x1234567812345678UL, + ).toUByteArray(LITTLE_ENDIAN), + ) + for (i in 0..1) { + assertContentEquals(expected[i], actual[i]) + } + } +}