Skip to content

Commit dcd0015

Browse files
committed
Update EncoderDecoderTest.kt
1 parent d74972a commit dcd0015

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

Codex/src/test/java/org/operatorfoundation/codex/EncoderDecoderTest.kt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ package org.operatorfoundation.codex
22

33
import org.junit.jupiter.api.Test
44
import org.junit.jupiter.api.Assertions.*
5-
import org.operatorfoundation.codex.symbols.*
5+
import org.operatorfoundation.codex.symbols.Symbol
6+
import org.operatorfoundation.codex.symbols.Number
7+
import org.operatorfoundation.codex.symbols.Byte
8+
import org.operatorfoundation.codex.symbols.Required
9+
import org.operatorfoundation.codex.symbols.CallLetterNumber
10+
import org.operatorfoundation.codex.symbols.CallLetterSpace
11+
import org.operatorfoundation.codex.symbols.GridLetter
12+
import org.operatorfoundation.codex.symbols.Power
13+
614
import java.math.BigInteger
715

816
class EncoderDecoderTest
@@ -38,4 +46,54 @@ class EncoderDecoderTest
3846
assertEquals("Test", reconstructedString)
3947
}
4048

49+
@Test
50+
fun testWSPREncoding() {
51+
// First get test integer from byte encoding
52+
val bytesDecoder = Decoder(listOf(Byte(), Byte(), Byte(), Byte()))
53+
val testByteArrays = "Test".toByteArray().map { byteArrayOf(it) }
54+
val testInteger = bytesDecoder.decode(testByteArrays)
55+
56+
// Create WSPR encoder - explicitly type as List<Symbol>
57+
val wsprEncoder = Encoder(listOf<Symbol>(
58+
Required('Q'.code.toByte()),
59+
CallLetterNumber(),
60+
Number(),
61+
CallLetterSpace(),
62+
CallLetterSpace(),
63+
CallLetterSpace(),
64+
GridLetter(),
65+
GridLetter(),
66+
Number(),
67+
Number(),
68+
Power()
69+
))
70+
71+
// Encode the integer
72+
val wsprEncoding = wsprEncoder.encode(testInteger)
73+
println(wsprEncoding.map { it.decodeToString() })
74+
75+
// Format output like Python
76+
val callsign = wsprEncoding.subList(0, 6).joinToString("") { it.decodeToString() }
77+
val grid = wsprEncoding.subList(6, 10).joinToString("") { it.decodeToString() }
78+
val power = wsprEncoding[10].decodeToString()
79+
80+
println("$callsign $grid $power")
81+
82+
// Verify decoding back to same integer
83+
val wsprDecoder = wsprEncoder.decoder()
84+
val decodedInteger = wsprDecoder.decode(wsprEncoding)
85+
println("$ i: $decodedInteger")
86+
87+
assertEquals(testInteger, decodedInteger)
88+
89+
// Encode back to bytes and verify
90+
val bytesEncoder = bytesDecoder.encoder()
91+
val finalBytes = bytesEncoder.encode(decodedInteger)
92+
val finalString = String(finalBytes.map { it[0] }.toByteArray())
93+
94+
println("% bs: ${finalBytes.map { it[0].toInt() and 0xFF }}, str: $finalString")
95+
96+
assertEquals("Test", finalString)
97+
}
98+
4199
}

0 commit comments

Comments
 (0)