BitVectorImpl implements BitVector, Iterable<Boolean> { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (long position = 0; position < this.size;) { sb.append(getBit(position) ? "1" : "0"); position++; } return sb.toString(); } 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 testToString() { BitVectorImpl bv = new BitVectorImpl(); for (int i = 0; i < 0x10; i++) { boolean value = (i % 3) == 0; bv.addBit(value); } Assert.assertEquals("1001001001001001", bv.toString()); for (int i = 0; i < 0x10; i++) { boolean value = (i % 2) == 0; bv.addBit(value); } Assert.assertEquals("10010010010010011010101010101010", bv.toString()); for (int i = 0; i < 0x20; i++) { bv.setBit(i, bv.getBit(i)); } Assert.assertEquals("10010010010010011010101010101010", bv.toString()); for (int i = 0; i < 0x20; i++) { bv.setBit(i, !bv.getBit(i)); } Assert.assertEquals("01101101101101100101010101010101", bv.toString()); }