FC18: Added failing unit test to fix some time later when need it work
This commit is contained in:
parent
e1d804b168
commit
dc0f9b2282
2 changed files with 137 additions and 43 deletions
|
|
@ -22,16 +22,21 @@
|
|||
*/
|
||||
package org.x4o.fc18.zion7;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import org.x4o.fc18.cake2.FourCornerDotCake;
|
||||
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
|
||||
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
|
||||
import org.x4o.fc18.octal8.PrimordialOctal;
|
||||
import org.x4o.fc18.octal8.PrimordialOctalOrangeJuice;
|
||||
import org.x4o.fc18.octal8.PrimordialOctalOrangeString;
|
||||
|
||||
/// Write steno for zion.
|
||||
///
|
||||
|
|
@ -40,29 +45,76 @@ import org.x4o.fc18.octal8.PrimordialOctalOrangeJuice;
|
|||
public class FourCornerZionStenoGrapher {
|
||||
|
||||
static public FourCornerZion7Candlelier writerX06(List<Integer> out) {
|
||||
return new FourCornerWriter(out, true);
|
||||
return new FourCornerWriter(v -> out.add(v), () -> {}, true);
|
||||
}
|
||||
|
||||
static public FourCornerZion7TempleScrolls writerX18(List<Integer> out) {
|
||||
return new FourCornerWriter(out, false);
|
||||
return new FourCornerWriter(v -> out.add(v), () -> {}, false);
|
||||
}
|
||||
|
||||
/*
|
||||
static public FourCornerZion7TempleScrolls writerX18PackedX8(OutputStream out) {
|
||||
class FourCornerPackedX8Encoder implements IntConsumer, Runnable {
|
||||
private List<Integer> data = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void accept(int value) {
|
||||
data.add(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PrimordialOctalOrangeString str = PrimordialOctalOrangeString.ioSmurfReadListX18(data);
|
||||
try {
|
||||
PrimordialOctalOrangeString.ioSmurfWriteStreamX8(out, str);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
FourCornerPackedX8Encoder encoder = new FourCornerPackedX8Encoder();
|
||||
return new FourCornerWriter(encoder, encoder, false);
|
||||
}
|
||||
*/
|
||||
|
||||
static public final class FourCornerWriter implements FourCornerZion7Candlelier,FourCornerZion7TempleScrolls {
|
||||
|
||||
private final List<Integer> out;
|
||||
private final IntConsumer out;
|
||||
private final Runnable outFlush;
|
||||
private final boolean isSixBit;
|
||||
|
||||
public FourCornerWriter(List<Integer> out,boolean isSixBit) {
|
||||
public FourCornerWriter(IntConsumer out, Runnable outFlush, boolean isSixBit) {
|
||||
this.out = Objects.requireNonNull(out);
|
||||
this.outFlush = Objects.requireNonNull(outFlush);
|
||||
this.isSixBit = isSixBit;
|
||||
}
|
||||
|
||||
private void outFlush() {
|
||||
outFlush.run();
|
||||
}
|
||||
|
||||
private void outAdd(int value) {
|
||||
out.accept(value);
|
||||
}
|
||||
|
||||
private void outAddAll(List<Integer> values) {
|
||||
int listSize = values.size();
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
outAdd(values.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeDocumentAlpha() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeDocumentOmega() {
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,7 +125,7 @@ public class FourCornerZionStenoGrapher {
|
|||
if (cakePoint > PrimordialOctalOrangeJuice.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("Cake point is larger than max value limit: 0x" + Integer.toHexString(cakePoint));
|
||||
}
|
||||
out.add(cakePoint);
|
||||
outAdd(cakePoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,6 +135,7 @@ public class FourCornerZionStenoGrapher {
|
|||
for (int i = 0; i < cakeSize; i++) {
|
||||
strobeWord(cakePoints.get(i));
|
||||
}
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -103,7 +156,7 @@ public class FourCornerZionStenoGrapher {
|
|||
}
|
||||
|
||||
if (isSixBit) {
|
||||
out.addAll(FCDotDEC2701DashPX0.ESC68_NCR.baklavaPointSequence());
|
||||
outAddAll(FCDotDEC2701DashPX0.ESC68_NCR.baklavaPointSequence());
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = numerator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
if (bankValue == 0 && i > 0) {
|
||||
|
|
@ -115,23 +168,23 @@ public class FourCornerZionStenoGrapher {
|
|||
int valueCSB = (bankValue >> 3) & 0b111;
|
||||
int valueLSB = (bankValue >> 0) & 0b111;
|
||||
if (pageMSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY01_AT.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY01_AT.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
|
||||
}
|
||||
if (pageLSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
|
||||
}
|
||||
if (valueMSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY03_BAR_V_LEFT.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY03_BAR_V_LEFT.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
|
||||
}
|
||||
if (valueCSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY04_BAR_UNDER.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY04_BAR_UNDER.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = denominator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
|
|
@ -144,25 +197,26 @@ public class FourCornerZionStenoGrapher {
|
|||
int valueCSB = (bankValue >> 3) & 0b111;
|
||||
int valueLSB = (bankValue >> 0) & 0b111;
|
||||
if (pageMSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY06_PERCENT.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY06_PERCENT.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
|
||||
}
|
||||
if (pageLSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY07_DOLLAR.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY07_DOLLAR.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
|
||||
}
|
||||
if (valueMSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY08_HASH.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY08_HASH.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
|
||||
}
|
||||
if (valueCSB > 0) {
|
||||
out.add(FCDotCDC1604DashP6.NY09_EQUALS.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY09_EQUALS.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
|
||||
outAdd(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
outFlush();
|
||||
return;
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
|
|
@ -171,7 +225,7 @@ public class FourCornerZionStenoGrapher {
|
|||
continue;
|
||||
}
|
||||
int cakePoint = FourCornerDotCake.FC_NCR1632_NUM.getStart() + bankValue + (i * 512);
|
||||
out.add(cakePoint);
|
||||
outAdd(cakePoint);
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = denominator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
|
|
@ -179,8 +233,9 @@ public class FourCornerZionStenoGrapher {
|
|||
continue;
|
||||
}
|
||||
int cakePoint = FourCornerDotCake.FC_NCR1632_DEN.getStart() + bankValue + (i * 512);
|
||||
out.add(cakePoint);
|
||||
outAdd(cakePoint);
|
||||
}
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -190,15 +245,16 @@ public class FourCornerZionStenoGrapher {
|
|||
if (!FourCornerZion7Petroglyphs.SAND_WORM_SIGN.contains(rhythm.size())) {
|
||||
throw new IllegalArgumentException("Sand walker rhythm is not 72 bit aligned: " + rhythm.size());
|
||||
}
|
||||
out.add(FCDotDEC2701DashPX0.ESC_SAND_WALKER.cakePointDotIndex());
|
||||
outAdd(FCDotDEC2701DashPX0.ESC_SAND_WALKER.cakePointDotIndex());
|
||||
for (int i = 192 - 1; i >= 0; i--) {
|
||||
if (rhythm.size() <= i) {
|
||||
continue;
|
||||
}
|
||||
PrimordialOctal octal = rhythm.get(i);
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
outFlush();
|
||||
return;
|
||||
//}
|
||||
// todo bring back native 18 bit sand walking if space allow (for adult rule)
|
||||
|
|
@ -208,12 +264,12 @@ public class FourCornerZionStenoGrapher {
|
|||
public void strobeSandWorm(List<PrimordialOctal> spice) {
|
||||
Objects.requireNonNull(spice);
|
||||
if (isSixBit) {
|
||||
out.add(FCDotDEC2701DashPX0.ESC68_SAND_WORM.cakePointDotIndex());
|
||||
outAdd(FCDotDEC2701DashPX0.ESC68_SAND_WORM.cakePointDotIndex());
|
||||
for (int i = spice.size(); i >= 0; i--) {
|
||||
PrimordialOctal octal = spice.get(i);
|
||||
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
|
||||
outAdd(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
|
||||
return;
|
||||
}
|
||||
Iterator<PrimordialOctal> spiceItr = spice.iterator();
|
||||
|
|
@ -229,8 +285,9 @@ public class FourCornerZionStenoGrapher {
|
|||
bitValue15 += (octal2.ordinal() << 6);
|
||||
bitValue15 += (octal1.ordinal() << 3);
|
||||
bitValue15 += (octal0.ordinal() << 0);
|
||||
out.add(FourCornerDotCake.FC_SANDWORM_15.getStart() + bitValue15);
|
||||
outAdd(FourCornerDotCake.FC_SANDWORM_15.getStart() + bitValue15);
|
||||
}
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -239,26 +296,27 @@ public class FourCornerZionStenoGrapher {
|
|||
Objects.requireNonNull(arguments);
|
||||
if (FourCornerZion7SalahSequence.ESC_VT06.equals(type)) {
|
||||
if (isSixBit) {
|
||||
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.baklavaPointSequence());
|
||||
outAddAll(FCDotDEC2701DashPX0.ESC_VT06.baklavaPointSequence());
|
||||
} else {
|
||||
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.cakePointSequence());
|
||||
outAddAll(FCDotDEC2701DashPX0.ESC_VT06.cakePointSequence());
|
||||
}
|
||||
} else {
|
||||
if (isSixBit) {
|
||||
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).baklavaPointSequence());
|
||||
outAddAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).baklavaPointSequence());
|
||||
} else {
|
||||
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).cakePointSequence());
|
||||
outAddAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).cakePointSequence());
|
||||
}
|
||||
}
|
||||
Iterator<List<Integer>> argu = arguments.iterator();
|
||||
while (argu.hasNext()) {
|
||||
List<Integer> arguValue = argu.next();
|
||||
out.addAll(arguValue); // TODO: add range check
|
||||
outAddAll(arguValue); // TODO: add range check
|
||||
if (argu.hasNext()) {
|
||||
out.add(FCDotCDC1604DashP6._RAKA_QUESTION.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6._RAKA_QUESTION.baklavaPointDotIndex());
|
||||
}
|
||||
}
|
||||
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.baklavaPointDotIndex());
|
||||
outAdd(FCDotCDC1604DashP6._SALAH_EXCLAMATION.baklavaPointDotIndex());
|
||||
outFlush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@
|
|||
*/
|
||||
package org.x4o.fc18.zion7;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -29,7 +34,9 @@ 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.cake2.flag4.FCDotF4TTY0001DashNL;
|
||||
import org.x4o.fc18.octal8.PrimordialOctal;
|
||||
import org.x4o.fc18.octal8.PrimordialOctalOrangeString;
|
||||
|
||||
/**
|
||||
* Tests four corner grapher parts.
|
||||
|
|
@ -73,6 +80,35 @@ public class StenoGrapherTest {
|
|||
Assertions.assertEquals("¹/₁₂₃¹/₁₂₃₄₅", resX06);
|
||||
}
|
||||
|
||||
//Test TODO: MOVE + fix java.io.IOException: Expected 9 bytes, got: 3 from PrimordialOctalOrangeString.ioSmurfReadStreamX8
|
||||
public void testNCRWriteFile() throws Exception {
|
||||
File testFile = new File("target/test-ncr.dat");
|
||||
try (OutputStream out = new FileOutputStream(testFile)) {
|
||||
//FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18PackedX8(out);
|
||||
List<Integer> outX18 = new ArrayList<>();
|
||||
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
|
||||
writerX18.strobeDocumentAlpha();
|
||||
for (int x = 1; x <= 1025 /*_999999*/; x++) {
|
||||
BigInteger v = BigInteger.valueOf(x);
|
||||
writerX18.strobeNCR1632(BigInteger.ONE, v);
|
||||
writerX18.strobeWord(FCDotF4TTY0001DashNL.NETHER_LINE.cakePointDotIndex());
|
||||
}
|
||||
writerX18.strobeDocumentOmega();
|
||||
PrimordialOctalOrangeString str = PrimordialOctalOrangeString.ioSmurfReadListX18(outX18);
|
||||
PrimordialOctalOrangeString.ioSmurfWriteStreamX8(out, str);
|
||||
}
|
||||
// todo test streaming read too
|
||||
try (InputStream in = new FileInputStream(testFile)) {
|
||||
PrimordialOctalOrangeString str = PrimordialOctalOrangeString.ioSmurfReadStreamX8(in);
|
||||
List<Integer> testX18 = new ArrayList<>();
|
||||
PrimordialOctalOrangeString.ioSmurfWriteListX18(testX18, str);
|
||||
String fileStr = FourCornerUnicodeDisplay.text().renderFromInt18(testX18);
|
||||
//System.out.println(fileStr);
|
||||
Assertions.assertFalse(fileStr.contains("burnNCR1632MissingBankSparkler"), "data error");
|
||||
}
|
||||
//testFile.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNCRCount1024() throws Exception {
|
||||
List<Integer> outX06 = new ArrayList<>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue