Created four corner package and prefixed classes

This commit is contained in:
Willem Cazander 2024-12-27 11:08:49 +01:00
parent 7f0d942b2a
commit 3de5ba5569
8 changed files with 236 additions and 204 deletions

View file

@ -29,7 +29,7 @@ a smurf village and lego bricks.
* Local laser pointers [BãßBȍőnSpiderTest](nx01-jpp-base/src/test/java/ᒢᐩᐩ/ᒃᣔᔆᔆᒃᐤᐤᣕ/ᒄᓫᣔᐪᑋ/ᔆᣖᑊᒄᓫᣗ/BãßBȍőnSpiderTest.java)
* Lego stair way [LegoBrickStairWay](nx01-jpp-base/src/main/java/ᒢᐩᐩ/ᒡᒢᑊᒻᒻᓫᔿ/ᣳᣝᐤᣜᣳ/ᒢᓫᑊᐣᑊ/LegoBrickStairWay.java)
* LegoᐧBrickᐧTapeᐧReplicatorᐧχ3 [LegoBrickTapeStudio](nx01-jpp-base/src/main/java/ᒢᐩᐩ/ᒡᒢᑊᒻᒻᓫᔿ/ᣳᣝᐤᣜᣳ/ᒢᓫᑊᐣᑊ/LegoBrickTapeStudio.java)
* Enterprise mainframe text [CDC1604DashP6](nx01-x4o-o2o/src/main/java/org/x4o/o2o/CDC1604DashP6.java)
* Enterprise mainframe text [FCDotCDC1604DashP6](nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FCDotCDC1604DashP6.java)
## Code of Conduct

View file

