Apache Lucene open-source search software
LUCENE-6196: committing Karl's latest patch https://reviews.apache.org/r/33780/ (diff #1)
David Wayne Smiley1b901cab9ae6
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.javaindex 08dd46423a7..02d38d85248 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java@@ -205,11 +205,15 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {@Overrideprotected Geo3dShape generateRandomShape(Point nearP) {+ final Point centerPoint = randomPoint();+ final int maxDistance = random().nextInt(160) + 20;final int vertexCount = random().nextInt(3) + 3;while (true) {final List<GeoPoint> geoPoints = new ArrayList<>();while (geoPoints.size() < vertexCount) {final Point point = randomPoint();+ if (ctx.getDistCalc().distance(point,centerPoint) > maxDistance)+ continue;final GeoPoint gPt = new GeoPoint(point.getY() * DEGREES_TO_RADIANS, point.getX() * DEGREES_TO_RADIANS);geoPoints.add(gPt);}@@ -230,6 +234,12 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {throw new IllegalStateException("unexpected; need to finish test code");}+ @Override+ protected int getWithinMinimum(int laps) {+ // Long/thin so only 10% of the usual figure+ return laps/10000;+ }+}.testRelateWithRectangle();}@@ -239,14 +249,20 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {@Overrideprotected Geo3dShape generateRandomShape(Point nearP) {+ final Point centerPoint = randomPoint();+ final int maxDistance = random().nextInt(160) + 20;final int pointCount = random().nextInt(5) + 1;final double width = (random().nextInt(89)+1) * DEGREES_TO_RADIANS;while (true) {try {final GeoPath path = new GeoPath(width);- for (int i = 0; i < pointCount; i++) {+ int i = 0;+ while (i < pointCount) {final Point nextPoint = randomPoint();+ if (ctx.getDistCalc().distance(nextPoint,centerPoint) > maxDistance)+ continue;path.addPoint(nextPoint.getY() * DEGREES_TO_RADIANS, nextPoint.getX() * DEGREES_TO_RADIANS);+ i++;}path.done();return new Geo3dShape(path, ctx);@@ -263,6 +279,12 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {throw new IllegalStateException("unexpected; need to finish test code");}+ @Override+ protected int getWithinMinimum(int laps) {+ // Long/thin so only 10% of the usual figure+ return laps/10000;+ }+}.testRelateWithRectangle();}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.javaindex 9040409d43f..78460e4f7f9 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java@@ -44,6 +44,32 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random/** shape has no area; return a point in it */protected abstract Point randomPointInEmptyShape(S shape);+ // Minimum distribution of relationships++ // Each shape has different characteristics, so we don't expect (for instance) shapes that+ // are likely to be long and thin to contain as many rectangles as those that+ // short and fat.++ protected int getContainsMinimum(int laps) {+ return laps/1000;+ }++ protected int getIntersectsMinimum(int laps) {+ return laps/1000;+ }++ protected int getWithinMinimum(int laps) {+ return laps/1000;+ }++ protected int getDisjointMinimum(int laps) {+ return laps/1000;+ }++ protected int getBoundingMinimum(int laps) {+ return laps/1000;+ }+@SuppressWarnings("unchecked")@Overrideprotected Point randomPointIn(Shape shape) {@@ -59,17 +85,22 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random//counters for the different intersection casesint i_C = 0, i_I = 0, i_W = 0, i_D = 0, i_bboxD = 0;int laps = 0;- final int MINLAPSPERCASE = scaledRandomIntBetween(20, 200);- while(i_C < MINLAPSPERCASE || i_I < MINLAPSPERCASE || i_W < MINLAPSPERCASE- || (!isRandomShapeRectangular() && i_D < MINLAPSPERCASE) || i_bboxD < MINLAPSPERCASE) {+ final int MINLAPS = scaledRandomIntBetween(20000, 200000);+ while(i_C < getContainsMinimum(MINLAPS) || i_I < getIntersectsMinimum(MINLAPS) || i_W < getWithinMinimum(MINLAPS)+ || (!isRandomShapeRectangular() && i_D < getDisjointMinimum(MINLAPS)) || i_bboxD < getBoundingMinimum(MINLAPS)) {laps++;TestLog.clear();- if (laps > MINLAPSPERCASE * 1000) {- fail("Did not find enough intersection cases in a reasonable number" +- " of random attempts. CWIDbD: " + i_C + "," + i_W + "," + i_I + "," + i_D + "," + i_bboxD- + " Laps exceeded " + MINLAPSPERCASE * 1000);+ if (laps > MINLAPS) {+ fail("Did not find enough contains/within/intersection/disjoint/bounds cases in a reasonable number" ++ " of random attempts. CWIDbD: " ++ i_C + "("+getContainsMinimum(MINLAPS)+")," ++ i_W + "("+getWithinMinimum(MINLAPS)+")," ++ i_I + "("+getIntersectsMinimum(MINLAPS)+")," ++ i_D + "("+getDisjointMinimum(MINLAPS)+")," ++ i_bboxD + "("+getBoundingMinimum(MINLAPS)+")"+ + " Laps exceeded " + MINLAPS);}Point nearP = randomPointIn(ctx.getWorldBounds());@@ -109,7 +140,7 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Randomcase DISJOINT:if (!s.getBoundingBox().relate(r).intersects()) {//bboxes are disjointi_bboxD++;- if (i_bboxD > MINLAPSPERCASE)+ if (i_bboxD >= getBoundingMinimum(MINLAPS))break;} else {i_D++;@@ -195,4 +226,4 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Randomreturn ctx.makeRectangle(minX, maxX, minY, maxY);}-}\ No newline at end of file+}