"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/test/java/com/google/zxing/qrcode/encoder/BitVectorTestCase.java" between
zxing-zxing-3.4.0.tar.gz and zxing-zxing-3.4.1.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.

BitVectorTestCase.java  (zxing-zxing-3.4.0):BitVectorTestCase.java  (zxing-zxing-3.4.1)
skipping to change at line 29 skipping to change at line 29
import com.google.zxing.common.BitArray; import com.google.zxing.common.BitArray;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
/** /**
* @author satorux@google.com (Satoru Takabayashi) - creator * @author satorux@google.com (Satoru Takabayashi) - creator
* @author dswitkin@google.com (Daniel Switkin) - ported from C++ * @author dswitkin@google.com (Daniel Switkin) - ported from C++
*/ */
public final class BitVectorTestCase extends Assert { public final class BitVectorTestCase extends Assert {
private static long getUnsignedInt(BitArray v, int index) { private static long getUnsignedInt(BitArray v) {
long result = 0L; long result = 0L;
for (int i = 0, offset = index * 8; i < 32; i++) { for (int i = 0, offset = 0; i < 32; i++) {
if (v.get(offset + i)) { if (v.get(offset + i)) {
result |= 1L << (31 - i); result |= 1L << (31 - i);
} }
} }
return result; return result;
} }
@Test @Test
public void testAppendBit() { public void testAppendBit() {
BitArray v = new BitArray(); BitArray v = new BitArray();
assertEquals(0, v.getSizeInBytes()); assertEquals(0, v.getSizeInBytes());
// 1 // 1
v.appendBit(true); v.appendBit(true);
assertEquals(1, v.getSize()); assertEquals(1, v.getSize());
assertEquals(0x80000000L, getUnsignedInt(v, 0)); assertEquals(0x80000000L, getUnsignedInt(v));
// 10 // 10
v.appendBit(false); v.appendBit(false);
assertEquals(2, v.getSize()); assertEquals(2, v.getSize());
assertEquals(0x80000000L, getUnsignedInt(v, 0)); assertEquals(0x80000000L, getUnsignedInt(v));
// 101 // 101
v.appendBit(true); v.appendBit(true);
assertEquals(3, v.getSize()); assertEquals(3, v.getSize());
assertEquals(0xa0000000L, getUnsignedInt(v, 0)); assertEquals(0xa0000000L, getUnsignedInt(v));
// 1010 // 1010
v.appendBit(false); v.appendBit(false);
assertEquals(4, v.getSize()); assertEquals(4, v.getSize());
assertEquals(0xa0000000L, getUnsignedInt(v, 0)); assertEquals(0xa0000000L, getUnsignedInt(v));
// 10101 // 10101
v.appendBit(true); v.appendBit(true);
assertEquals(5, v.getSize()); assertEquals(5, v.getSize());
assertEquals(0xa8000000L, getUnsignedInt(v, 0)); assertEquals(0xa8000000L, getUnsignedInt(v));
// 101010 // 101010
v.appendBit(false); v.appendBit(false);
assertEquals(6, v.getSize()); assertEquals(6, v.getSize());
assertEquals(0xa8000000L, getUnsignedInt(v, 0)); assertEquals(0xa8000000L, getUnsignedInt(v));
// 1010101 // 1010101
v.appendBit(true); v.appendBit(true);
assertEquals(7, v.getSize()); assertEquals(7, v.getSize());
assertEquals(0xaa000000L, getUnsignedInt(v, 0)); assertEquals(0xaa000000L, getUnsignedInt(v));
// 10101010 // 10101010
v.appendBit(false); v.appendBit(false);
assertEquals(8, v.getSize()); assertEquals(8, v.getSize());
assertEquals(0xaa000000L, getUnsignedInt(v, 0)); assertEquals(0xaa000000L, getUnsignedInt(v));
// 10101010 1 // 10101010 1
v.appendBit(true); v.appendBit(true);
assertEquals(9, v.getSize()); assertEquals(9, v.getSize());
assertEquals(0xaa800000L, getUnsignedInt(v, 0)); assertEquals(0xaa800000L, getUnsignedInt(v));
// 10101010 10 // 10101010 10
v.appendBit(false); v.appendBit(false);
assertEquals(10, v.getSize()); assertEquals(10, v.getSize());
assertEquals(0xaa800000L, getUnsignedInt(v, 0)); assertEquals(0xaa800000L, getUnsignedInt(v));
} }
@Test @Test
public void testAppendBits() { public void testAppendBits() {
BitArray v = new BitArray(); BitArray v = new BitArray();
v.appendBits(0x1, 1); v.appendBits(0x1, 1);
assertEquals(1, v.getSize()); assertEquals(1, v.getSize());
assertEquals(0x80000000L, getUnsignedInt(v, 0)); assertEquals(0x80000000L, getUnsignedInt(v));
v = new BitArray(); v = new BitArray();
v.appendBits(0xff, 8); v.appendBits(0xff, 8);
assertEquals(8, v.getSize()); assertEquals(8, v.getSize());
assertEquals(0xff000000L, getUnsignedInt(v, 0)); assertEquals(0xff000000L, getUnsignedInt(v));
v = new BitArray(); v = new BitArray();
v.appendBits(0xff7, 12); v.appendBits(0xff7, 12);
assertEquals(12, v.getSize()); assertEquals(12, v.getSize());
assertEquals(0xff700000L, getUnsignedInt(v, 0)); assertEquals(0xff700000L, getUnsignedInt(v));
} }
@Test @Test
public void testNumBytes() { public void testNumBytes() {
BitArray v = new BitArray(); BitArray v = new BitArray();
assertEquals(0, v.getSizeInBytes()); assertEquals(0, v.getSizeInBytes());
v.appendBit(false); v.appendBit(false);
// 1 bit was added in the vector, so 1 byte should be consumed. // 1 bit was added in the vector, so 1 byte should be consumed.
assertEquals(1, v.getSizeInBytes()); assertEquals(1, v.getSizeInBytes());
v.appendBits(0, 7); v.appendBits(0, 7);
skipping to change at line 135 skipping to change at line 135
assertEquals(" X.XXXXX. XXX.XXXX", v1.toString()); assertEquals(" X.XXXXX. XXX.XXXX", v1.toString());
} }
@Test @Test
public void testXOR() { public void testXOR() {
BitArray v1 = new BitArray(); BitArray v1 = new BitArray();
v1.appendBits(0x5555aaaa, 32); v1.appendBits(0x5555aaaa, 32);
BitArray v2 = new BitArray(); BitArray v2 = new BitArray();
v2.appendBits(0xaaaa5555, 32); v2.appendBits(0xaaaa5555, 32);
v1.xor(v2); v1.xor(v2);
assertEquals(0xffffffffL, getUnsignedInt(v1, 0)); assertEquals(0xffffffffL, getUnsignedInt(v1));
} }
@Test @Test
public void testXOR2() { public void testXOR2() {
BitArray v1 = new BitArray(); BitArray v1 = new BitArray();
v1.appendBits(0x2a, 7); // 010 1010 v1.appendBits(0x2a, 7); // 010 1010
BitArray v2 = new BitArray(); BitArray v2 = new BitArray();
v2.appendBits(0x55, 7); // 101 0101 v2.appendBits(0x55, 7); // 101 0101
v1.xor(v2); v1.xor(v2);
assertEquals(0xfe000000L, getUnsignedInt(v1, 0)); // 1111 1110 assertEquals(0xfe000000L, getUnsignedInt(v1)); // 1111 1110
} }
@Test @Test
public void testAt() { public void testAt() {
BitArray v = new BitArray(); BitArray v = new BitArray();
v.appendBits(0xdead, 16); // 1101 1110 1010 1101 v.appendBits(0xdead, 16); // 1101 1110 1010 1101
assertTrue(v.get(0)); assertTrue(v.get(0));
assertTrue(v.get(1)); assertTrue(v.get(1));
assertFalse(v.get(2)); assertFalse(v.get(2));
assertTrue(v.get(3)); assertTrue(v.get(3));
 End of changes. 17 change blocks. 
17 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)