FC18: Moved write logic to steno grapher

This commit is contained in:
Willem Cazander 2025-08-24 20:17:40 +02:00
parent 586b5f9fe3
commit 4c7355b65d
8 changed files with 345 additions and 360 deletions

View file

@ -22,14 +22,6 @@
*/
package org.x4o.fc18;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.x4o.fc18.octal8.PrimordialOctal;
/**
* Tests FourCornerRecipe methods.
*
@ -38,73 +30,4 @@ import org.x4o.fc18.octal8.PrimordialOctal;
*/
public class FourCornerRecipeTest {
@Test
public void testSandWalker() throws Exception {
List<Integer> cdc = new ArrayList<>();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedSandWalkerX06(cdc, List.of(PrimordialOctal.PART_1));
});
List<PrimordialOctal> octalMine = new ArrayList<>();
for (int i=0;i<24;i++) {
octalMine.add(PrimordialOctal.PART_1);
}
FourCornerRecipe.embedSandWalkerX06(cdc, octalMine);
String res = FourCornerUnicodeDisplay.text().renderFromInt18(cdc);
Assertions.assertTrue(res.endsWith("PART_1PART_1"), "missing " + res);
}
@Test
public void testNCRValues() throws Exception {
List<Integer> cdcX06 = new ArrayList<>();
List<Integer> cdcX18 = new ArrayList<>();
BigInteger v1 = BigInteger.valueOf(123);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v1, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v1, BigInteger.ONE);
BigInteger v2 = BigInteger.valueOf(12345);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v2, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v2, BigInteger.ONE);
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertEquals("¹/₁₂₃¹/₁₂₃₄₅", resX06);
}
@Test
public void testNCRCount1024() throws Exception {
List<Integer> cdcX06 = new ArrayList<>();
List<Integer> cdcX18 = new ArrayList<>();
for (int x = 1; x <= 1025; x++) {
BigInteger v = BigInteger.valueOf(x);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v, BigInteger.ONE);
}
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertTrue(resX06.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX06);
Assertions.assertTrue(resX06.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX06);
Assertions.assertTrue(resX06.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX06);
Assertions.assertTrue(resX18.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX18);
Assertions.assertTrue(resX18.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX18);
Assertions.assertTrue(resX18.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX18);
}
@Test
public void testNCRMaxValue() throws Exception {
BigInteger maxValue = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
FourCornerRecipe.embedNCR1632FractionX06(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX06(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX06(maxValue, maxValue.add(BigInteger.ONE));
});
FourCornerRecipe.embedNCR1632FractionX18(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX18(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX18(maxValue, maxValue.add(BigInteger.ONE));
});
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2004-2014, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.fc18.zion7;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.x4o.fc18.FourCornerUnicodeDisplay;
import org.x4o.fc18.octal8.PrimordialOctal;
/**
* Tests four corner grapher parts.
*
* @author Willem Cazander
* @version 1.0 Aug 24, 2025
*/
public class StenoGrapherTest {
@Test
public void testSandWalker() throws Exception {
List<Integer> out = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(out);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeSandWalker(List.of(PrimordialOctal.PART_1));
});
List<PrimordialOctal> octalMine = new ArrayList<>();
for (int i=0;i<24;i++) {
octalMine.add(PrimordialOctal.PART_1);
}
writerX06.strobeSandWalker(octalMine);
String res = FourCornerUnicodeDisplay.text().renderFromInt18(out);
Assertions.assertTrue(res.endsWith("PART_1PART_1"), "missing " + res);
}
@Test
public void testNCRValues() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
BigInteger v1 = BigInteger.valueOf(123);
writerX06.strobeNCR1632(v1, BigInteger.ONE);
writerX18.strobeNCR1632(v1, BigInteger.ONE);
BigInteger v2 = BigInteger.valueOf(12345);
writerX06.strobeNCR1632(v2, BigInteger.ONE);
writerX18.strobeNCR1632(v2, BigInteger.ONE);
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(outX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(outX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertEquals("¹/₁₂₃¹/₁₂₃₄₅", resX06);
}
@Test
public void testNCRCount1024() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
for (int x = 1; x <= 1025; x++) {
BigInteger v = BigInteger.valueOf(x);
writerX06.strobeNCR1632(v, BigInteger.ONE);
writerX18.strobeNCR1632(v, BigInteger.ONE);
}
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(outX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(outX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertTrue(resX06.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX06);
Assertions.assertTrue(resX06.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX06);
Assertions.assertTrue(resX06.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX06);
Assertions.assertTrue(resX18.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX18);
Assertions.assertTrue(resX18.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX18);
Assertions.assertTrue(resX18.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX18);
}
@Test
public void testNCRMaxValue() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
BigInteger maxValue = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
writerX06.strobeNCR1632(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeNCR1632(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeNCR1632(maxValue, maxValue.add(BigInteger.ONE));
});
writerX18.strobeNCR1632(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX18.strobeNCR1632(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX18.strobeNCR1632(maxValue, maxValue.add(BigInteger.ONE));
});
}
}

View file

@ -36,7 +36,7 @@ import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
* @author Willem Cazander
* @version 1.0 Aug 4, 2025
*/
public class LexerInvalidTest {
public class StenoLexerInvalidTest {
@Test
public void testInvalid18Plus() throws Exception {

View file

@ -38,7 +38,7 @@ import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
* @author Willem Cazander
* @version 1.0 Jan 14, 2025
*/
public class LexerNCRTest {
public class StenoLexerNCRTest {
@Test
public void testNCRSmokeSignals() throws Exception {