testPerformance2d();
testPerformance3d();
}
private void testHelperMethods() {
MultiDimension m = MultiDimension.getInstance();
assertEquals(Integer.MAX_VALUE, m.getMaxValue(2));
assertEquals(0, m.normalize(2, 0, 0, 100));
assertEquals(Integer.MAX_VALUE / 2, m.normalize(2, 50, 0, 100));
assertEquals(Integer.MAX_VALUE, m.normalize(2, 100, 0, 100));
assertEquals(Integer.MAX_VALUE / 10, m.normalize(2, 0.1, 0, 1));
assertEquals(0, m.normalize(2, 1, 1, 1));
assertEquals(0, m.normalize(2, 0, 0, 0));
assertEquals(3, m.interleave(1, 1));
assertEquals(3, m.interleave(new int[]{1, 1}));
assertEquals(5, m.interleave(3, 0));
assertEquals(5, m.interleave(new int[]{3, 0}));
assertEquals(10, m.interleave(0, 3));
assertEquals(10, m.interleave(new int[] { 0, 3 }));
long v = Integer.MAX_VALUE | ((long) Integer.MAX_VALUE << 31L);
assertEquals(v, m.interleave(Integer.MAX_VALUE, Integer.MAX_VALUE));
assertEquals(v, m.interleave(new int[] { Integer.MAX_VALUE, Integer.MAX_VALUE }));
Random random = new Random(1);
for (int i = 0; i < 1000; i++) {
int x = random.nextInt(Integer.MAX_VALUE), y = random.nextInt(Integer.MAX_VALUE);
v = m.interleave(new int[] {x, y});
long v2 = m.interleave(x, y);
assertEquals(v, v2);
int x1 = m.deinterleave(2, v, 0);
int y1 = m.deinterleave(2, v, 1);
assertEquals(x, x1);
assertEquals(y, y1);
}
for (int i = 0; i < 1000; i++) {
int x = random.nextInt(1000), y = random.nextInt(1000), z = random.nextInt(1000);
MultiDimension tool = MultiDimension.getInstance();
long xyz = tool.interleave(new int[] { x, y, z });
assertEquals(x, tool.deinterleave(3, xyz, 0));
assertEquals(y, tool.deinterleave(3, xyz, 1));
assertEquals(z, tool.deinterleave(3, xyz, 2));
}
createClassProxy(MultiDimension.class);
assertThrows(IllegalArgumentException.class, m).getMaxValue(1);
assertThrows(IllegalArgumentException.class, m).getMaxValue(33);
assertThrows(IllegalArgumentException.class, m).normalize(2, 10, 11, 12);