mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Cleaned up previous commit
Following Sean Owen's suggestions, I cleaned up my code in the Aztec decoder and its tests as follows: 1. Made convertBoolArrayToByteArray() package-private. 2. Replaced my own assertEqualByteArrays() with existing assertArrayEquals(). 3. Replaced C-style array declarations with more Javaish ones.
This commit is contained in:
parent
e9896d03a6
commit
ee48b3e5d3
|
@ -347,7 +347,7 @@ public final class Decoder {
|
|||
/**
|
||||
* Packs a bit array into bytes, most significant bit first
|
||||
*/
|
||||
public static byte[] convertBoolArrayToByteArray(boolean[] boolArr) {
|
||||
static byte[] convertBoolArrayToByteArray(boolean[] boolArr) {
|
||||
byte[] byteArr = new byte[(boolArr.length + 7) / 8];
|
||||
for (int i = 0; i < byteArr.length; i++) {
|
||||
byteArr[i] = readByte(boolArr, 8 * i);
|
||||
|
|
|
@ -106,35 +106,28 @@ public final class DecoderTest extends Assert {
|
|||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
private static void assertEqualByteArrays(byte[] b1, byte[] b2) {
|
||||
assertEquals(b1.length, b2.length);
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
assertEquals(b1[i], b2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawBytes() {
|
||||
boolean bool0[] = {};
|
||||
boolean bool1[] = { true };
|
||||
boolean bool7[] = { true, false, true, false, true, false, true };
|
||||
boolean bool8[] = { true, false, true, false, true, false, true, false };
|
||||
boolean bool9[] = { true, false, true, false, true, false, true, false,
|
||||
boolean[] bool0 = {};
|
||||
boolean[] bool1 = { true };
|
||||
boolean[] bool7 = { true, false, true, false, true, false, true };
|
||||
boolean[] bool8 = { true, false, true, false, true, false, true, false };
|
||||
boolean[] bool9 = { true, false, true, false, true, false, true, false,
|
||||
true };
|
||||
boolean bool16[] = { false, true, true, false, false, false, true, true,
|
||||
boolean[] bool16 = { false, true, true, false, false, false, true, true,
|
||||
true, true, false, false, false, false, false, true };
|
||||
byte byte0[] = {};
|
||||
byte byte1[] = { -128 };
|
||||
byte byte7[] = { -86 };
|
||||
byte byte8[] = { -86 };
|
||||
byte byte9[] = { -86, -128 };
|
||||
byte byte16[] = { 99, -63 };
|
||||
byte[] byte0 = {};
|
||||
byte[] byte1 = { -128 };
|
||||
byte[] byte7 = { -86 };
|
||||
byte[] byte8 = { -86 };
|
||||
byte[] byte9 = { -86, -128 };
|
||||
byte[] byte16 = { 99, -63 };
|
||||
|
||||
assertEqualByteArrays(byte0, Decoder.convertBoolArrayToByteArray(bool0));
|
||||
assertEqualByteArrays(byte1, Decoder.convertBoolArrayToByteArray(bool1));
|
||||
assertEqualByteArrays(byte7, Decoder.convertBoolArrayToByteArray(bool7));
|
||||
assertEqualByteArrays(byte8, Decoder.convertBoolArrayToByteArray(bool8));
|
||||
assertEqualByteArrays(byte9, Decoder.convertBoolArrayToByteArray(bool9));
|
||||
assertEqualByteArrays(byte16, Decoder.convertBoolArrayToByteArray(bool16));
|
||||
assertArrayEquals(byte0, Decoder.convertBoolArrayToByteArray(bool0));
|
||||
assertArrayEquals(byte1, Decoder.convertBoolArrayToByteArray(bool1));
|
||||
assertArrayEquals(byte7, Decoder.convertBoolArrayToByteArray(bool7));
|
||||
assertArrayEquals(byte8, Decoder.convertBoolArrayToByteArray(bool8));
|
||||
assertArrayEquals(byte9, Decoder.convertBoolArrayToByteArray(bool9));
|
||||
assertArrayEquals(byte16, Decoder.convertBoolArrayToByteArray(bool16));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue