public class TestLinearHashing extends TestCase {
public void testBasics() {
int capacity;
int unitCapacity = DynamicConstants.SUB_ARRAY_SIZE;
LinearHashing h = new LinearHashing(unitCapacity);
assertEquals(unitCapacity, h.getUnitCapacity());
assertEquals(0, h.getSplit());
assertEquals(0, h.getLevel());
assertEquals(unitCapacity, h.getLevelCapacity());
capacity = unitCapacity;
assertEquals(0, h.getSplit());
assertEquals(0, h.getLevel());
assertEquals(unitCapacity, h.getLevelCapacity());
capacity = unitCapacity << 1;
h.reinit(capacity);
assertEquals(0, h.getSplit());
assertEquals(0, h.getLevel());
assertEquals(unitCapacity, h.getLevelCapacity());
capacity = unitCapacity << 2;
h.reinit(capacity);
assertEquals(unitCapacity, h.getSplit());
assertEquals(1, h.getLevel());
assertEquals(unitCapacity << 1, h.getLevelCapacity());
capacity = unitCapacity << 3;
h.reinit(capacity);
assertEquals((unitCapacity << 2) - unitCapacity, h.getSplit());
assertEquals(2, h.getLevel());
assertEquals(unitCapacity << 2, h.getLevelCapacity());
capacity = (unitCapacity << 3) - 1;
h.reinit(capacity);
assertEquals((unitCapacity << 2) - 2 * unitCapacity, h.getSplit());
assertEquals(2, h.getLevel());
assertEquals(unitCapacity << 2, h.getLevelCapacity());
capacity = (unitCapacity << 3) - unitCapacity + 1;
h.reinit(capacity);
assertEquals((unitCapacity << 2) - 2 * unitCapacity, h.getSplit());
assertEquals(2, h.getLevel());
assertEquals(unitCapacity << 2, h.getLevelCapacity());
capacity = (unitCapacity << 3) - unitCapacity;
h.reinit(capacity);
assertEquals((unitCapacity << 2) - 2 * unitCapacity, h.getSplit());
assertEquals(2, h.getLevel());
assertEquals(unitCapacity << 2, h.getLevelCapacity());
capacity = Integer.MAX_VALUE;
h.reinit(capacity);
assertEquals((1 << 30) - (unitCapacity << 1), h.getSplit());
assertEquals(14, h.getLevel());
assertEquals(1 << 30, h.getLevelCapacity());
}