Skip to content
Browse files

Adding interlace test for CartesianGeoRecord interlace

  • Loading branch information...
1 parent 7e47d67 commit f15c7b3112f8665a0a31a28de292d4a189f266a0 @gcooney committed Jul 10, 2012
View
60 ...b/src/test/java/com/browseengine/bobo/geosearch/impl/CartesianGeoRecordInterlaceTest.java
@@ -0,0 +1,60 @@
+package com.browseengine.bobo.geosearch.impl;
+
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Comparator;
+
+import org.junit.runners.Parameterized.Parameters;
+
+import com.browseengine.bobo.geosearch.CartesianCoordinateDocId;
+import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord;
+
+/**
+ * CartesianGeoRecord implementation of interlace class
+ *
+ * @author gcooney
+ *
+ */
+public class CartesianGeoRecordInterlaceTest extends InterlaceTezt<CartesianGeoRecord> {
+
+ public CartesianGeoRecordInterlaceTest(DimensionSpec[] dimensionSpecs, boolean[] holdConstant) {
+ super(dimensionSpecs, holdConstant);
+ }
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ DimensionSpec[] dimensionSpecs = new DimensionSpec[4];
+
+ dimensionSpecs[0] = new DimensionSpec("x", Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
+ dimensionSpecs[1] = new DimensionSpec("y", Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
+ dimensionSpecs[2] = new DimensionSpec("z", Integer.MIN_VALUE, Integer.MAX_VALUE, 2);
+ dimensionSpecs[3] = new DimensionSpec("docid", 0, Integer.MAX_VALUE, 1);
+
+ return buildDataFromDimensionSpecs(dimensionSpecs);
+ }
+
+ @Override
+ protected CartesianGeoRecord buildGeoRecord(int[] values, int identifier) {
+ return geoConverter.toCartesianGeoRecord(values[0], values[1], values[2], values[3], (byte)0);
+ }
+
+ @Override
+ protected Comparator<CartesianGeoRecord> getGeoRecordComparator() {
+ return new CartesianGeoRecordComparator();
+ }
+
+ @Override
+ protected void validateGeoRecord(CartesianGeoRecord actualResult, int[] values, int identifier) {
+ CartesianCoordinateDocId actualCoordinate = geoConverter.toCartesianCoordinateDocId(actualResult);
+
+ assertTrue("x should not change: expected=" + values[0] + "; actual=" +
+ actualCoordinate.x, values[0] - actualCoordinate.x == 0);
+ assertTrue("y should not change by more than 1: expected=" + values[1] + "; actual=" +
+ actualCoordinate.y, Math.abs(values[1] - actualCoordinate.y) <= 1);
+ assertTrue("z should not change by more than 1: expected=" + values[2] + "; actual=" +
+ actualCoordinate.z, Math.abs(values[2] - actualCoordinate.z) <= 1);
+ assertTrue("doc should not change: expected=" + values[3] + "; actual=" +
+ actualCoordinate.docid, Math.abs(values[2] - actualCoordinate.z) <= 1);
+ }
+}
View
6 ...-contrib/src/test/java/com/browseengine/bobo/geosearch/impl/IDGeoRecordInterlaceTest.java
@@ -22,9 +22,9 @@ public IDGeoRecordInterlaceTest(DimensionSpec[] dimensionSpecs, boolean[] holdCo
public static Collection<Object[]> data() {
DimensionSpec[] dimensionSpecs = new DimensionSpec[3];
- dimensionSpecs[0] = new DimensionSpec("x", Integer.MIN_VALUE, Integer.MAX_VALUE);
- dimensionSpecs[1] = new DimensionSpec("y", Integer.MIN_VALUE, Integer.MAX_VALUE);
- dimensionSpecs[2] = new DimensionSpec("z", Integer.MIN_VALUE, Integer.MAX_VALUE);
+ dimensionSpecs[0] = new DimensionSpec("x", Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
+ dimensionSpecs[1] = new DimensionSpec("y", Integer.MIN_VALUE, Integer.MAX_VALUE, 2);
+ dimensionSpecs[2] = new DimensionSpec("z", Integer.MIN_VALUE, Integer.MAX_VALUE, 2);
return buildDataFromDimensionSpecs(dimensionSpecs);
}
View
39 bobo-contrib/src/test/java/com/browseengine/bobo/geosearch/impl/InterlaceTezt.java
@@ -14,6 +14,12 @@
import com.browseengine.bobo.geosearch.bo.IGeoRecord;
+/**
+ * Provides an abstract tests class for validating GeoRecord bit-interlace functions
+ * @author gcooney
+ *
+ * @param <T>
+ */
@RunWith(Parameterized.class)
public abstract class InterlaceTezt<T extends IGeoRecord> {
@@ -30,7 +36,7 @@ public InterlaceTezt(DimensionSpec[] dimensionSpecs, boolean[] holdConstant) {
public void testToIDGeoRecordOrder_LargeDelta() {
int totalCoordinates = 10000;
int start = Integer.MIN_VALUE;
- int delta = 2 * (Integer.MAX_VALUE / totalCoordinates);
+ int delta = getDelta(2 * (Integer.MAX_VALUE / totalCoordinates));
createRecordsAndValidateSortOrder(dimensionSpecs, start, delta, totalCoordinates);
}
@@ -39,16 +45,16 @@ public void testToIDGeoRecordOrder_LargeDelta() {
public void testToIDGeoRecordOrder_SmallDelta() {
int totalCoordinates = 10000;
int start = -5000;
- int delta = 1;
-
+ int delta = getDelta(1);
+
createRecordsAndValidateSortOrder(dimensionSpecs, start, delta, totalCoordinates);
}
@Test
public void testToIDGeoRecordOrder_TinyDelta() {
int totalCoordinates = 10;
int start = -5;
- int delta = 1;
+ int delta = getDelta(1);
createRecordsAndValidateSortOrder(dimensionSpecs, start, delta, totalCoordinates);
}
@@ -57,7 +63,7 @@ public void testToIDGeoRecordOrder_TinyDelta() {
public void testInterlaceThenUninterlace_LargeRange() {
int totalCoordinates = 10000;
int start = Integer.MIN_VALUE;
- int delta = 2 * (Integer.MAX_VALUE / totalCoordinates);
+ int delta = getDelta(2 * (Integer.MAX_VALUE / totalCoordinates));
interlaceAndUninterlace(dimensionSpecs, start, delta, totalCoordinates);
}
@@ -66,7 +72,7 @@ public void testInterlaceThenUninterlace_LargeRange() {
public void testInterlaceThenUninterlace_SmallRange() {
int totalCoordinates = 100;
int start = -50;
- int delta = 1;
+ int delta = getDelta(1);
interlaceAndUninterlace(dimensionSpecs, start, delta, totalCoordinates);
}
@@ -87,6 +93,18 @@ public void testInterlaceThenUninterlace_EveryPowerOfTwo_XOnly() {
}
}
+ private int getDelta(int requestedDelta) {
+ int delta = requestedDelta;
+
+ for (int i = 0; i < dimensionSpecs.length; i++) {
+ if (!holdConstant[i]) {
+ delta = Math.max(delta, dimensionSpecs[i].minDelta);
+ }
+ }
+
+ return delta;
+ }
+
private void interlaceAndUninterlace(DimensionSpec[] specs, int start, int delta,
int totalCoordinates) {
for (int i = 0; i < totalCoordinates; i++) {
@@ -103,12 +121,12 @@ private void interlaceAndUninterlace(DimensionSpec[] specs, int start, int delta
for (int j = 0; j < specs.length; j++) {
DimensionSpec spec = specs[j];
if (holdConstant[j]) {
- values[j] = 0;
+ values[j] = start + currentCoordinate * delta;
} else {
int specDelta = delta;
int specStart = start;
if (start < spec.minValue) {
- specDelta = (int)(((double)delta * totalCoordinates - start + spec.minValue) / totalCoordinates);
+ specDelta = (int)(((double)delta * totalCoordinates + start - spec.minValue) / totalCoordinates);
specStart = spec.minValue;
}
@@ -130,6 +148,7 @@ private void createRecordsAndValidateSortOrder(DimensionSpec[] specs, int start,
list.add(geoRecord);
tree.add(geoRecord);
+
}
int i = 0;
@@ -174,11 +193,13 @@ private void createRecordsAndValidateSortOrder(DimensionSpec[] specs, int start,
final String dimensionName;
final int minValue;
final int maxValue;
+ final int minDelta;
- public DimensionSpec(String dimensionName, int minValue, int maxValue) {
+ public DimensionSpec(String dimensionName, int minValue, int maxValue, int minDelta) {
this.dimensionName = dimensionName;
this.minValue = minValue;
this.maxValue = maxValue;
+ this.minDelta = minDelta;
}
}
}

0 comments on commit f15c7b3

Please sign in to comment.
Something went wrong with that request. Please try again.