implement tests

This commit is contained in:
2025-11-18 11:22:05 +01:00
parent 12344283f7
commit 9e4109c9f3
7 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package com.infendro.encoding
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `Base16 Test` {
val encoding: Encoding
get() = Base16
val `Hello World!` = ubyteArrayOf(
0x48U, 0x65U, 0x6cU, 0x6cU,
0x6fU, 0x20U, 0x57U, 0x6fU,
0x72U, 0x6cU, 0x64U, 0x21U,
)
@Test
fun `encode empty ByteArray`() {
val expected = ubyteArrayOf()
val actual = encoding.encode(ubyteArrayOf())
assertContentEquals(expected, actual)
}
@Test
fun `encode "Hello, World!"`() {
val expected = ubyteArrayOf(
0x34U, 0x38U, 0x36U, 0x35U, 0x36U, 0x63U, 0x36U, 0x63U,
0x36U, 0x66U, 0x32U, 0x30U, 0x35U, 0x37U, 0x36U, 0x66U,
0x37U, 0x32U, 0x36U, 0x63U, 0x36U, 0x34U, 0x32U, 0x31U,
)
val actual = encoding.encode(`Hello World!`)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,42 @@
package com.infendro.encoding
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `Base2 Test` {
val encoding: Encoding
get() = Base2
val `Hello World!` = ubyteArrayOf(
0x48U, 0x65U, 0x6cU, 0x6cU,
0x6fU, 0x20U, 0x57U, 0x6fU,
0x72U, 0x6cU, 0x64U, 0x21U,
)
@Test
fun `encode empty ByteArray`() {
val expected = ubyteArrayOf()
val actual = encoding.encode(ubyteArrayOf())
assertContentEquals(expected, actual)
}
@Test
fun `encode "Hello, World!"`() {
val expected = ubyteArrayOf(
0x30U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U,
0x30U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x31U,
0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U,
0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U,
0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U, 0x31U,
0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U,
0x30U, 0x31U, 0x30U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U,
0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U, 0x31U,
0x30U, 0x31U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U,
0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U,
0x30U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x30U,
0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, 0x30U, 0x31U,
)
val actual = encoding.encode(`Hello World!`)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,33 @@
package com.infendro.encoding
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `Base32 Test` {
val encoding: Encoding
get() = Base32
val `Hello World!` = ubyteArrayOf(
0x48U, 0x65U, 0x6cU, 0x6cU,
0x6fU, 0x20U, 0x57U, 0x6fU,
0x72U, 0x6cU, 0x64U, 0x21U,
)
@Test
fun `encode empty ByteArray`() {
val expected = ubyteArrayOf()
val actual = encoding.encode(ubyteArrayOf())
assertContentEquals(expected, actual)
}
@Test
fun `encode "Hello, World!"`() {
val expected = ubyteArrayOf(
0x4aU, 0x42U, 0x53U, 0x57U, 0x59U, 0x33U, 0x44U, 0x50U,
0x45U, 0x42U, 0x4cU, 0x57U, 0x36U, 0x34U, 0x54U, 0x4dU,
0x4dU, 0x51U, 0x51U, 0x51U, 0x3dU, 0x3dU, 0x3dU, 0x3dU,
)
val actual = encoding.encode(`Hello World!`)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,32 @@
package com.infendro.encoding
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `Base64 Test` {
val encoding: Encoding
get() = Base64
val `Hello World!` = ubyteArrayOf(
0x48U, 0x65U, 0x6cU, 0x6cU,
0x6fU, 0x20U, 0x57U, 0x6fU,
0x72U, 0x6cU, 0x64U, 0x21U,
)
@Test
fun `encode empty ByteArray`() {
val expected = ubyteArrayOf()
val actual = encoding.encode(ubyteArrayOf())
assertContentEquals(expected, actual)
}
@Test
fun `encode "Hello, World!"`() {
val expected = ubyteArrayOf(
0x53U, 0x47U, 0x56U, 0x73U, 0x62U, 0x47U, 0x38U, 0x67U,
0x56U, 0x32U, 0x39U, 0x79U, 0x62U, 0x47U, 0x51U, 0x68U,
)
val actual = encoding.encode(`Hello World!`)
assertContentEquals(expected, actual)
}
}

View File

@@ -0,0 +1,34 @@
package com.infendro.encoding
import kotlin.test.Test
import kotlin.test.assertContentEquals
class `Base8 Test` {
val encoding: Encoding
get() = Base8
val `Hello World!` = ubyteArrayOf(
0x48U, 0x65U, 0x6cU, 0x6cU,
0x6fU, 0x20U, 0x57U, 0x6fU,
0x72U, 0x6cU, 0x64U, 0x21U,
)
@Test
fun `encode empty ByteArray`() {
val expected = ubyteArrayOf()
val actual = encoding.encode(ubyteArrayOf())
assertContentEquals(expected, actual)
}
@Test
fun `encode "Hello, World!"`() {
val expected = ubyteArrayOf(
0x32U, 0x32U, 0x30U, 0x36U, 0x32U, 0x35U, 0x35U, 0x34U,
0x33U, 0x33U, 0x30U, 0x36U, 0x37U, 0x34U, 0x34U, 0x30U,
0x32U, 0x35U, 0x36U, 0x36U, 0x37U, 0x35U, 0x36U, 0x32U,
0x33U, 0x33U, 0x30U, 0x36U, 0x32U, 0x30U, 0x34U, 0x31U,
)
val actual = encoding.encode(`Hello World!`)
assertContentEquals(expected, actual)
}
}