assertArraysEqual(expectedECBytes, 0, toEncode, dataBytes.length, expectedECBytes.length);
}
- private static void assertArraysEqual(int[] expected, int expectedOffset, int[] actual, int actualOffset, int length) {
+ static Random getRandom() {
+ return new Random(0xDEADBEEF);
+ }
+
+ static void assertArraysEqual(int[] expected, int expectedOffset, int[] actual, int actualOffset, int length) {
for (int i = 0; i < length; i++) {
assertEquals(expected[expectedOffset + i], actual[actualOffset + i]);
}
public void testOneError() throws ReedSolomonException {
int[] received = new int[DM_CODE_TEST_WITH_EC.length];
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
for (int i = 0; i < received.length; i++) {
System.arraycopy(DM_CODE_TEST_WITH_EC, 0, received, 0, received.length);
received[i] = random.nextInt(256);
public void testMaxErrors() throws ReedSolomonException {
int[] received = new int[DM_CODE_TEST_WITH_EC.length];
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
for (int i = 0; i < DM_CODE_TEST.length; i++) { // # iterations is kind of arbitrary
System.arraycopy(DM_CODE_TEST_WITH_EC, 0, received, 0, received.length);
corrupt(received, DM_CODE_CORRECTABLE, random);
public void testTooManyErrors() {
int[] received = new int[DM_CODE_TEST_WITH_EC.length];
System.arraycopy(DM_CODE_TEST_WITH_EC, 0, received, 0, received.length);
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
corrupt(received, DM_CODE_CORRECTABLE + 1, random);
try {
checkQRRSDecode(received);
public void testOneError() throws ReedSolomonException {
int[] received = new int[QR_CODE_TEST_WITH_EC.length];
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
for (int i = 0; i < received.length; i++) {
System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length);
received[i] = random.nextInt(256);
public void testMaxErrors() throws ReedSolomonException {
int[] received = new int[QR_CODE_TEST_WITH_EC.length];
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
for (int i = 0; i < QR_CODE_TEST.length; i++) { // # iterations is kind of arbitrary
System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length);
corrupt(received, QR_CODE_CORRECTABLE, random);
public void testTooManyErrors() {
int[] received = new int[QR_CODE_TEST_WITH_EC.length];
System.arraycopy(QR_CODE_TEST_WITH_EC, 0, received, 0, received.length);
- Random random = new Random(0xDEADBEEFL);
+ Random random = getRandom();
corrupt(received, QR_CODE_CORRECTABLE + 1, random);
try {
checkQRRSDecode(received);
package com.google.zxing.common.reedsolomon;
+import java.util.Random;
+
/**
* @author srowen@google.com (Sean Owen)
*/
doTestQRCodeEncoding(dataBytes, expectedECBytes);
}
+ public void testQRCodeVersusDecoder() throws Exception {
+ Random random = getRandom();
+ ReedSolomonEncoder encoder = new ReedSolomonEncoder(GF256.QR_CODE_FIELD);
+ ReedSolomonDecoder decoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);
+ for (int i = 0; i < 100; i++) {
+ int size = random.nextInt(1000);
+ int[] toEncode = new int[size];
+ int ecBytes = random.nextInt(2 * (1 + size / 8));
+ int dataBytes = size - ecBytes;
+ for (int j = 0; j < dataBytes; j++) {
+ toEncode[j] = random.nextInt(256);
+ }
+ int[] original = new int[dataBytes];
+ System.arraycopy(toEncode, 0, original, 0, dataBytes);
+ encoder.encode(toEncode, ecBytes);
+ decoder.decode(toEncode, ecBytes);
+ assertArraysEqual(original, 0, toEncode, 0, dataBytes);
+ }
+ }
+
// Need more tests I am sure
}