BitVectorImpl implements BitVector, Iterable<Boolean> { @Override public boolean getBit(long position) { assertNonNegativePosition(position); if (position >= this.size) { return false; } int arrayPos = (int) (position >> LG_WORD_SIZE); byte wordPos = (byte) (position & WORD_MASK); return getBitInWord(wordPos, this.arrayOfBits[arrayPos]); } BitVectorImpl();  BitVectorImpl(BitVector bitVector);  BitVectorImpl(long initialSize); @Override boolean addBit(boolean bit); @Override boolean equals(Object obj); @Override boolean getBit(long position); @Override int hashCode(); @Override Iterator<Boolean> iterator(); @Override void setBit(long position, boolean bit); @Override long size(); @Override String toString();  }
@Test public void testGetBit() { long word = 0; for (byte i = 0; i < 0x40; i++) { Assert.assertFalse(BitVectorImpl.getBitInWord(i, word)); } word = 0x0810F; Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 0, word)); Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 1, word)); Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 2, word)); Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 3, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 4, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 5, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 6, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 7, word)); Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 8, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 9, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 10, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 11, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 12, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 13, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 14, word)); Assert.assertTrue(BitVectorImpl.getBitInWord((byte) 15, word)); Assert.assertFalse(BitVectorImpl.getBitInWord((byte) 16, word)); }
@Test public void testGetOutOfRange() { Assert.assertFalse(new BitVectorImpl().getBit(1)); Assert.assertFalse(new BitVectorImpl().getBit(Long.MAX_VALUE)); }
@Test(expected = IndexOutOfBoundsException.class) public void testInvalidPositionSizeGet00() { (new BitVectorImpl()).getBit(-1); }