@ -54,7 +54,7 @@ public enum WarpManifestTheVersion {
// TODO: Format: SAX3 binary 8 bit XDBX XML with unicode manifest data
// VERSION_5_0
// TODO: Format: SAX4 binary adult 18 bit XML with manifest in 4C, but tags/attr in CDC1604DashP6
// TODO: Format: SAX4 binary adult 18 bit XML with manifest in 4C, but tags/attr in FCDotCDC1604DashP6
// VERSION_6_0
// TODO: Format: SAX4 binary adult 18 bit XML with manifest data and XML structure in 4C

View file

@ -20,7 +20,7 @@
* 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.o2o;
package org.x4o.o2o.fc18;
import java.util.ArrayList;
import java.util.Iterator;
@ -28,7 +28,7 @@ import java.util.List;
import java.util.PrimitiveIterator;
///
/// CDC1604DashP6 has 27 pie slice number systems "Packed" for MATH and BASIC letters in a "Six" bit encoding.
/// "FC.CDC1604-P6" has 27 pie slice number systems "Packed" for MATH and BASIC letters in a "Six" bit encoding.
///
/// This is used as the first 64 word numbers of the china four corner method, and acts like ascii glue for adult 18 bit computers.
///
@ -40,7 +40,7 @@ import java.util.PrimitiveIterator;
/// @author Willem Cazander
/// @version 1.0 Dec 22, 2024
///
public enum CDC1604DashP6 {
public enum FCDotCDC1604DashP6 {
// [__NUL][__PIE][__GLUE][__ESC] [__LINE][__SPACE]?! {[(< }])>
// ~+-* ,.:; '"`^ =#$%
// |_\/ @ABC DEFG HIJK
@ -131,11 +131,11 @@ public enum CDC1604DashP6 {
private final byte codePointLower;
private final String aliases;
private CDC1604DashP6(char codePoint) {
private FCDotCDC1604DashP6(char codePoint) {
this(codePoint, null);
}
private CDC1604DashP6(char codePoint, String aliases) {
private FCDotCDC1604DashP6(char codePoint, String aliases) {
this.codePoint = (byte) codePoint;
this.codePointLower = (byte) Character.toLowerCase(codePoint);
this.aliases = aliases;
@ -149,24 +149,24 @@ public enum CDC1604DashP6 {
return codePoint;
}
static public List<CDC1604DashP6> convertFromUnicode(String text) {
static public List<FCDotCDC1604DashP6> convertFromUnicode(String text) {
return convertFromUnicode(text, false);
}
static public List<CDC1604DashP6> convertFromUnicode(String text, boolean strict) {
static public List<FCDotCDC1604DashP6> convertFromUnicode(String text, boolean strict) {
String textSingleNewLines = text.replaceAll("\r\n", "\n");
PrimitiveIterator.OfInt i = textSingleNewLines.codePoints().iterator();
List<CDC1604DashP6> result = new ArrayList<>(text.length());
CDC1604DashP6[] cdcChars = values();
CDC1604DashP6 cdcNumberTerminator = null;
List<FCDotCDC1604DashP6> result = new ArrayList<>(text.length());
FCDotCDC1604DashP6[] cdcChars = values();
FCDotCDC1604DashP6 cdcNumberTerminator = null;
while (i.hasNext()) {
int codePoint = i.next();
boolean found = false;
if ('\r' == codePoint) {
result.add(CDC1604DashP6.__LINE);
result.add(FCDotCDC1604DashP6.__LINE);
continue;
}
for (CDC1604DashP6 v : cdcChars) {
for (FCDotCDC1604DashP6 v : cdcChars) {
if (v.codePoint == codePoint) {
result.add(v);
found = true;
@ -174,31 +174,31 @@ public enum CDC1604DashP6 {
break;
}
if ('0' == codePoint) {
if (!CDC1604DashP6.NX01_A.equals(cdcNumberTerminator)) {
result.add(CDC1604DashP6.__PIE);
result.add(CDC1604DashP6.NX01_A);
cdcNumberTerminator = CDC1604DashP6.NX01_A;
if (!FCDotCDC1604DashP6.NX01_A.equals(cdcNumberTerminator)) {
result.add(FCDotCDC1604DashP6.__PIE);
result.add(FCDotCDC1604DashP6.NX01_A);
cdcNumberTerminator = FCDotCDC1604DashP6.NX01_A;
}
result.add(CDC1604DashP6.NX01_A);
result.add(FCDotCDC1604DashP6.NX01_A);
found = true;
break;
}
if (codePoint >= '1' && codePoint <= '9') {
if (!CDC1604DashP6.NX09_I.equals(cdcNumberTerminator)) {
result.add(CDC1604DashP6.__PIE);
result.add(CDC1604DashP6.NX09_I);
cdcNumberTerminator = CDC1604DashP6.NX09_I;
if (!FCDotCDC1604DashP6.NX09_I.equals(cdcNumberTerminator)) {
result.add(FCDotCDC1604DashP6.__PIE);
result.add(FCDotCDC1604DashP6.NX09_I);
cdcNumberTerminator = FCDotCDC1604DashP6.NX09_I;
}
int cdcNumberOff = codePoint - '1'; // 0 = 1
int cdcNumber = CDC1604DashP6.NX01_A.ordinal() + cdcNumberOff;
result.add(CDC1604DashP6.values()[cdcNumber]);
int cdcNumber = FCDotCDC1604DashP6.NX01_A.ordinal() + cdcNumberOff;
result.add(FCDotCDC1604DashP6.values()[cdcNumber]);
found = true;
break;
}
}
if (!found && !strict) {
String codePointStr = Character.toString(codePoint);
for (CDC1604DashP6 v : cdcChars) {
for (FCDotCDC1604DashP6 v : cdcChars) {
if (v.codePointLower == codePoint) {
result.add(v);
found = true;
@ -223,38 +223,38 @@ public enum CDC1604DashP6 {
return result;
}
static public String convertToUnicode(List<CDC1604DashP6> cdcChars) {
static public String convertToUnicode(List<FCDotCDC1604DashP6> cdcChars) {
StringBuilder buf = new StringBuilder();
Iterator<CDC1604DashP6> cdc = cdcChars.iterator();
CDC1604DashP6 numberMode = null;
Iterator<FCDotCDC1604DashP6> cdc = cdcChars.iterator();
FCDotCDC1604DashP6 numberMode = null;
while (cdc.hasNext()) {
CDC1604DashP6 cdcPoint = cdc.next();
FCDotCDC1604DashP6 cdcPoint = cdc.next();
if (numberMode != null && (cdcPoint.ordinal() > numberMode.ordinal())) {
numberMode = null; // out of range
}
if (numberMode != null && (cdcPoint.ordinal() < CDC1604DashP6.NX01_A.ordinal())) {
if (numberMode != null && (cdcPoint.ordinal() < FCDotCDC1604DashP6.NX01_A.ordinal())) {
numberMode = null; // below index 1 is end number mode
}
if (CDC1604DashP6.__PIE.equals(cdcPoint)) {
if (FCDotCDC1604DashP6.__PIE.equals(cdcPoint)) {
if (!cdc.hasNext()) {
break;
}
numberMode = cdc.next();
if (numberMode.ordinal() < CDC1604DashP6.NX01_A.ordinal()) {
if (numberMode.ordinal() < FCDotCDC1604DashP6.NX01_A.ordinal()) {
cdcPoint = numberMode; // print char
numberMode = null; // illegal number mode
} else {
continue;
}
}
if (CDC1604DashP6.__GLUE.equals(cdcPoint)) {
if (FCDotCDC1604DashP6.__GLUE.equals(cdcPoint)) {
continue;
}
if (numberMode == null) {
buf.appendCodePoint(cdcPoint.asciiByte());
} else {
int terminatorNum = numberMode.ordinal() - CDC1604DashP6.NX01_A.ordinal() + 1;
int valueNumber = cdcPoint.ordinal() - CDC1604DashP6.NX01_A.ordinal();
int terminatorNum = numberMode.ordinal() - FCDotCDC1604DashP6.NX01_A.ordinal() + 1;
int valueNumber = cdcPoint.ordinal() - FCDotCDC1604DashP6.NX01_A.ordinal();
appendTerminatorNumber(buf, terminatorNum, valueNumber);
}
}

View file

@ -20,21 +20,23 @@
* 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.o2o;
package org.x4o.o2o.fc18;
/**
* Direct Escaped Control of text terminal with CDC1604DashP6 code points. (TODO: currently empty)
* "FC.DEC1604-E2" Four Corner dot Direct or Escaped Control in grid of 16 by 04 of dashed Escape codes V2.
*
* This block defines "start" points of different escape sequence data-gram encoding within the 6 bit space.
*
* A 6 or 8 bit computer use the CDC1604DashP6.__ESC to use these 64 control codes.
* A 6 or 8 bit computer use the __ESC to use these 64 control codes.
*
* A 18 or 144 bit computer uses this direct as the second 64 part page. (thus number 64 to 127)
*
* NOTE: TODO: Currently still all undefined, until time for see below todos.
*
* @author Willem Cazander
* @version 1.0 Dec 24, 2024
*/
public enum CDC1604DashP6DEC {
public enum FCDotDEC1604DashE2 {
RESERVED___NUL,
RESERVED___PIE,
RESERVED___GLUE,
@ -129,6 +131,6 @@ public enum CDC1604DashP6DEC {
// On 18 bit P6DEC system with takes TAG_ANSI_UPPER+__PIE+NX09_I+NX01_A
;
private CDC1604DashP6DEC() {
private FCDotDEC1604DashE2() {
}
}

View file

@ -0,0 +1,30 @@
/*
* 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.
*/
/**
* 18 bit Four Corner enterprise number and text encoding.
*
*
* @since 1.0
*/
package org.x4o.o2o.fc18;

View file

@ -24,7 +24,7 @@ package org.x4o.o2o.io.sax4;
import java.util.Objects;
import org.x4o.o2o.CDC1604DashP6;
import org.x4o.o2o.fc18.FCDotCDC1604DashP6;
import org.x4o.o2o.octal.PrimordialOctalOrangeJuice;
import org.x4o.o2o.octal.PrimordialOctalOrangeSexWord;
@ -36,27 +36,27 @@ import org.x4o.o2o.octal.PrimordialOctalOrangeSexWord;
*/
public enum X4ContentFrameTag {
DOCUMENT_END(CDC1604DashP6.NX27_AMPERSAND),
ELEMENT_END(CDC1604DashP6.NX26_Z),
DOCUMENT_END(FCDotCDC1604DashP6.NX27_AMPERSAND),
ELEMENT_END(FCDotCDC1604DashP6.NX26_Z),
ELEMENT_II(CDC1604DashP6.NX05_E),
ELEMENT_SI(CDC1604DashP6.NX24_X),
ELEMENT_II(FCDotCDC1604DashP6.NX05_E),
ELEMENT_SI(FCDotCDC1604DashP6.NX24_X),
ATTRIBUTE_II(CDC1604DashP6.NX01_A),
ATTRIBUTE_SI(CDC1604DashP6.NX02_B),
ATTRIBUTE_II(FCDotCDC1604DashP6.NX01_A),
ATTRIBUTE_SI(FCDotCDC1604DashP6.NX02_B),
NS_DECL_II(CDC1604DashP6.NX13_M),
NS_SCHEMA_SI(CDC1604DashP6.NX14_N),
NS_DECL_II(FCDotCDC1604DashP6.NX13_M),
NS_SCHEMA_SI(FCDotCDC1604DashP6.NX14_N),
CHARACTERS(CDC1604DashP6.NX20_T),
COMMENT(CDC1604DashP6.NX03_C),
CHARACTERS(FCDotCDC1604DashP6.NX20_T),
COMMENT(FCDotCDC1604DashP6.NX03_C),
STRING_ID(CDC1604DashP6.NX09_I),
STRING_ID(FCDotCDC1604DashP6.NX09_I),
;
private final PrimordialOctalOrangeJuice tagNumber;
private X4ContentFrameTag(CDC1604DashP6 tag) {
private X4ContentFrameTag(FCDotCDC1604DashP6 tag) {
this(PrimordialOctalOrangeSexWord.valueOfSmurf(tag.ordinal()));
}

View file

@ -1,150 +0,0 @@
/*
* 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.o2o;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Tests CDC1604DashP6 encoding.
*
* @author Willem Cazander
* @version 1.0 Dec 23, 2024
*/
public class CDC1604DashP6Test {
@Test
public void testValues() throws Exception {
Assertions.assertEquals(64, CDC1604DashP6.values().length);
boolean duplicate = false;
Map<Byte,CDC1604DashP6> global = new HashMap<>();
for (CDC1604DashP6 v : CDC1604DashP6.values()) {
Assertions.assertNotNull(v);
if (global.containsKey(v.asciiByte())) {
duplicate = true;
break;
}
global.put(v.asciiByte(), v);
}
Assertions.assertTrue(global.size() > 1);
Assertions.assertFalse(duplicate, "Duplicate ascii core value detected");
}
@Test
public void testAsciiSimple() throws Exception {
List<CDC1604DashP6> cdc = CDC1604DashP6.convertFromUnicode("foobar");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(6, cdc.size());
Assertions.assertEquals(CDC1604DashP6.NX06_F, cdc.get(0));
Assertions.assertEquals(CDC1604DashP6.NX15_O, cdc.get(1));
Assertions.assertEquals(CDC1604DashP6.NX15_O, cdc.get(2));
Assertions.assertEquals(CDC1604DashP6.NX02_B, cdc.get(3));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(4));
Assertions.assertEquals(CDC1604DashP6.NX18_R, cdc.get(5));
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("FOOBAR", out);
}
@Test
public void testNumber012() throws Exception {
List<CDC1604DashP6> cdc = CDC1604DashP6.convertFromUnicode("01201337");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(16, cdc.size());
Assertions.assertEquals(CDC1604DashP6.__PIE, cdc.get(0));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(1));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(2)); // 0
Assertions.assertEquals(CDC1604DashP6.__PIE, cdc.get(3));
Assertions.assertEquals(CDC1604DashP6.NX09_I, cdc.get(4));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(5)); // 1
Assertions.assertEquals(CDC1604DashP6.NX02_B, cdc.get(6)); // 2
Assertions.assertEquals(CDC1604DashP6.__PIE, cdc.get(7));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(8));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(9)); // 0
Assertions.assertEquals(CDC1604DashP6.__PIE, cdc.get(10));
Assertions.assertEquals(CDC1604DashP6.NX09_I, cdc.get(11));
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(12)); // 1
Assertions.assertEquals(CDC1604DashP6.NX03_C, cdc.get(13)); // 3
Assertions.assertEquals(CDC1604DashP6.NX03_C, cdc.get(14)); // 3
Assertions.assertEquals(CDC1604DashP6.NX07_G, cdc.get(15)); // 7
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("01201337", out);
}
@Test
public void testNumberTerminatorOutOfRange() throws Exception {
List<CDC1604DashP6> cdc = new ArrayList<>();
cdc.add(CDC1604DashP6.NX24_X); // = X
cdc.add(CDC1604DashP6.__PIE);
cdc.add(CDC1604DashP6._CARET); // ^
cdc.add(CDC1604DashP6._PERCENT); // = %
cdc.add(CDC1604DashP6.__PIE);
cdc.add(CDC1604DashP6._AT);
cdc.add(CDC1604DashP6.NX11_K); // = K
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("X^%@K", out);
}
@Test
public void testNumberPieOutOfRange() throws Exception {
List<CDC1604DashP6> cdc = new ArrayList<>();
cdc.add(CDC1604DashP6.__PIE);
cdc.add(CDC1604DashP6.NX01_A);
cdc.add(CDC1604DashP6.NX02_B); // = B
cdc.add(CDC1604DashP6.__PIE);
cdc.add(CDC1604DashP6.NX09_I);
cdc.add(CDC1604DashP6.NX03_C); // = 3
cdc.add(CDC1604DashP6.NX10_J); // = J
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("B3J", out);
}
@Test
public void testLineEndings() throws Exception {
List<CDC1604DashP6> cdc = CDC1604DashP6.convertFromUnicode("A\nB\rC\r\nD\n");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(8, cdc.size());
Assertions.assertEquals(CDC1604DashP6.NX01_A, cdc.get(0));
Assertions.assertEquals(CDC1604DashP6.__LINE, cdc.get(1));
Assertions.assertEquals(CDC1604DashP6.NX02_B, cdc.get(2));
Assertions.assertEquals(CDC1604DashP6.__LINE, cdc.get(3));
Assertions.assertEquals(CDC1604DashP6.NX03_C, cdc.get(4));
Assertions.assertEquals(CDC1604DashP6.__LINE, cdc.get(5));
Assertions.assertEquals(CDC1604DashP6.NX04_D, cdc.get(6));
Assertions.assertEquals(CDC1604DashP6.__LINE, cdc.get(7));
String out = CDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("A\nB\nC\nD\n", out);
}
}

View file

@ -0,0 +1,150 @@
/*
* 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.o2o.fc18;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Tests FCDotCDC1604DashP6 encoding.
*
* @author Willem Cazander
* @version 1.0 Dec 23, 2024
*/
public class FCDotCDC1604DashP6Test {
@Test
public void testValues() throws Exception {
Assertions.assertEquals(64, FCDotCDC1604DashP6.values().length);
boolean duplicate = false;
Map<Byte,FCDotCDC1604DashP6> global = new HashMap<>();
for (FCDotCDC1604DashP6 v : FCDotCDC1604DashP6.values()) {
Assertions.assertNotNull(v);
if (global.containsKey(v.asciiByte())) {
duplicate = true;
break;
}
global.put(v.asciiByte(), v);
}
Assertions.assertTrue(global.size() > 1);
Assertions.assertFalse(duplicate, "Duplicate ascii core value detected");
}
@Test
public void testAsciiSimple() throws Exception {
List<FCDotCDC1604DashP6> cdc = FCDotCDC1604DashP6.convertFromUnicode("foobar");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(6, cdc.size());
Assertions.assertEquals(FCDotCDC1604DashP6.NX06_F, cdc.get(0));
Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(1));
Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(2));
Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(3));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(4));
Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(5));
String out = FCDotCDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("FOOBAR", out);
}
@Test
public void testNumber012() throws Exception {
List<FCDotCDC1604DashP6> cdc = FCDotCDC1604DashP6.convertFromUnicode("01201337");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(16, cdc.size());
Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(0));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(1));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(2)); // 0
Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(3));
Assertions.assertEquals(FCDotCDC1604DashP6.NX09_I, cdc.get(4));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(5)); // 1
Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(6)); // 2
Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(7));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(8));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(9)); // 0
Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(10));
Assertions.assertEquals(FCDotCDC1604DashP6.NX09_I, cdc.get(11));
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(12)); // 1
Assertions.assertEquals(FCDotCDC1604DashP6.NX03_C, cdc.get(13)); // 3
Assertions.assertEquals(FCDotCDC1604DashP6.NX03_C, cdc.get(14)); // 3
Assertions.assertEquals(FCDotCDC1604DashP6.NX07_G, cdc.get(15)); // 7
String out = FCDotCDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("01201337", out);
}
@Test
public void testNumberTerminatorOutOfRange() throws Exception {
List<FCDotCDC1604DashP6> cdc = new ArrayList<>();
cdc.add(FCDotCDC1604DashP6.NX24_X); // = X
cdc.add(FCDotCDC1604DashP6.__PIE);
cdc.add(FCDotCDC1604DashP6._CARET); // ^
cdc.add(FCDotCDC1604DashP6._PERCENT); // = %
cdc.add(FCDotCDC1604DashP6.__PIE);
cdc.add(FCDotCDC1604DashP6._AT);
cdc.add(FCDotCDC1604DashP6.NX11_K); // = K
String out = FCDotCDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("X^%@K", out);
}
@Test
public void testNumberPieOutOfRange() throws Exception {
List<FCDotCDC1604DashP6> cdc = new ArrayList<>();
cdc.add(FCDotCDC1604DashP6.__PIE);
cdc.add(FCDotCDC1604DashP6.NX01_A);
cdc.add(FCDotCDC1604DashP6.NX02_B); // = B
cdc.add(FCDotCDC1604DashP6.__PIE);
cdc.add(FCDotCDC1604DashP6.NX09_I);
cdc.add(FCDotCDC1604DashP6.NX03_C); // = 3
cdc.add(FCDotCDC1604DashP6.NX10_J); // = J
String out = FCDotCDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("B3J", out);
}
@Test
public void testLineEndings() throws Exception {
List<FCDotCDC1604DashP6> cdc = FCDotCDC1604DashP6.convertFromUnicode("A\nB\rC\r\nD\n");
Assertions.assertNotNull(cdc);
Assertions.assertFalse(cdc.isEmpty());
Assertions.assertEquals(8, cdc.size());
Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(0));
Assertions.assertEquals(FCDotCDC1604DashP6.__LINE, cdc.get(1));
Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(2));
Assertions.assertEquals(FCDotCDC1604DashP6.__LINE, cdc.get(3));
Assertions.assertEquals(FCDotCDC1604DashP6.NX03_C, cdc.get(4));
Assertions.assertEquals(FCDotCDC1604DashP6.__LINE, cdc.get(5));
Assertions.assertEquals(FCDotCDC1604DashP6.NX04_D, cdc.get(6));
Assertions.assertEquals(FCDotCDC1604DashP6.__LINE, cdc.get(7));
String out = FCDotCDC1604DashP6.convertToUnicode(cdc);
Assertions.assertEquals("A\nB\nC\nD\n", out);
}
}