Skip to content

Commit

Permalink
progressing the testing on the ReedSolomon encoder. #10
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Apr 18, 2017
1 parent a649f73 commit 523c91b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
19 changes: 19 additions & 0 deletions tests/src/QZXingTests/TestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ class TestCase {
const std::vector<int> &expected,
const std::vector<int> & received)
{
if(expected.size() != received.size())
assertTrue(false);

for (int i = 0; i < expected.size(); i++) {
if (expected[i] != received[i]) {
qDebug() << QString::fromStdString(message) << ". Mismatch at " << QString::number(i) /*<< ". Expected " + arrayToString(expected) + ", got " +
arrayToString(Arrays.copyOf(received, expected.length)))*/;
assertTrue(false);
}
}
}

void assertDataEquals(const std::string &message,
const std::vector<int> &expected,
const ArrayRef<int> &received)
{
if(expected.size() != received->size())
assertTrue(false);

for (int i = 0; i < expected.size(); i++) {
if (expected[i] != received[i]) {
qDebug() << QString::fromStdString(message) << ". Mismatch at " << QString::number(i) /*<< ". Expected " + arrayToString(expected) + ", got " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ void ReedSolomonTests::testQRCode()
testEncodeDecode(GenericGF::QR_CODE_FIELD_256, {
0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11,
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11
// 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
},
{0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87,
0x2C, 0x55 });
0x2C, 0x55});

testEncodeDecode(GenericGF::QR_CODE_FIELD_256, {
0x72, 0x67, 0x2F, 0x77, 0x69, 0x6B, 0x69, 0x2F,
0x4D, 0x61, 0x69, 0x6E, 0x5F, 0x50, 0x61, 0x67,
Expand All @@ -37,15 +37,15 @@ void ReedSolomonTests::testQRCode()
0x73, 0x40, 0x0B, 0xB5, 0x5A, 0xB8, 0x8B, 0x2E,
0x08, 0x62 });
// real life test cases
// synthetic test cases
testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 10, 240);
testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 128, 127);
testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 220, 35);
// synthetic test cases - suspended for now
// testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 10, 240);
// testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 128, 127);
// testEncodeDecodeRandom(GenericGF::QR_CODE_FIELD_256, 220, 35);
}

void ReedSolomonTests::corrupt(std::vector<int> &received, int howMany, int max)
{
std::vector<bool> corrupted(false, received.size());
std::vector<bool> corrupted(received.size(), false);
for (int j = 0; j < howMany; j++) {
int location = generateRandomNumber(received.size());
int value = generateRandomNumber(max);
Expand Down Expand Up @@ -96,11 +96,10 @@ void ReedSolomonTests::testEncoder(Ref<GenericGF> field,
{
ReedSolomonEncoder encoder(field);
std::vector<int> messageExpected;
std::vector<int> message;
std::vector<int> message(dataWords);

messageExpected = dataWords;
messageExpected.insert(std::end(messageExpected), std::begin(ecWords), std::end(ecWords));
message = dataWords;

encoder.encode(message, ecWords.size());
assertDataEquals("",//"Encode in " + field + " (" + dataWords.size() + ',' + ecWords.size() + ") failed",
Expand All @@ -112,17 +111,23 @@ void ReedSolomonTests::testDecoder(Ref<GenericGF> field,
const std::vector<int> & ecWords) {
ReedSolomonDecoder decoder(field);
std::vector<int> message;
std::vector<int> referenceMessage;

int maxErrors = ecWords.size() / 2;
initializeRandom();
int iterations = field->getSize() > 256 ? 1 : DECODER_TEST_ITERATIONS;

referenceMessage = dataWords;
referenceMessage.insert(std::end(referenceMessage), std::begin(ecWords), std::end(ecWords));

for (int j = 0; j < iterations; j++) {
for (int i = 0; i < ecWords.size(); i++) {
if (i > 10 && i < ecWords.size() / 2 - 10) {
// performance improvement - skip intermediate cases in long-running tests
i += ecWords.size() / 10;
}
message = dataWords;
message.insert(std::end(message), std::begin(ecWords), std::end(ecWords));

message = referenceMessage;
corrupt(message, i, field->getSize());

ArrayRef<int> messageArrayRef(message.size());
Expand All @@ -139,7 +144,7 @@ void ReedSolomonTests::testDecoder(Ref<GenericGF> field,

if (i < maxErrors) {
//"Decode in " + field + " (" + dataWords.size() + ',' + ecWords.size() + ") failed at " + i + " errors"
assertDataEquals("",dataWords, message);
assertDataEquals("decoded data error",referenceMessage, messageArrayRef);
}
}
}
Expand Down

0 comments on commit 523c91b

Please sign in to comment.