@Test public void visit() { final int m0 = 1, m2 = 3; final MultiDimensionalSpec spec = new MultiDimensionalSpec(ImmutableList.of(m0, 0, m2)); SpaceVisitor mock = EasyMock.createStrictMock(SpaceVisitor.class); BitVector[] p = new BitVector[] {null, BitVectorFactories.OPTIMAL.apply(0), null}; BitVector[] q = new BitVector[] {BitVectorFactories.OPTIMAL.apply(m0), BitVectorFactories.OPTIMAL.apply(0), BitVectorFactories.OPTIMAL.apply(m2)}; for (int index = 0; index < 1 << (m0 + m2); ++index) { BitVector indexBs = BitVectorFactories.OPTIMAL.apply(m0 + m2); indexBs.copyFrom(index); IndexCalculator fake = new FakeSpaceFillingCurve(spec, indexBs); ZoomingSpaceVisitorAdapter adaptor = new ZoomingSpaceVisitorAdapter(fake, mock); for (int i = 0; i < 1 << m0; ++i) { p[0] = BitVectorFactories.OPTIMAL.apply(m0); p[0].copyFrom(i); for (int j = 0; j < 1 << m2; ++j) { p[2] = BitVectorFactories.OPTIMAL.apply(m2); p[2].copyFrom(j); for (int level = 0; level <= spec.maxBitsPerDimension(); ++level) { for (int l = 0; l < p.length; ++l) { q[l].copyFrom(p[l]); q[l].clear(0, Math.min(l == 0 ? m0 : (l == 1 ? 0 : m2), level)); } BitVector indexEndBs = indexBs.clone(); int lowOrderBitCount = level <= m0 ? (2 * level) : m0 + level; indexEndBs.clear(0, lowOrderBitCount); Pow2LengthBitSetRange x = new Pow2LengthBitSetRange( TestUtils.createBitVector(i >>> level << level, m0), Math.min(m0, level)); Pow2LengthBitSetRange y = new Pow2LengthBitSetRange(BitVectorFactories.OPTIMAL.apply(0), 0); Pow2LengthBitSetRange z = new Pow2LengthBitSetRange( TestUtils.createBitVector(j >>> level << level, m2), level); List<Pow2LengthBitSetRange> ranges = ImmutableList.of(x, y, z); for (int b = 0; b < 2; ++b) { EasyMock.expect(mock.visit(EasyMock.eq( new Pow2LengthBitSetRange(indexEndBs, lowOrderBitCount)), EasyMock.eq(ranges))) .andReturn(b % 2 == 0); EasyMock.replay(mock); Assert.assertEquals(b % 2 == 0, adaptor.visit(level, indexEndBs, q)); EasyMock.verify(mock); EasyMock.reset(mock); } } } } } }
@Override public boolean visit(int level, BitVector index, BitVector[] p) { checkArguments(level, p); Pow2LengthBitSetRange[] ranges = new Pow2LengthBitSetRange[p.length]; int n = p.length; int lowOrderBitCount = 0; for (int i = 0; i < n; ++i) { int realLevel = Math.min(m[i], level); ranges[i] = new Pow2LengthBitSetRange(p[i], realLevel); lowOrderBitCount += realLevel; } assert computeIndex(p, level).equals(index); assert index.areAllLowestBitsClear(lowOrderBitCount); boolean needChildren = visitor.visit( new Pow2LengthBitSetRange(index, lowOrderBitCount), Collections.unmodifiableList(Arrays.asList(ranges))); return needChildren; }
ZoomingSpaceVisitorAdapter implements ZoomingNavigator { @Override public boolean visit(int level, BitVector index, BitVector[] p) { checkArguments(level, p); Pow2LengthBitSetRange[] ranges = new Pow2LengthBitSetRange[p.length]; int n = p.length; int lowOrderBitCount = 0; for (int i = 0; i < n; ++i) { int realLevel = Math.min(m[i], level); ranges[i] = new Pow2LengthBitSetRange(p[i], realLevel); lowOrderBitCount += realLevel; } assert computeIndex(p, level).equals(index); assert index.areAllLowestBitsClear(lowOrderBitCount); boolean needChildren = visitor.visit( new Pow2LengthBitSetRange(index, lowOrderBitCount), Collections.unmodifiableList(Arrays.asList(ranges))); return needChildren; } }
ZoomingSpaceVisitorAdapter implements ZoomingNavigator { @Override public boolean visit(int level, BitVector index, BitVector[] p) { checkArguments(level, p); Pow2LengthBitSetRange[] ranges = new Pow2LengthBitSetRange[p.length]; int n = p.length; int lowOrderBitCount = 0; for (int i = 0; i < n; ++i) { int realLevel = Math.min(m[i], level); ranges[i] = new Pow2LengthBitSetRange(p[i], realLevel); lowOrderBitCount += realLevel; } assert computeIndex(p, level).equals(index); assert index.areAllLowestBitsClear(lowOrderBitCount); boolean needChildren = visitor.visit( new Pow2LengthBitSetRange(index, lowOrderBitCount), Collections.unmodifiableList(Arrays.asList(ranges))); return needChildren; } ZoomingSpaceVisitorAdapter(IndexCalculator curve, SpaceVisitor visitor); }
ZoomingSpaceVisitorAdapter implements ZoomingNavigator { @Override public boolean visit(int level, BitVector index, BitVector[] p) { checkArguments(level, p); Pow2LengthBitSetRange[] ranges = new Pow2LengthBitSetRange[p.length]; int n = p.length; int lowOrderBitCount = 0; for (int i = 0; i < n; ++i) { int realLevel = Math.min(m[i], level); ranges[i] = new Pow2LengthBitSetRange(p[i], realLevel); lowOrderBitCount += realLevel; } assert computeIndex(p, level).equals(index); assert index.areAllLowestBitsClear(lowOrderBitCount); boolean needChildren = visitor.visit( new Pow2LengthBitSetRange(index, lowOrderBitCount), Collections.unmodifiableList(Arrays.asList(ranges))); return needChildren; } ZoomingSpaceVisitorAdapter(IndexCalculator curve, SpaceVisitor visitor); @Override boolean visit(int level, BitVector index, BitVector[] p); }
ZoomingSpaceVisitorAdapter implements ZoomingNavigator { @Override public boolean visit(int level, BitVector index, BitVector[] p) { checkArguments(level, p); Pow2LengthBitSetRange[] ranges = new Pow2LengthBitSetRange[p.length]; int n = p.length; int lowOrderBitCount = 0; for (int i = 0; i < n; ++i) { int realLevel = Math.min(m[i], level); ranges[i] = new Pow2LengthBitSetRange(p[i], realLevel); lowOrderBitCount += realLevel; } assert computeIndex(p, level).equals(index); assert index.areAllLowestBitsClear(lowOrderBitCount); boolean needChildren = visitor.visit( new Pow2LengthBitSetRange(index, lowOrderBitCount), Collections.unmodifiableList(Arrays.asList(ranges))); return needChildren; } ZoomingSpaceVisitorAdapter(IndexCalculator curve, SpaceVisitor visitor); @Override boolean visit(int level, BitVector index, BitVector[] p);  }