summaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorSean Owen <srowen@gmail.com>2016-05-08 11:13:34 +0300
committerSean Owen <srowen@gmail.com>2016-05-08 11:13:41 +0300
commit30bb62bf4f8f9e837e611a1cb577af1a31b92b58 (patch)
treebdbfa11f878f675e4abd1689a0f24b069305ec62 /core/src/test/java
parenta8d01bd85f85d139d54f376ca74c7a29e154359a (diff)
downloadzxing-30bb62bf4f8f9e837e611a1cb577af1a31b92b58.tar.xz
Minor changes from inspection
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java17
-rw-r--r--core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java9
-rw-r--r--core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java4
-rw-r--r--core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java48
-rw-r--r--core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java23
5 files changed, 38 insertions, 63 deletions
diff --git a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java
index 5331ad14b..15de77263 100644
--- a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java
+++ b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java
@@ -45,6 +45,7 @@ import java.util.regex.Pattern;
public final class EncoderTest extends Assert {
private static final Pattern DOTX = Pattern.compile("[^.X]");
+ private static final Pattern SPACES = Pattern.compile("\\s+");
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
// real life tests
@@ -509,15 +510,14 @@ public final class EncoderTest extends Assert {
private static void testModeMessage(boolean compact, int layers, int words, String expected) {
BitArray in = Encoder.generateModeMessage(compact, layers, words);
- assertEquals("generateModeMessage() failed", expected.replace(" ", ""), in.toString().replace(" ", ""));
+ assertEquals("generateModeMessage() failed", stripSpace(expected), stripSpace(in.toString()));
}
private static void testStuffBits(int wordSize, String bits, String expected) {
BitArray in = toBitArray(bits);
BitArray stuffed = Encoder.stuffBits(in, wordSize);
assertEquals("stuffBits() failed for input string: " + bits,
- expected.replace(" ", ""),
- stuffed.toString().replace(" ", ""));
+ stripSpace(expected), stripSpace(stuffed.toString()));
}
private static BitArray toBitArray(CharSequence bits) {
@@ -539,16 +539,21 @@ public final class EncoderTest extends Assert {
private static void testHighLevelEncodeString(String s, String expectedBits) {
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
- String receivedBits = bits.toString().replace(" ", "");
- assertEquals("highLevelEncode() failed for input string: " + s, expectedBits.replace(" ", ""), receivedBits);
+ String receivedBits = stripSpace(bits.toString());
+ assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits);
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
}
private static void testHighLevelEncodeString(String s, int expectedReceivedBits) {
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
- int receivedBitCount = bits.toString().replace(" ", "").length();
+ int receivedBitCount = stripSpace(bits.toString()).length();
assertEquals("highLevelEncode() failed for input string: " + s,
expectedReceivedBits, receivedBitCount);
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
}
+
+ private static String stripSpace(String s) {
+ return SPACES.matcher(s).replaceAll("");
+ }
+
}
diff --git a/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java b/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java
index db3503e53..60aed9c6e 100644
--- a/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java
+++ b/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java
@@ -22,15 +22,6 @@ final class DebugPlacement extends DefaultPlacement {
super(codewords, numcols, numrows);
}
- public String toBitFieldString() {
- byte[] bits = getBits();
- StringBuilder sb = new StringBuilder(bits.length);
- for (byte bit : bits) {
- sb.append(bit == 1 ? '1' : '0');
- }
- return sb.toString();
- }
-
String[] toBitFieldStringArray() {
byte[] bits = getBits();
int numrows = getNumrows();
diff --git a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java
index cf68414fb..1d26507d4 100644
--- a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java
+++ b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java
@@ -32,8 +32,8 @@ public class Code128WriterTestCase extends Assert {
private static final String FNC3 = "10111100010";
private static final String FNC4 = "10111101110";
private static final String START_CODE_B = "11010010000";
- public static final String QUIET_SPACE = "00000";
- public static final String STOP = "1100011101011";
+ private static final String QUIET_SPACE = "00000";
+ private static final String STOP = "1100011101011";
private Writer writer;
diff --git a/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java
index 96a689126..0cc69835a 100644
--- a/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java
+++ b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java
@@ -36,39 +36,39 @@ import org.junit.Assert;
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
-public abstract class AbstractDecoderTest extends Assert {
+abstract class AbstractDecoderTest extends Assert {
- protected static final String numeric_10 = "..X..XX";
- protected static final String numeric_12 = "..X.X.X";
- protected static final String numeric_1FNC1 = "..XXX.X";
- //protected static final String numeric_FNC11 = "XXX.XXX";
+ static final String numeric_10 = "..X..XX";
+ static final String numeric_12 = "..X.X.X";
+ static final String numeric_1FNC1 = "..XXX.X";
+ // static final String numeric_FNC11 = "XXX.XXX";
- protected static final String numeric2alpha = "....";
+ static final String numeric2alpha = "....";
- protected static final String alpha_A = "X.....";
- protected static final String alpha_FNC1 = ".XXXX";
- protected static final String alpha2numeric = "...";
- protected static final String alpha2isoiec646 = "..X..";
+ static final String alpha_A = "X.....";
+ static final String alpha_FNC1 = ".XXXX";
+ static final String alpha2numeric = "...";
+ static final String alpha2isoiec646 = "..X..";
- protected static final String i646_B = "X.....X";
- protected static final String i646_C = "X....X.";
- protected static final String i646_FNC1 = ".XXXX";
- protected static final String isoiec646_2alpha = "..X..";
+ static final String i646_B = "X.....X";
+ static final String i646_C = "X....X.";
+ static final String i646_FNC1 = ".XXXX";
+ static final String isoiec646_2alpha = "..X..";
- protected static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
- protected static final String compressedGtin_900000000000008 = "........................................";
+ static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
+ static final String compressedGtin_900000000000008 = "........................................";
- protected static final String compressed15bitWeight_1750 = "....XX.XX.X.XX.";
- protected static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX.";
- protected static final String compressed15bitWeight_0 = "...............";
+ static final String compressed15bitWeight_1750 = "....XX.XX.X.XX.";
+ static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX.";
+ static final String compressed15bitWeight_0 = "...............";
- protected static final String compressed20bitWeight_1750 = ".........XX.XX.X.XX.";
+ static final String compressed20bitWeight_1750 = ".........XX.XX.X.XX.";
- protected static final String compressedDate_March_12th_2010 = "....XXXX.X..XX..";
- protected static final String compressedDate_End = "X..X.XX.........";
+ static final String compressedDate_March_12th_2010 = "....XXXX.X..XX..";
+ static final String compressedDate_End = "X..X.XX.........";
- protected static void assertCorrectBinaryString(CharSequence binaryString,
- String expectedNumber) throws NotFoundException, FormatException {
+ static void assertCorrectBinaryString(CharSequence binaryString,
+ String expectedNumber) throws NotFoundException, FormatException {
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
String result = decoder.parseInformation();
diff --git a/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java b/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java
index 01ac1e34c..e93f0cfd0 100644
--- a/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java
+++ b/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java
@@ -74,16 +74,14 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
testPDF417BlackBoxCountingResults(true);
}
- SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
+ private SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
assertFalse(testResults.isEmpty());
Map<String,List<Path>> imageFiles = getImageFileLists();
int testCount = testResults.size();
int[] passedCounts = new int[testCount];
- int[] misreadCounts = new int[testCount];
int[] tryHarderCounts = new int[testCount];
- int[] tryHaderMisreadCounts = new int[testCount];
Path testBase = getTestBase();
@@ -144,8 +142,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
// Print the results of all tests first
int totalFound = 0;
int totalMustPass = 0;
- int totalMisread = 0;
- int totalMaxMisread = 0;
int numberOfTests = imageFiles.keySet().size();
for (int x = 0; x < testResults.size(); x++) {
@@ -153,18 +149,10 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation()));
log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests,
testResult.getMustPassCount()));
- int failed = numberOfTests - passedCounts[x];
- log.info(String
- .format(" %d failed due to misreads, %d not detected", misreadCounts[x], failed - misreadCounts[x]));
log.info(String.format(" %d of %d images passed with try harder (%d required)", tryHarderCounts[x],
numberOfTests, testResult.getTryHarderCount()));
- failed = numberOfTests - tryHarderCounts[x];
- log.info(String.format(" %d failed due to misreads, %d not detected", tryHaderMisreadCounts[x], failed -
- tryHaderMisreadCounts[x]));
totalFound += passedCounts[x] + tryHarderCounts[x];
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
- totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x];
- totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
}
int totalTests = numberOfTests * testCount * 2;
@@ -177,12 +165,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
log.warning(String.format("--- Test failed by %d images", totalMustPass - totalFound));
}
- if (totalMisread < totalMaxMisread) {
- log.warning(String.format("+++ Test expects too many misreads by %d images", totalMaxMisread - totalMisread));
- } else if (totalMisread > totalMaxMisread) {
- log.warning(String.format("--- Test had too many misreads by %d images", totalMisread - totalMaxMisread));
- }
-
// Then run through again and assert if any failed
if (assertOnFailure) {
for (int x = 0; x < testCount; x++) {
@@ -190,9 +172,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
- label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread";
- assertTrue(label, misreadCounts[x] <= testResult.getMaxMisreads());
- assertTrue("Try harder, " + label, tryHaderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
}
}
return new SummaryResults(totalFound, totalMustPass, totalTests);