@Test
public void test() throws IOException {
int[] values = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int[] lens = new int[] { 1, 2, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8 };
CanonicalHuffmanIntegerCodec c = new CanonicalHuffmanIntegerCodec(values,
lens);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DefaultBitOutputStream bos = new DefaultBitOutputStream(baos);
for (int b : values) {
c.write(bos, b);
}
bos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DefaultBitInputStream bis = new DefaultBitInputStream(bais);
for (int b : values) {
int v = c.read(bis);
if (v != b)
fail("Mismatch: " + v + " vs " + b);
}
}