@Test
public void testInt64Compression()
throws Exception
{
FixedSizeUnsafeAllocator allocator = new FixedSizeUnsafeAllocator( 1, 9 );
try
{
for ( int i = 0; i < 8; i++ )
{
long[] values = new long[TEST_VALUES_COUNT];
Random random = new Random( -System.currentTimeMillis() );
int min = ( 0x1 << ( i * 8 ) );
int max = ( 0xFF << ( i * 8 ) );
for ( int o = 0; o < TEST_VALUES_COUNT; o++ )
{
values[o] = (long) ( random.nextDouble() * ( max - min + 1 ) ) + min;
}
MemoryBuffer buffer = allocator.allocate( 5 );
for ( int v = 0; v < TEST_VALUES_COUNT; v++ )
{
long value = values[v];
buffer.clear();
buffer.writeCompressedLong( value );
checkLongLength( value, buffer.writerIndex() );
long result = buffer.readCompressedLong();
assertEquals( value, result );
}
allocator.free( buffer );
}
}
finally
{
allocator.close();
}
}