This commit is contained in:
13
src/commonTest/kotlin/com/infendro/bytes/byte/Operator.kt
Normal file
13
src/commonTest/kotlin/com/infendro/bytes/byte/Operator.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.infendro.bytes.byte
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ByteOperatorTest {
|
||||
@Test
|
||||
fun not() {
|
||||
val expected = (-0x01).toByte()
|
||||
val actual = !0x00.toByte()
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,19 @@ class ByteArrayConversionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyIntoIntArray() {
|
||||
val expected = intArrayOf(0, 0x01234567, 0x01234567)
|
||||
val actual = IntArray(3).also { array ->
|
||||
val bytes = byteArrayOf(
|
||||
0x01, 0x23, 0x45, 0x67,
|
||||
0x01, 0x23, 0x45, 0x67,
|
||||
)
|
||||
bytes.copyInto(array, 1)
|
||||
}
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toIntArray() {
|
||||
val expected = intArrayOf(0x01234567, 0x67452301)
|
||||
@@ -51,6 +64,19 @@ class ByteArrayConversionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun copyIntoLongArray() {
|
||||
val expected = longArrayOf(0, 0x0123456789abcdefL, 0x0123456789abcdefL)
|
||||
val actual = LongArray(3).also { array ->
|
||||
val bytes = byteArrayOf(
|
||||
0x01, 0x23, 0x45, 0x67, -0x77, -0x55, -0x33, -0x11,
|
||||
0x01, 0x23, 0x45, 0x67, -0x77, -0x55, -0x33, -0x11,
|
||||
)
|
||||
bytes.copyInto(array, 1)
|
||||
}
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toLongArray() {
|
||||
val expected = longArrayOf(0x0123456789abcdefL, -0x1032547698badcffL)
|
||||
|
||||
@@ -11,6 +11,13 @@ class ByteArrayOperatorTest {
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun andByte() {
|
||||
val expected = byteArrayOf(0x0C, 0x00)
|
||||
val actual = byteArrayOf(0x5C, 0x70) and 0x0F
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun or() {
|
||||
val expected = byteArrayOf(0x7E, 0x7F)
|
||||
@@ -18,6 +25,13 @@ class ByteArrayOperatorTest {
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun orByte() {
|
||||
val expected = byteArrayOf(0x5F, 0x7F)
|
||||
val actual = byteArrayOf(0x5C, 0x70) or 0x0F
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xor() {
|
||||
val expected = byteArrayOf(0x66, 0x7F)
|
||||
@@ -25,6 +39,13 @@ class ByteArrayOperatorTest {
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun xorByte() {
|
||||
val expected = byteArrayOf(0x53, 0x7F)
|
||||
val actual = byteArrayOf(0x5C, 0x70) xor 0x0F
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun not() {
|
||||
val expected = byteArrayOf(-0x01, -0x20)
|
||||
|
||||
13
src/commonTest/kotlin/com/infendro/bytes/int/Operator.kt
Normal file
13
src/commonTest/kotlin/com/infendro/bytes/int/Operator.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.infendro.bytes.int
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class IntOperatorTest {
|
||||
@Test
|
||||
fun not() {
|
||||
val expected = -0x00000001
|
||||
val actual = !0x00000000
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
13
src/commonTest/kotlin/com/infendro/bytes/long/Operator.kt
Normal file
13
src/commonTest/kotlin/com/infendro/bytes/long/Operator.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.infendro.bytes.long
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class LongOperatorTest {
|
||||
@Test
|
||||
fun not() {
|
||||
val expected = -0x0000000000000001L
|
||||
val actual = !0x0000000000000000L
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user