@@ -2,6 +2,7 @@ package org.operatorfoundation.codex
22
33import org.junit.jupiter.api.Test
44import org.junit.jupiter.api.Assertions.*
5+ import org.operatorfoundation.codex.symbols.Binary
56import org.operatorfoundation.codex.symbols.Symbol
67import org.operatorfoundation.codex.symbols.Number
78import org.operatorfoundation.codex.symbols.Byte
@@ -10,6 +11,7 @@ import org.operatorfoundation.codex.symbols.CallLetterNumber
1011import org.operatorfoundation.codex.symbols.CallLetterSpace
1112import org.operatorfoundation.codex.symbols.GridLetter
1213import org.operatorfoundation.codex.symbols.Power
14+ import org.operatorfoundation.codex.symbols.Trinary
1315
1416import java.math.BigInteger
1517
@@ -96,4 +98,81 @@ class EncoderDecoderTest
9698 assertEquals(" Test" , finalString)
9799 }
98100
101+ @Test
102+ fun testBinaryTrinaryWithRequired ()
103+ {
104+ // Test with Required('A'), Binary(), Trinary()
105+ val encoder = Encoder (listOf (Required (' A' .code.toByte()), Binary (), Trinary ()))
106+
107+ val testCases = listOf (
108+ 0 to listOf (" A" , " 0" , " 0" ),
109+ 1 to listOf (" A" , " 0" , " 1" ),
110+ 2 to listOf (" A" , " 0" , " 2" ),
111+ 3 to listOf (" A" , " 1" , " 0" ),
112+ 4 to listOf (" A" , " 1" , " 1" ),
113+ 5 to listOf (" A" , " 1" , " 2" )
114+ )
115+
116+ testCases.forEach { (input, expected) ->
117+ val encoding = encoder.encode(BigInteger .valueOf(input.toLong()))
118+ val actual = encoding.map { it.decodeToString() }
119+
120+ println (" TEST RESULT input: $input , encoding: $actual " )
121+
122+ assertEquals(expected, actual)
123+ }
124+ }
125+
126+ @Test
127+ fun testBinaryTrinaryWithoutRequired ()
128+ {
129+ // Test with just Binary(), Trinary()
130+ val encoder = Encoder (listOf (Binary (), Trinary ()))
131+
132+ val testCases = listOf (
133+ 0 to listOf (" 0" , " 0" ),
134+ 1 to listOf (" 0" , " 1" ),
135+ 2 to listOf (" 0" , " 2" ),
136+ 3 to listOf (" 1" , " 0" ),
137+ 4 to listOf (" 1" , " 1" ),
138+ 5 to listOf (" 1" , " 2" )
139+ )
140+
141+ testCases.forEach { (input, expected) ->
142+ val encoding = encoder.encode(BigInteger .valueOf(input.toLong()))
143+ val actual = encoding.map { it.decodeToString() }
144+
145+ println (" TEST RESULT input: $input , encoding: $actual " )
146+
147+ assertEquals(expected, actual)
148+ }
149+ }
150+
151+ @Test
152+ fun testRoundTrip ()
153+ {
154+ // Test that encoding then decoding returns the original value
155+ val symbols = listOf (
156+ CallLetterNumber (),
157+ Binary (),
158+ Trinary (),
159+ Number (),
160+ CallLetterSpace ()
161+ )
162+
163+ val encoder = Encoder (symbols)
164+ val decoder = encoder.decoder()
165+
166+ // Test various values
167+ val testValues = listOf (0 , 1 , 42 , 100 , 500 , 1000 , 5000 )
168+
169+ testValues.forEach { value ->
170+ val bigIntValue = BigInteger .valueOf(value.toLong())
171+ val encoded = encoder.encode(bigIntValue)
172+ val decoded = decoder.decode(encoded)
173+
174+ assertEquals(bigIntValue, decoded, " Round-trip failed for value $value " )
175+ }
176+ }
177+
99178}
0 commit comments