(int numBits)
| 73 | } |
| 74 | |
| 75 | private void runTest(int numBits) throws IOException { |
| 76 | long[] inp = new long[SIZE]; |
| 77 | for (int i = 0; i < SIZE; i++) { |
| 78 | long val = 0; |
| 79 | if (numBits <= 32) { |
| 80 | if (numBits == 1) { |
| 81 | val = -1 * rand.nextInt(2); |
| 82 | } else { |
| 83 | val = rand.nextInt((int) Math.pow(2, numBits - 1)); |
| 84 | } |
| 85 | } else { |
| 86 | val = nextLong(rand, (long) Math.pow(2, numBits - 2)); |
| 87 | } |
| 88 | if (val % 2 == 0) { |
| 89 | val = -val; |
| 90 | } |
| 91 | inp[i] = val; |
| 92 | } |
| 93 | long[] deltaEncoded = deltaEncode(inp); |
| 94 | long minInput = Collections.min(Longs.asList(deltaEncoded)); |
| 95 | long maxInput = Collections.max(Longs.asList(deltaEncoded)); |
| 96 | long rangeInput = maxInput - minInput; |
| 97 | SerializationUtils utils = new SerializationUtils(); |
| 98 | int fixedWidth = utils.findClosestNumBits(rangeInput); |
| 99 | TestInStream.OutputCollector collect = new TestInStream.OutputCollector(); |
| 100 | OutStream output = new OutStream("test", new StreamOptions(SIZE), collect); |
| 101 | utils.writeInts(deltaEncoded, 0, deltaEncoded.length, fixedWidth, output); |
| 102 | output.flush(); |
| 103 | ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size()); |
| 104 | collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size()); |
| 105 | inBuf.flip(); |
| 106 | long[] buff = new long[SIZE]; |
| 107 | utils.readInts(buff, 0, SIZE, fixedWidth, |
| 108 | InStream.create("test", new BufferChunk(inBuf,0), 0, |
| 109 | inBuf.remaining())); |
| 110 | for (int i = 0; i < SIZE; i++) { |
| 111 | buff[i] = utils.zigzagDecode(buff[i]); |
| 112 | } |
| 113 | assertEquals(numBits, fixedWidth); |
| 114 | assertArrayEquals(inp, buff); |
| 115 | } |
| 116 | |
| 117 | @Test |
| 118 | public void test01BitPacking1Bit() throws IOException { |
no test coverage detected