test for correct bytebuffer folding

This commit is contained in:
Xavier Léauté 2014-05-22 17:48:19 -07:00
parent cc40a3394d
commit df3fb07e51
1 changed files with 18 additions and 0 deletions

View File

@ -298,6 +298,24 @@ public class HyperLogLogCollectorTest
}
}
@Test
public void testBufferSwap() throws Exception
{
ByteBuffer biggerOffset = makeCollectorBuffer(1, (byte) 0x00, 0x11);
ByteBuffer smallerOffset = makeCollectorBuffer(0, (byte) 0x20, 0x00);
ByteBuffer buffer = ByteBuffer.allocate(HyperLogLogCollector.getLatestNumBytesForDenseStorage());
HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buffer);
// make sure the original buffer gets modified
collector.fold(biggerOffset);
Assert.assertEquals(collector, HyperLogLogCollector.makeCollector(buffer));
// make sure the original buffer gets modified
collector.fold(smallerOffset);
Assert.assertEquals(collector, HyperLogLogCollector.makeCollector(buffer));
}
@Test
public void testFoldWithArbitraryInitialPositions() throws Exception
{