Compacted QR-code: remove needless adding of Mode.TERMINATOR (is taken care of in Encoder.terminateBits) (#1452)

* - added code to suppress the terminator if the capacity of the version is less than 4 bit
- added test case

* - Removed code in MinimalEncoder that added Mode.TERMINATOR (is taken care of in Encoder.terminateBits)
- Removed the corresponding test case

* Updated test cases

* Improved documentation

* Changed documentation to not use an example with an unsupported character encoding

* Improved wording of comment

* - Simplified code
- Added space after comma in several places
This commit is contained in:
AlexGeller1 2021-10-19 15:47:58 +02:00 committed by GitHub
parent 128775149b
commit c729abe393
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 151 deletions

View file

@ -339,6 +339,7 @@ public final class Encoder {
throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " + throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " +
capacity); capacity);
} }
// Append Mode.TERMINATE if there is enough space (value is 0000)
for (int i = 0; i < 4 && bits.getSize() < capacity; ++i) { for (int i = 0; i < 4 && bits.getSize() < capacity; ++i) {
bits.appendBit(false); bits.appendBit(false);
} }

View file

@ -33,46 +33,27 @@ import java.nio.charset.UnsupportedCharsetException;
/** /**
* Encoder that encodes minimally * Encoder that encodes minimally
* *
* Version selection: * Algorithm:
* The version can be preset in the constructor. If it isn't specified then the algorithm will compute three solutions
* for the three different version classes 1-9, 10-26 and 27-40.
* *
* It is not clear to me if ever a solution using for example Medium (Versions 10-26) could be smaller than a Small * The eleventh commandment was "Thou Shalt Compute" or "Thou Shalt Not Compute" - I forget which (Alan Perilis).
* solution (Versions 1-9) (proof for or against would be nice to have).
* With hypothetical values for the number of length bits, the number of bits per mode and the number of bits per
* encoded character it can be shown that it can happen at all as follows:
* We hypothetically assume that a mode is encoded using 1 bit (instead of 4) and a character is encoded in BYTE mode
* using 2 bit (instead of 8). Using these values we now attempt to encode the four characters "1234".
* If we furthermore assume that in Version 1-9 the length field has 1 bit length so that it can encode up to 2
* characters and that in Version 10-26 it has 2 bits length so that we can encode up to 2 characters then it is more
* efficient to encode with Version 10-26 than with Version 1-9 as shown below:
* *
* Number of length bits small version (1-9): 1 * This implementation computes. As an alternative, the QR-Code specification suggests heuristics like this one:
* Number of length bits large version (10-26): 2
* Number of bits per mode item: 1
* Number of bits per character item: 2
* BYTE(1,2),BYTE(3,4): 1+1+2+2,1+1+2+2=12 bits
* BYTE(1,2,3,4): 1+2+2+2+2+2 =11 bits
* *
* If we however change the capacity of the large encoding from 2 bit to 4 bit so that it potentially can encode 16 * If initial input data is in the exclusive subset of the Alphanumeric character set AND if there are less than
* items, then it is more efficient to encode using the small encoding * [6,7,8] characters followed by data from the remainder of the 8-bit byte character set, THEN select the 8-
* as shown below: * bit byte mode ELSE select Alphanumeric mode;
* *
* Number of length bits small version (1-9): 1 * This is probably right for 99.99% of cases but there is at least this one counter example: The string "AAAAAAa"
* Number of length bits large version (10-26): 4 * encodes 2 bits smaller as ALPHANUMERIC(AAAAAA), BYTE(a) than by encoding it as BYTE(AAAAAAa).
* Number of bits per mode item: 1 * Perhaps that is the only counter example but without having proof, it remains unclear.
* Number of bits per character item: 2
* BYTE(1,2),BYTE(3,4): 1+1+2+2,1+1+2+2=12 bits
* BYTE(1,2,3,4): 1+4+2+2+2+2 =13 bits
*
* But as mentioned, it is not clear to me if this can ever happen with the actual values.
* *
* ECI switching: * ECI switching:
* *
* In multi language content the algorithm selects the most compact representation using ECI modes. For example the * In multi language content the algorithm selects the most compact representation using ECI modes.
* most compact representation of the string "\u0625\u05D0" is ECI(UTF-8),BYTE(arabic_aleph,hebrew_aleph) while * For example the most compact representation of the string "\u0150\u015C" (O-double-acute, S-circumflex) is
* the encoding the string "\u0625\u0625\u05D0" is most compactly represented with two ECIs as * ECI(UTF-8), BYTE(\u0150\u015C) while prepending one or more times the same leading character as in
* ECI(ISO-8859-6),BYTE(arabic_aleph,arabic_aleph),ECI(ISO-8859-8),BYTE(hebew_aleph). * "\u0150\u0150\u015C", the most compact representation uses two ECIs so that the string is encoded as
* ECI(ISO-8859-2), BYTE(\u0150\u0150), ECI(ISO-8859-3), BYTE(\u015C).
* *
* @author Alex Geller * @author Alex Geller
*/ */
@ -119,7 +100,7 @@ final class MinimalEncoder {
this.isGS1 = isGS1; this.isGS1 = isGS1;
this.ecLevel = ecLevel; this.ecLevel = ecLevel;
CharsetEncoder[] isoEncoders = new CharsetEncoder[15]; //room for the 15 ISO-8859 charsets 1 through 16. CharsetEncoder[] isoEncoders = new CharsetEncoder[15]; // room for the 15 ISO-8859 charsets 1 through 16.
isoEncoders[0] = StandardCharsets.ISO_8859_1.newEncoder(); isoEncoders[0] = StandardCharsets.ISO_8859_1.newEncoder();
boolean needUnicodeEncoder = priorityCharset != null && priorityCharset.name().startsWith("UTF"); boolean needUnicodeEncoder = priorityCharset != null && priorityCharset.name().startsWith("UTF");
@ -135,11 +116,11 @@ final class MinimalEncoder {
} }
} }
if (cnt == 14) { //we need all. Can stop looking further. if (cnt == 14) { // we need all. Can stop looking further.
break; break;
} }
if (j >= 15) { //no encoder found if (j >= 15) { // no encoder found
for (j = 0; j < 15; j++) { for (j = 0; j < 15; j++) {
if (j != 11 && isoEncoders[j] == null) { // ISO-8859-12 doesn't exist if (j != 11 && isoEncoders[j] == null) { // ISO-8859-12 doesn't exist
try { try {
@ -226,7 +207,7 @@ final class MinimalEncoder {
} }
ResultList encode(Version version) throws WriterException { ResultList encode(Version version) throws WriterException {
if (version == null) { //compute minimal encoding trying the three version sizes. if (version == null) { // compute minimal encoding trying the three version sizes.
final Version[] versions = {getVersion(VersionSize.SMALL), final Version[] versions = {getVersion(VersionSize.SMALL),
getVersion(VersionSize.MEDIUM), getVersion(VersionSize.MEDIUM),
getVersion(VersionSize.LARGE)}; getVersion(VersionSize.LARGE)};
@ -246,7 +227,7 @@ final class MinimalEncoder {
throw new WriterException("Data too big for any version"); throw new WriterException("Data too big for any version");
} }
return results[smallestResult]; return results[smallestResult];
} else { //compute minimal encoding for a given version } else { // compute minimal encoding for a given version
ResultList result = encodeSpecificVersion(version); ResultList result = encodeSpecificVersion(version);
if (!Encoder.willFit(result.getSize(), getVersion(getVersionSize(result.getVersion())), ecLevel)) { if (!Encoder.willFit(result.getSize(), getVersion(getVersionSize(result.getVersion())), ecLevel)) {
throw new WriterException("Data too big for version" + version); throw new WriterException("Data too big for version" + version);
@ -298,8 +279,8 @@ final class MinimalEncoder {
case KANJI: return isDoubleByteKanji(c); case KANJI: return isDoubleByteKanji(c);
case ALPHANUMERIC: return isAlphanumeric(c); case ALPHANUMERIC: return isAlphanumeric(c);
case NUMERIC: return isNumeric(c); case NUMERIC: return isNumeric(c);
case BYTE: return true; //any character can be encoded as byte(s). Up to the caller to manage splitting into case BYTE: return true; // any character can be encoded as byte(s). Up to the caller to manage splitting into
//multiple bytes when String.getBytes(Charset) return more than one byte. // multiple bytes when String.getBytes(Charset) return more than one byte.
default: default:
return false; return false;
} }
@ -323,42 +304,6 @@ final class MinimalEncoder {
} }
} }
ResultList postProcess(Edge solution, Version version) {
ResultList result = new ResultList(version,solution);
Edge edge = solution;
if (isGS1) {
ResultList.ResultNode first = result.get(0);
if (first != null) {
if (first.mode != Mode.ECI) {
boolean haveECI = false;
for (ResultList.ResultNode resultNode : result) {
if (resultNode.mode == Mode.ECI) {
haveECI = true;
break;
}
}
if (haveECI) {
//prepend a default character set ECI
result.add(0,result.new ResultNode(Mode.ECI, 0, 0, 0));
}
}
}
first = result.get(0);
if (first.mode != Mode.ECI) {
//prepend a FNC1_FIRST_POSITION
result.add(0,result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
} else {
//insert a FNC1_FIRST_POSITION after the ECI
result.add(1,result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
}
}
//Add TERMINATOR according to "8.4.8 Terminator"
//TODO: The terminator can be omitted if there are less than 4 bit in the capacity of the symbol.
result.add(result.new ResultNode(Mode.TERMINATOR, stringToEncode.length(), 0, 0));
return result;
}
void addEdge(ArrayList<Edge>[][][] edges, int position, Edge edge) { void addEdge(ArrayList<Edge>[][][] edges, int position, Edge edge) {
int vertexIndex = position + edge.characterLength; int vertexIndex = position + edge.characterLength;
if (edges[vertexIndex][edge.charsetEncoderIndex][getCompactedOrdinal(edge.mode)] == null) { if (edges[vertexIndex][edge.charsetEncoderIndex][getCompactedOrdinal(edge.mode)] == null) {
@ -568,7 +513,7 @@ final class MinimalEncoder {
if (minimalJ < 0) { if (minimalJ < 0) {
throw new WriterException("Internal error: failed to encode \"" + stringToEncode + "\""); throw new WriterException("Internal error: failed to encode \"" + stringToEncode + "\"");
} }
return postProcess(edges[inputLength][minimalJ][minimalK].get(0), version); return new ResultList(version, edges[inputLength][minimalJ][minimalK].get(0));
} }
private final class Edge { private final class Edge {
@ -583,7 +528,7 @@ final class MinimalEncoder {
this.mode = mode; this.mode = mode;
this.fromPosition = fromPosition; this.fromPosition = fromPosition;
this.charsetEncoderIndex = mode == Mode.BYTE || previous == null ? charsetEncoderIndex : this.charsetEncoderIndex = mode == Mode.BYTE || previous == null ? charsetEncoderIndex :
previous.charsetEncoderIndex; //inherit the encoding if not of type BYTE previous.charsetEncoderIndex; // inherit the encoding if not of type BYTE
this.characterLength = characterLength; this.characterLength = characterLength;
this.previous = previous; this.previous = previous;
@ -622,10 +567,11 @@ final class MinimalEncoder {
final Version version; final Version version;
ResultList(Version version,Edge solution) { ResultList(Version version, Edge solution) {
this.version = version;
int length = 0; int length = 0;
Edge current = solution; Edge current = solution;
boolean containsECI = false;
while (current != null) { while (current != null) {
length += current.characterLength; length += current.characterLength;
Edge previous = current.previous; Edge previous = current.previous;
@ -634,39 +580,35 @@ final class MinimalEncoder {
(previous == null && current.charsetEncoderIndex != 0) || // at the beginning and charset is not ISO-8859-1 (previous == null && current.charsetEncoderIndex != 0) || // at the beginning and charset is not ISO-8859-1
(previous != null && current.charsetEncoderIndex != previous.charsetEncoderIndex); (previous != null && current.charsetEncoderIndex != previous.charsetEncoderIndex);
if (needECI) {
containsECI = true;
}
if (previous == null || previous.mode != current.mode || needECI) { if (previous == null || previous.mode != current.mode || needECI) {
add(0,new ResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length)); add(0, new ResultNode(current.mode, current.fromPosition, current.charsetEncoderIndex, length));
length = 0; length = 0;
} }
if (needECI) { if (needECI) {
add(0,new ResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0)); add(0, new ResultNode(Mode.ECI, current.fromPosition, current.charsetEncoderIndex, 0));
} }
current = previous; current = previous;
} }
}
/** // prepend FNC1 if needed. If the bits contain an ECI then the FNC1 must be preceeded by an ECI.
* returns the size in bits // If there is no ECI at the beginning then we put an ECI to the default charset (ISO-8859-1)
*/ if (isGS1) {
int getSize() { ResultNode first = get(0);
int result = 0; if (first != null && first.mode != Mode.ECI && containsECI) {
for (ResultNode resultNode : this) { // prepend a default character set ECI
result += resultNode.getSize(); add(0, new ResultNode(Mode.ECI, 0, 0, 0));
}
first = get(0);
// prepend or insert a FNC1_FIRST_POSITION after the ECI (if any)
add(first.mode != Mode.ECI ? 0 : 1, new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
} }
return result;
} // set version to smallest version into which the bits fit.
/**
* appends the bits
*/
void getBits(BitArray bits) throws WriterException {
for (ResultNode resultNode : this) {
resultNode.getBits(bits);
}
}
Version getVersion() {
int versionNumber = version.getVersionNumber(); int versionNumber = version.getVersionNumber();
int lowerLimit; int lowerLimit;
int upperLimit; int upperLimit;
@ -685,17 +627,46 @@ final class MinimalEncoder {
upperLimit = 40; upperLimit = 40;
break; break;
} }
int size = getSize(version);
// increase version if needed // increase version if needed
while (versionNumber < upperLimit && !Encoder.willFit(getSize(), Version.getVersionForNumber(versionNumber), while (versionNumber < upperLimit && !Encoder.willFit(size, Version.getVersionForNumber(versionNumber),
ecLevel)) { ecLevel)) {
versionNumber++; versionNumber++;
} }
// shrink version if possible // shrink version if possible
while (versionNumber > lowerLimit && Encoder.willFit(getSize(), Version.getVersionForNumber(versionNumber - 1), while (versionNumber > lowerLimit && Encoder.willFit(size, Version.getVersionForNumber(versionNumber - 1),
ecLevel)) { ecLevel)) {
versionNumber--; versionNumber--;
} }
return Version.getVersionForNumber(versionNumber); this.version = Version.getVersionForNumber(versionNumber);
}
/**
* returns the size in bits
*/
int getSize() {
return getSize(version);
}
private int getSize(Version version) {
int result = 0;
for (ResultNode resultNode : this) {
result += resultNode.getSize(version);
}
return result;
}
/**
* appends the bits
*/
void getBits(BitArray bits) throws WriterException {
for (ResultNode resultNode : this) {
resultNode.getBits(bits);
}
}
Version getVersion() {
return version;
} }
public String toString() { public String toString() {
@ -728,7 +699,7 @@ final class MinimalEncoder {
/** /**
* returns the size in bits * returns the size in bits
*/ */
private int getSize() { private int getSize(Version version) {
int size = 4 + mode.getCharacterCountBits(version); int size = 4 + mode.getCharacterCountBits(version);
switch (mode) { switch (mode) {
case KANJI: case KANJI:

View file

@ -670,218 +670,215 @@ public final class EncoderTestCase extends Assert {
@Test @Test
public void testMinimalEncoder1() throws Exception { public void testMinimalEncoder1() throws Exception {
verifyMinimalEncoding("A", "ALPHANUMERIC(A),TERMINATOR()", null, false); verifyMinimalEncoding("A", "ALPHANUMERIC(A)", null, false);
} }
@Test @Test
public void testMinimalEncoder2() throws Exception { public void testMinimalEncoder2() throws Exception {
verifyMinimalEncoding("AB", "ALPHANUMERIC(AB),TERMINATOR()", null, false); verifyMinimalEncoding("AB", "ALPHANUMERIC(AB)", null, false);
} }
@Test @Test
public void testMinimalEncoder3() throws Exception { public void testMinimalEncoder3() throws Exception {
verifyMinimalEncoding("ABC", "ALPHANUMERIC(ABC),TERMINATOR()", null, false); verifyMinimalEncoding("ABC", "ALPHANUMERIC(ABC)", null, false);
} }
@Test @Test
public void testMinimalEncoder4() throws Exception { public void testMinimalEncoder4() throws Exception {
verifyMinimalEncoding("ABCD", "ALPHANUMERIC(ABCD),TERMINATOR()", null, false); verifyMinimalEncoding("ABCD", "ALPHANUMERIC(ABCD)", null, false);
} }
@Test @Test
public void testMinimalEncoder5() throws Exception { public void testMinimalEncoder5() throws Exception {
verifyMinimalEncoding("ABCDE", "ALPHANUMERIC(ABCDE),TERMINATOR()", null, false); verifyMinimalEncoding("ABCDE", "ALPHANUMERIC(ABCDE)", null, false);
} }
@Test @Test
public void testMinimalEncoder6() throws Exception { public void testMinimalEncoder6() throws Exception {
verifyMinimalEncoding("ABCDEF", "ALPHANUMERIC(ABCDEF),TERMINATOR()", null, false); verifyMinimalEncoding("ABCDEF", "ALPHANUMERIC(ABCDEF)", null, false);
} }
@Test @Test
public void testMinimalEncoder7() throws Exception { public void testMinimalEncoder7() throws Exception {
verifyMinimalEncoding("ABCDEFG", "ALPHANUMERIC(ABCDEFG),TERMINATO" + verifyMinimalEncoding("ABCDEFG", "ALPHANUMERIC(ABCDEFG)", null, false);
"R()", null, false);
} }
@Test @Test
public void testMinimalEncoder8() throws Exception { public void testMinimalEncoder8() throws Exception {
verifyMinimalEncoding("1", "NUMERIC(1),TERMINATOR()", null, false); verifyMinimalEncoding("1", "NUMERIC(1)", null, false);
} }
@Test @Test
public void testMinimalEncoder9() throws Exception { public void testMinimalEncoder9() throws Exception {
verifyMinimalEncoding("12", "NUMERIC(12),TERMINATOR()", null, false); verifyMinimalEncoding("12", "NUMERIC(12)", null, false);
} }
@Test @Test
public void testMinimalEncoder10() throws Exception { public void testMinimalEncoder10() throws Exception {
verifyMinimalEncoding("123", "NUMERIC(123),TERMINATOR()", null, false); verifyMinimalEncoding("123", "NUMERIC(123)", null, false);
} }
@Test @Test
public void testMinimalEncoder11() throws Exception { public void testMinimalEncoder11() throws Exception {
verifyMinimalEncoding("1234", "NUMERIC(1234),TERMINATOR()", null, false); verifyMinimalEncoding("1234", "NUMERIC(1234)", null, false);
} }
@Test @Test
public void testMinimalEncoder12() throws Exception { public void testMinimalEncoder12() throws Exception {
verifyMinimalEncoding("12345", "NUMERIC(12345),TERMINATOR()", null, false); verifyMinimalEncoding("12345", "NUMERIC(12345)", null, false);
} }
@Test @Test
public void testMinimalEncoder13() throws Exception { public void testMinimalEncoder13() throws Exception {
verifyMinimalEncoding("123456", "NUMERIC(123456),TERMINATOR()", null, false); verifyMinimalEncoding("123456", "NUMERIC(123456)", null, false);
} }
@Test @Test
public void testMinimalEncoder14() throws Exception { public void testMinimalEncoder14() throws Exception {
verifyMinimalEncoding("123A", "ALPHANUMERIC(123A),TERMINATOR()", null, false); verifyMinimalEncoding("123A", "ALPHANUMERIC(123A)", null, false);
} }
@Test @Test
public void testMinimalEncoder15() throws Exception { public void testMinimalEncoder15() throws Exception {
verifyMinimalEncoding("A1", "ALPHANUMERIC(A1),TERMINATOR()", null, false); verifyMinimalEncoding("A1", "ALPHANUMERIC(A1)", null, false);
} }
@Test @Test
public void testMinimalEncoder16() throws Exception { public void testMinimalEncoder16() throws Exception {
verifyMinimalEncoding("A12", "ALPHANUMERIC(A12),TERMINATOR()", null, false); verifyMinimalEncoding("A12", "ALPHANUMERIC(A12)", null, false);
} }
@Test @Test
public void testMinimalEncoder17() throws Exception { public void testMinimalEncoder17() throws Exception {
verifyMinimalEncoding("A123", "ALPHANUMERIC(A123),TERMINATOR()", null, false); verifyMinimalEncoding("A123", "ALPHANUMERIC(A123)", null, false);
} }
@Test @Test
public void testMinimalEncoder18() throws Exception { public void testMinimalEncoder18() throws Exception {
verifyMinimalEncoding("A1234", "ALPHANUMERIC(A1234),TERMINATOR()", null, false); verifyMinimalEncoding("A1234", "ALPHANUMERIC(A1234)", null, false);
} }
@Test @Test
public void testMinimalEncoder19() throws Exception { public void testMinimalEncoder19() throws Exception {
verifyMinimalEncoding("A12345", "ALPHANUMERIC(A12345),TERMINATOR()", null, false); verifyMinimalEncoding("A12345", "ALPHANUMERIC(A12345)", null, false);
} }
@Test @Test
public void testMinimalEncoder20() throws Exception { public void testMinimalEncoder20() throws Exception {
verifyMinimalEncoding("A123456", "ALPHANUMERIC(A123456),TERMINATOR()", null, false); verifyMinimalEncoding("A123456", "ALPHANUMERIC(A123456)", null, false);
} }
@Test @Test
public void testMinimalEncoder21() throws Exception { public void testMinimalEncoder21() throws Exception {
verifyMinimalEncoding("A1234567", "ALPHANUMERIC(A1234567),TERMINATOR()", null, false); verifyMinimalEncoding("A1234567", "ALPHANUMERIC(A1234567)", null, false);
} }
@Test @Test
public void testMinimalEncoder22() throws Exception { public void testMinimalEncoder22() throws Exception {
verifyMinimalEncoding("A12345678", "BYTE(A),NUMERIC(12345678),TERMINATOR()", null, false); verifyMinimalEncoding("A12345678", "BYTE(A),NUMERIC(12345678)", null, false);
} }
@Test @Test
public void testMinimalEncoder23() throws Exception { public void testMinimalEncoder23() throws Exception {
verifyMinimalEncoding("A123456789", "BYTE(A),NUMERIC(123456789),TERMINATOR()", null, false); verifyMinimalEncoding("A123456789", "BYTE(A),NUMERIC(123456789)", null, false);
} }
@Test @Test
public void testMinimalEncoder24() throws Exception { public void testMinimalEncoder24() throws Exception {
verifyMinimalEncoding("A1234567890", "ALPHANUMERIC(A1),NUMERIC(234567890),TERMINATOR()", null, false); verifyMinimalEncoding("A1234567890", "ALPHANUMERIC(A1),NUMERIC(234567890)", null, false);
} }
@Test @Test
public void testMinimalEncoder25() throws Exception { public void testMinimalEncoder25() throws Exception {
verifyMinimalEncoding("AB1", "ALPHANUMERIC(AB1),TERMINATOR()", null, false); verifyMinimalEncoding("AB1", "ALPHANUMERIC(AB1)", null, false);
} }
@Test @Test
public void testMinimalEncoder26() throws Exception { public void testMinimalEncoder26() throws Exception {
verifyMinimalEncoding("AB12", "ALPHANUMERIC(AB12),TERMINATOR()", null, false); verifyMinimalEncoding("AB12", "ALPHANUMERIC(AB12)", null, false);
} }
@Test @Test
public void testMinimalEncoder27() throws Exception { public void testMinimalEncoder27() throws Exception {
verifyMinimalEncoding("AB123", "ALPHANUMERIC(AB123),TERMINATOR()", null, false); verifyMinimalEncoding("AB123", "ALPHANUMERIC(AB123)", null, false);
} }
@Test @Test
public void testMinimalEncoder28() throws Exception { public void testMinimalEncoder28() throws Exception {
verifyMinimalEncoding("AB1234", "ALPHANUMERIC(AB1234),TERMINATOR()", null, false); verifyMinimalEncoding("AB1234", "ALPHANUMERIC(AB1234)", null, false);
} }
@Test @Test
public void testMinimalEncoder29() throws Exception { public void testMinimalEncoder29() throws Exception {
verifyMinimalEncoding("ABC1", "ALPHANUMERIC(ABC1),TERMINATOR()", null, false); verifyMinimalEncoding("ABC1", "ALPHANUMERIC(ABC1)", null, false);
} }
@Test @Test
public void testMinimalEncoder30() throws Exception { public void testMinimalEncoder30() throws Exception {
verifyMinimalEncoding("ABC12", "ALPHANUMERIC(ABC12),TERMINATOR()", null, false); verifyMinimalEncoding("ABC12", "ALPHANUMERIC(ABC12)", null, false);
} }
@Test @Test
public void testMinimalEncoder31() throws Exception { public void testMinimalEncoder31() throws Exception {
verifyMinimalEncoding("ABC1234", "ALPHANUMERIC(ABC1234),TERMINA" + verifyMinimalEncoding("ABC1234", "ALPHANUMERIC(ABC1234)", null, false);
"TOR()", null, false);
} }
@Test @Test
public void testMinimalEncoder32() throws Exception { public void testMinimalEncoder32() throws Exception {
verifyMinimalEncoding("http://foo.com", "BYTE(http://foo.com)" + verifyMinimalEncoding("http://foo.com", "BYTE(http://foo.com)" +
",TERMINATOR()", null, false); "", null, false);
} }
@Test @Test
public void testMinimalEncoder33() throws Exception { public void testMinimalEncoder33() throws Exception {
verifyMinimalEncoding("HTTP://FOO.COM", "ALPHANUMERIC(HTTP://FOO.COM" + verifyMinimalEncoding("HTTP://FOO.COM", "ALPHANUMERIC(HTTP://FOO.COM" +
"),TERMINATOR()", null, false); ")", null, false);
} }
@Test @Test
public void testMinimalEncoder34() throws Exception { public void testMinimalEncoder34() throws Exception {
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781", verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781",
"NUMERIC(1001114670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(140045003267781),TERMINA" + "NUMERIC(1001114670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(140045003267781)", null, false);
"TOR()", null, false);
} }
@Test @Test
public void testMinimalEncoder35() throws Exception { public void testMinimalEncoder35() throws Exception {
verifyMinimalEncoding("\u0150", "ECI(ISO-8859-2),BYTE(.),TERMINATOR()", null, false); verifyMinimalEncoding("\u0150", "ECI(ISO-8859-2),BYTE(.)", null, false);
} }
@Test @Test
public void testMinimalEncoder36() throws Exception { public void testMinimalEncoder36() throws Exception {
verifyMinimalEncoding("\u015C", "ECI(ISO-8859-3),BYTE(.),TERMINATOR()", null, false); verifyMinimalEncoding("\u015C", "ECI(ISO-8859-3),BYTE(.)", null, false);
} }
@Test @Test
public void testMinimalEncoder37() throws Exception { public void testMinimalEncoder37() throws Exception {
verifyMinimalEncoding("\u0150\u015C", "ECI(UTF-8),BYTE(..),TERMINATOR()", null, false); verifyMinimalEncoding("\u0150\u015C", "ECI(UTF-8),BYTE(..)", null, false);
} }
@Test @Test
public void testMinimalEncoder38() throws Exception { public void testMinimalEncoder38() throws Exception {
verifyMinimalEncoding("\u0150\u0150\u015C\u015C", "ECI(ISO-8859-2),BYTE(." + verifyMinimalEncoding("\u0150\u0150\u015C\u015C", "ECI(ISO-8859-2),BYTE(." +
".),ECI(ISO-8859-3),BYTE(..),TERMINATOR()", null, false); ".),ECI(ISO-8859-3),BYTE(..)", null, false);
} }
@Test @Test
public void testMinimalEncoder39() throws Exception { public void testMinimalEncoder39() throws Exception {
verifyMinimalEncoding("abcdef\u0150ghij", "ECI(ISO-8859-2),BYTE(abcde" + verifyMinimalEncoding("abcdef\u0150ghij", "ECI(ISO-8859-2),BYTE(abcde" +
"f.ghij),TERMINATOR()", null, false); "f.ghij)", null, false);
} }
@Test @Test
public void testMinimalEncoder40() throws Exception { public void testMinimalEncoder40() throws Exception {
verifyMinimalEncoding("2938928329832983\u01502938928329832983\u015C2938928329832983", verifyMinimalEncoding("2938928329832983\u01502938928329832983\u015C2938928329832983",
"NUMERIC(2938928329832983),ECI(ISO-8859-2),BYTE(.),NUMERIC(2938928329832983),ECI(ISO-8" + "NUMERIC(2938928329832983),ECI(ISO-8859-2),BYTE(.),NUMERIC(2938928329832983),ECI(ISO-8" +
"859-3),BYTE(.),NUMERIC(2938928329832983),TERMINATOR()", null, false); "859-3),BYTE(.),NUMERIC(2938928329832983)", null, false);
} }
@Test @Test
public void testMinimalEncoder41() throws Exception { public void testMinimalEncoder41() throws Exception {
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781", "FNC1_FIRST_POSITION(),NUMERIC(100111" + verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781", "FNC1_FIRST_POSITION(),NUMERIC(100111" +
"4670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(140045003267781),TERMINATOR()", null, "4670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(140045003267781)", null,
true); true);
} }