private void randomBytes_GD(byte[] data, double p) { for (int i = 0; i < data.length; i++) data[i] = randomByteGeometricDistribution(p); }
@Test public void testXLSize() { int size = 10 * 1000 * 1000 + 1; roundTrip(randomBytes_GD(size, 0.01)); }
@Test public void testByteRange() { byte[] data = new byte[256]; for (int i = 0; i < data.length; i++) data[i] = (byte) i; roundTrip(data); }
private byte[] randomBytes_GD(int size, double p) { byte[] data = new byte[size]; randomBytes_GD(data, p); return data; }
@Test public void testTwoByte() { roundTrip(new byte[] { 0, 1 }); }
@Test public void testRansHeader() { byte[] data = randomBytes_GD(1000, 0.01); ByteBuffer compressed = RANS.compress(ByteBuffer.wrap(data), RANS.ORDER.ZERO, null); Assert.assertEquals(compressed.get(), (byte) 0); Assert.assertEquals(compressed.getInt(), compressed.limit() - 9); Assert.assertEquals(compressed.getInt(), data.length); }
@Test public void test1000_0dot1() { roundTrip(randomBytes_GD(1000, 0.1)); }
@Test public void testEmpty() { roundTrip(new byte[0]); }
@Test public void testBuffersMeetBoundaryExpectations() { int size = 1001; ByteBuffer raw = ByteBuffer.wrap(randomBytes_GD(size, 0.01)); for (RANS.ORDER order : RANS.ORDER.values()) { ByteBuffer compressed = RANS.compress(raw, order, null); Assert.assertFalse(raw.hasRemaining()); Assert.assertEquals(raw.limit(), size); Assert.assertEquals(compressed.position(), 0); Assert.assertTrue(compressed.limit() > 10); Assert.assertEquals(compressed.get(), (byte) order.ordinal()); Assert.assertEquals(compressed.getInt(), compressed.limit() - 1 - 4 - 4); Assert.assertEquals(compressed.getInt(), size); compressed.rewind(); ByteBuffer uncompressed = RANS.uncompress(compressed, null); Assert.assertFalse(compressed.hasRemaining()); Assert.assertEquals(uncompressed.limit(), size); Assert.assertEquals(uncompressed.position(), 0); raw.rewind(); } }
@Test public void test1000_0dot01() { roundTrip(randomBytes_GD(1000, 0.01)); }
@Test public void testThreeByte() { roundTrip(new byte[] { 0, 1, 2 }); }
@Test public void testSizeRange_small() { byte[] data = randomBytes_GD(1000, 0.01); ByteBuffer in = ByteBuffer.wrap(data); for (int size = 4; size < data.length; size++) { in.position(0); in.limit(size); roundTrip(in); } }
@Test public void testOneByte() { roundTrip(new byte[] { 0 }); }
@Test public void testLargeSize() { int size = 100 * 1000 + 3; byte[] data = randomBytes_GD(size, 0.01); ByteBuffer in = ByteBuffer.wrap(data); for (int limit = size - 4; limit < size; limit++) { in.position(0); in.limit(limit); roundTrip(in); } }
@Test public void testZeroBytes() { roundTrip(new byte[1000]); }
@Test public void testSizeRange_tiny() { for (int i = 0; i < 20; i++) { byte[] data = randomBytes_GD(100, 0.1); ByteBuffer in = ByteBuffer.wrap(data); for (int size = 1; size < data.length; size++) { in.position(0); in.limit(size); try { roundTrip(in); } catch (AssertionError e) { System.err.printf("Failed at size %d and data %s\n", size, Arrays.toString(data)); throw e; } } } }
@Test public void testFourBytes() { roundTrip(new byte[] { 0, 1, 2, 3 }); }
private static void roundTrip(byte[] data, RANS.ORDER order) { roundTrip(ByteBuffer.wrap(data), order); }
@Test public void testUniBytes() { byte[] data = new byte[1000]; Arrays.fill(data, (byte) 1); roundTrip(data); }
@Test public void testByteMax() { byte[] data = new byte[1000]; Arrays.fill(data, Byte.MAX_VALUE); roundTrip(data); }