public void runSeekTest(CompressionCodec codec) { TestInStream.OutputCollector collect = new TestInStream.OutputCollector(); RunLengthIntegerWriterV2 @out = new RunLengthIntegerWriterV2( new OutStream("test", 1000, codec, collect), true); TestInStream.PositionCollector[] positions = new TestInStream.PositionCollector[4096]; Random random = new Random(99); int[] junk = new int[2048]; for (int i = 0; i < junk.Length; ++i) { junk[i] = random.Next(); } for (int i = 0; i < 4096; ++i) { positions[i] = new TestInStream.PositionCollector(); @out.getPosition(positions[i]); // test runs, incrementing runs, non-runs if (i < 1024) { @out.write(i / 4); } else if (i < 2048) { @out.write(2 * i); } else { @out.write(junk[i - 2048]); } } @out.flush(); ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size()); collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size()); inBuf.flip(); #pragma warning disable 612 RunLengthIntegerReaderV2 @in = new RunLengthIntegerReaderV2(InStream.create (null, "test", new ByteBuffer[] { inBuf }, new long[] { 0 }, inBuf.remaining(), codec, 1000), true, false); #pragma warning restore 612 for (int i = 0; i < 2048; ++i) { int x = (int)@in.next(); if (i < 1024) { Assert.Equal(i / 4, x); } else if (i < 2048) { Assert.Equal(2 * i, x); } else { Assert.Equal(junk[i - 2048], x); } } for (int i = 2047; i >= 0; --i) { @in.seek(positions[i]); int x = (int)@in.next(); if (i < 1024) { Assert.Equal(i / 4, x); } else if (i < 2048) { Assert.Equal(2 * i, x); } else { Assert.Equal(junk[i - 2048], x); } } }
public void testSkips() { TestInStream.OutputCollector collect = new TestInStream.OutputCollector(); RunLengthIntegerWriterV2 @out = new RunLengthIntegerWriterV2( new OutStream("test", 100, null, collect), true); for (int i = 0; i < 2048; ++i) { if (i < 1024) { @out.write(i); } else { @out.write(256 * i); } } @out.flush(); ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size()); collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size()); inBuf.flip(); #pragma warning disable 612 RunLengthIntegerReaderV2 @in = new RunLengthIntegerReaderV2(InStream.create(null, "test", new ByteBuffer[] { inBuf }, new long[] { 0 }, inBuf.remaining(), null, 100), true, false); #pragma warning restore 612 for (int i = 0; i < 2048; i += 10) { int x = (int)@in.next(); if (i < 1024) { Assert.Equal(i, x); } else { Assert.Equal(256 * i, x); } if (i < 2038) { @in.skip(9); } @in.skip(0); } }