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/05/04 07:26:52 UTC

svn commit: r1677527 - in /lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j: Geo3dShapeRectRelationTest.java RectIntersectionTestHelper.java

Author: dsmiley
Date: Mon May  4 05:26:52 2015
New Revision: 1677527

URL: http://svn.apache.org/r1677527
Log:
LUCENE-6196: committing Karl's latest patch
https://reviews.apache.org/r/33780/ (diff #1)

Modified:
    lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
    lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java?rev=1677527&r1=1677526&r2=1677527&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java Mon May  4 05:26:52 2015
@@ -205,11 +205,15 @@ public class Geo3dShapeRectRelationTest
 
       @Override
       protected 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
         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
 
       @Override
       protected 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
         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();
   }
 

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java?rev=1677527&r1=1677526&r2=1677527&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java Mon May  4 05:26:52 2015
@@ -44,6 +44,32 @@ public abstract class RectIntersectionTe
   /** 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")
   @Override
   protected Point randomPointIn(Shape shape) {
@@ -59,17 +85,22 @@ public abstract class RectIntersectionTe
     //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 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 RectIntersectionTe
           case DISJOINT:
             if (!s.getBoundingBox().relate(r).intersects()) {//bboxes are disjoint
               i_bboxD++;
-              if (i_bboxD > MINLAPSPERCASE)
+              if (i_bboxD >= getBoundingMinimum(MINLAPS))
                 break;
             } else {
               i_D++;
@@ -195,4 +226,4 @@ public abstract class RectIntersectionTe
     return ctx.makeRectangle(minX, maxX, minY, maxY);
   }
 
-}
\ No newline at end of file
+}