mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
More enhancements to Reed-Solomon tests
git-svn-id: https://zxing.googlecode.com/svn/trunk@703 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
b625c6f7e5
commit
f80cd1ff51
|
@ -47,7 +47,11 @@ abstract class AbstractReedSolomonTestCase extends TestCase {
|
|||
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]);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public final class ReedSolomonDecoderDataMatrixTestCase extends AbstractReedSolo
|
|||
|
||||
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);
|
||||
|
@ -50,7 +50,7 @@ public final class ReedSolomonDecoderDataMatrixTestCase extends AbstractReedSolo
|
|||
|
||||
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);
|
||||
|
@ -61,7 +61,7 @@ public final class ReedSolomonDecoderDataMatrixTestCase extends AbstractReedSolo
|
|||
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);
|
||||
|
|
|
@ -45,7 +45,7 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT
|
|||
|
||||
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);
|
||||
|
@ -55,7 +55,7 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT
|
|||
|
||||
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);
|
||||
|
@ -66,7 +66,7 @@ public final class ReedSolomonDecoderQRCodeTestCase extends AbstractReedSolomonT
|
|||
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);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.common.reedsolomon;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
|
@ -34,6 +36,26 @@ public final class ReedSolomonEncoderQRCodeTestCase extends AbstractReedSolomonT
|
|||
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
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue