StrictBitVector implements BitVector { public boolean getBit(int index, boolean isBigEndian) { rangeCheck(index); int actualIndex = isBigEndian ? size - 1 - index : index; return ByteArrayHelper.getBit(bits, actualIndex); } StrictBitVector(byte[] bits);  StrictBitVector(int size);  StrictBitVector(int size, Drbg rand); boolean getBit(int index, boolean isBigEndian); @Override boolean getBit(int bit); void setBit(int index, boolean value, boolean isBigEndian); @Override void setBit(int index, boolean value); @Override int getSize(); @Override byte[] toByteArray(); String asBinaryString(); @Override void xor(BitVector other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static StrictBitVector concat(StrictBitVector... bitVectors);  }
@Test public void testGetBitBigEndian() { int bitLen = 72; byte[] bits = new byte[bitLen / 8]; for (int b = 0; b < bits.length; b++) { bits[b] = (byte) b; } StrictBitVector bv = new StrictBitVector(bits); String actual = ""; for (int b = 0; b < bitLen; b++) { actual += bv.getBit(b) ? "1" : "0"; } String expected = "000100001110000001100000101000000010000011000000010000001000000000000000"; assertEquals(expected, actual); }
@Test public void testGetBitLittleEndian() { int bitLen = 72; byte[] bits = new byte[bitLen / 8]; for (int b = 0; b < bits.length; b++) { bits[b] = (byte) b; } StrictBitVector bv = new StrictBitVector(bits); String actual = ""; for (int b = 0; b < bitLen; b++) { actual += bv.getBit(b, false) ? "1" : "0"; } String expected = "000000000000000100000010000000110000010000000101000001100000011100001000"; assertEquals(expected, actual); }
@Test(expected = IndexOutOfBoundsException.class) public void testRangeCheckNegative() { byte[] bits = { (byte) 0xFF, (byte) 0x01, (byte) 0x00 }; StrictBitVector bv = new StrictBitVector(bits); bv.getBit(-1); }