You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/06/13 06:21:46 UTC
svn commit: r1685211 - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/spatial/ lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/
Author: dsmiley
Date: Sat Jun 13 04:21:45 2015
New Revision: 1685211
URL: http://svn.apache.org/r1685211
Log:
LUCENE-6502: Drastically reduce the probability Geo3d ShapeRectRelationTestCase will complain about not finding enough predicate occurrences.
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/spatial/ (props changed)
lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java
lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java?rev=1685211&r1=1685210&r2=1685211&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java Sat Jun 13 04:21:45 2015
@@ -83,9 +83,27 @@ public abstract class Geo3dShapeRectRela
return GeoBBoxFactory.makeGeoBBox(planetModel, maxLat, minLat, leftLon, rightLon);
}
+ abstract class Geo3dRectIntersectionTestHelper extends RectIntersectionTestHelper<Geo3dShape> {
+
+ public Geo3dRectIntersectionTestHelper(SpatialContext ctx) {
+ super(ctx);
+ }
+
+ @Override
+ protected int getMaxLaps() {
+ //sometimes, getWithinMinimum needs some more attempts then normal; 20k is suggested max.
+ return 200_000;//200k
+ }
+
+ @Override
+ protected int getDefaultMinimumPredicateFrequency(int maxLaps) {
+ return 20;//20 times each -- should be plenty in 200k
+ }
+ }
+
@Test
public void testGeoCircleRect() {
- new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+ new Geo3dRectIntersectionTestHelper(ctx) {
@Override
protected Geo3dShape generateRandomShape(Point nearP) {
@@ -115,7 +133,7 @@ public abstract class Geo3dShapeRectRela
@Test
public void testGeoBBoxRect() {
- new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+ new Geo3dRectIntersectionTestHelper(ctx) {
@Override
protected boolean isRandomShapeRectangular() {
@@ -149,7 +167,7 @@ public abstract class Geo3dShapeRectRela
@Test
public void testGeoPolygonRect() {
- new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+ new Geo3dRectIntersectionTestHelper(ctx) {
@Override
protected Geo3dShape generateRandomShape(Point nearP) {
@@ -184,8 +202,8 @@ public abstract class Geo3dShapeRectRela
@Override
protected int getWithinMinimum(int laps) {
- // Long/thin so only 10% of the usual figure
- return laps/10000;
+ // Long/thin so lets just find 1.
+ return 1;
}
}.testRelateWithRectangle();
@@ -193,7 +211,7 @@ public abstract class Geo3dShapeRectRela
@Test
public void testGeoPathRect() {
- new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+ new Geo3dRectIntersectionTestHelper(ctx) {
@Override
protected Geo3dShape generateRandomShape(Point nearP) {
@@ -229,8 +247,8 @@ public abstract class Geo3dShapeRectRela
@Override
protected int getWithinMinimum(int laps) {
- // Long/thin so only 10% of the usual figure
- return laps/10000;
+ // Long/thin so lets just find 1.
+ return 1;
}
}.testRelateWithRectangle();
Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java?rev=1685211&r1=1685210&r2=1685211&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java Sat Jun 13 04:21:45 2015
@@ -49,27 +49,37 @@ public abstract class RectIntersectionTe
// 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;
+
+ /** Called once by {@link #testRelateWithRectangle()} to determine the max laps to try before failing. */
+ protected int getMaxLaps() {
+ return scaledRandomIntBetween(20_000, 200_000);
+ }
+
+ /** The minimum number of times we need to see each predicate in {@code laps} iterations. */
+ protected int getDefaultMinimumPredicateFrequency(int maxLaps) {
+ return maxLaps / 1000;
+ }
+
+ protected int getContainsMinimum(int maxLaps) {
+ return getDefaultMinimumPredicateFrequency(maxLaps);
+ }
+
+ protected int getIntersectsMinimum(int maxLaps) {
+ return getDefaultMinimumPredicateFrequency(maxLaps);
}
-
+
+ protected int getWithinMinimum(int maxLaps) {
+ return getDefaultMinimumPredicateFrequency(maxLaps);
+ }
+
+ protected int getDisjointMinimum(int maxLaps) {
+ return getDefaultMinimumPredicateFrequency(maxLaps);
+ }
+
+ protected int getBoundingMinimum(int maxLaps) {
+ return getDefaultMinimumPredicateFrequency(maxLaps);
+ }
+
@SuppressWarnings("unchecked")
@Override
protected Point randomPointInOrNull(Shape shape) {
@@ -84,23 +94,23 @@ public abstract class RectIntersectionTe
public void testRelateWithRectangle() {
//counters for the different intersection cases
int i_C = 0, i_I = 0, i_W = 0, i_D = 0, i_bboxD = 0;
- int laps = 0;
- 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++;
+ int lap = 0;
+ final int MAXLAPS = getMaxLaps();
+ while(i_C < getContainsMinimum(MAXLAPS) || i_I < getIntersectsMinimum(MAXLAPS) || i_W < getWithinMinimum(MAXLAPS)
+ || (!isRandomShapeRectangular() && i_D < getDisjointMinimum(MAXLAPS)) || i_bboxD < getBoundingMinimum(MAXLAPS)) {
+ lap++;
LogRule.clear();
- if (laps > MINLAPS) {
+ if (lap > MAXLAPS) {
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);
+ " of attempts. CWIDbD: " +
+ i_C + "("+getContainsMinimum(MAXLAPS)+")," +
+ i_W + "("+getWithinMinimum(MAXLAPS)+")," +
+ i_I + "("+getIntersectsMinimum(MAXLAPS)+")," +
+ i_D + "("+getDisjointMinimum(MAXLAPS)+")," +
+ i_bboxD + "("+getBoundingMinimum(MAXLAPS)+")"
+ + " Laps exceeded " + MAXLAPS);
}
Point nearP = randomPointIn(ctx.getWorldBounds());
@@ -111,7 +121,7 @@ public abstract class RectIntersectionTe
SpatialRelation ic = s.relate(r);
- LogRule.log("S-R Rel: {}, Shape {}, Rectangle {} lap# {}", ic, s, r, laps);
+ LogRule.log("S-R Rel: {}, Shape {}, Rectangle {} lap# {}", ic, s, r, lap);
if (ic != DISJOINT) {
assertTrue("if not disjoint then the shape's bbox shouldn't be disjoint",
@@ -143,7 +153,7 @@ public abstract class RectIntersectionTe
case DISJOINT:
if (!s.getBoundingBox().relate(r).intersects()) {//bboxes are disjoint
i_bboxD++;
- if (i_bboxD >= getBoundingMinimum(MINLAPS))
+ if (i_bboxD >= getBoundingMinimum(MAXLAPS))
break;
} else {
i_D++;
@@ -195,7 +205,7 @@ public abstract class RectIntersectionTe
} // while loop
- System.out.println("Laps: "+laps + " CWIDbD: "+i_C+","+i_W+","+i_I+","+i_D+","+i_bboxD);
+ System.out.println("Laps: "+lap + " CWIDbD: "+i_C+","+i_W+","+i_I+","+i_D+","+i_bboxD);
}
protected void onAssertFail(AssertionError e, S s, Rectangle r, SpatialRelation ic) {