Added more smoke for NCR and test the big indian smoke reader

This commit is contained in:
Willem Cazander 2025-01-14 13:02:22 +01:00
parent b8139ebda0
commit d96e6e3e6e
3 changed files with 56 additions and 19 deletions

View file

@ -282,17 +282,20 @@ public class FourCornerZionStenoLexer {
private void handlePoints(List<Integer> slicedPoints) {
int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group
int numeratorBank[] = new int[64];
boolean fired = false;
boolean errorZeroSparks = true;
boolean errorUnusedSparks = true;
for (Integer cakePoint : slicedPoints) {
if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) {
int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart();
denominatorBank[denominatorX / 512] = denominatorX % 512;
errorUnusedSparks = true;
continue;
}
int numeratorX = cakePoint - FourCornerDotCake.FC_NCR1632_XN.getStart();
numeratorBank[numeratorX / 512] = numeratorX % 512;
if (cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStart() + 512) {
errorUnusedSparks = true;
continue; // Only fire fraction on lowest value select
}
BigInteger denominator = BigInteger.ONE;
@ -304,10 +307,15 @@ public class FourCornerZionStenoLexer {
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9));
}
handler.strobeNCR1632(denominator, numerator);
fired = true;
errorZeroSparks = false;
errorUnusedSparks = false;
}
if (smokeSignals != null) {
if (errorZeroSparks) {
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol);
} else if (errorUnusedSparks) {
smokeSignals.burnNCR1632UnusedSparks(currLine, currCol);
}
if (fired == false && smokeSignals != null) {
smokeSignals.burnInvalidNCR1632(currLine, currCol);
}
}
}

View file

@ -36,7 +36,9 @@ public interface FourCornerZionStenoLexerSmoke {
void burnInvalidEscape(int line, int col, int cakePoint);
void burnInvalidNCR1632(int line, int col);
void burnNCR1632ZeroSparks(int line, int col);
void burnNCR1632UnusedSparks(int line, int col);
interface Adapter extends FourCornerZionStenoLexerSmoke {
@ -57,7 +59,11 @@ public interface FourCornerZionStenoLexerSmoke {
}
@Override
default void burnInvalidNCR1632(int line, int col) {
default void burnNCR1632ZeroSparks(int line, int col) {
}
@Override
default void burnNCR1632UnusedSparks(int line, int col) {
}
}
}

View file

@ -22,7 +22,6 @@
*/
package org.x4o.o2o.fc18.zion7;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -30,9 +29,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.x4o.o2o.fc18.FourCornerDotCake;
import org.x4o.o2o.fc18.FourCornerUnicodeDisplay;
import org.x4o.o2o.fc18.FourCornerUnicodeImport;
import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints;
import org.x4o.o2o.fc18.pie9c.FCDotPIE9CDash26;
import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6;
import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
@ -44,22 +41,48 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
*/
public class LexerNCRTest {
int errorLine = -1;
SmokeReader SMOKE_READER = new SmokeReader();
class SmokeReader implements FourCornerZionStenoLexerSmoke.Adapter {
int errorNCRZeroSparks = -1;
int errorNCRUnusedSparks = -1;
public void reset() {
errorNCRZeroSparks = -1;
errorNCRUnusedSparks = -1;
}
@Override
public void burnNCR1632ZeroSparks(int line, int col) {
errorNCRZeroSparks = line;
}
@Override
public void burnNCR1632UnusedSparks(int line, int col) {
errorNCRUnusedSparks = line;
}
};
@Test
public void testNCRInvalid() throws Exception {
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
lexer.withSmokeSignals(SMOKE_READER);
List<Integer> cdc = new ArrayList<>();
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1);
//cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
lexer.withSmokeSignals(new FourCornerZionStenoLexerSmoke.Adapter() {
@Override
public void burnInvalidNCR1632(int line, int col) {
errorLine = line;
}
}).read(cdc);
Assertions.assertEquals(0, errorLine);
SMOKE_READER.reset();
lexer.read(cdc);
Assertions.assertEquals(-1, SMOKE_READER.errorNCRUnusedSparks);
Assertions.assertEquals(0, SMOKE_READER.errorNCRZeroSparks);
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2);
SMOKE_READER.reset();
lexer.read(cdc);
Assertions.assertEquals(0, SMOKE_READER.errorNCRUnusedSparks);
Assertions.assertEquals(-1, SMOKE_READER.errorNCRZeroSparks);
}
@Test