lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject lucene-solr:master: LUCENE-7185: fix edge case bug in test logic (min=max=180), don't leak Directory for edge cases!
Date Thu, 07 Apr 2016 04:08:55 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master b59ace99e -> 2965ac2ca


LUCENE-7185: fix edge case bug in test logic (min=max=180), don't leak Directory for edge
cases!


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2965ac2c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2965ac2c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2965ac2c

Branch: refs/heads/master
Commit: 2965ac2ca18e2019fb9f03170b9bcf98162a9d21
Parents: b59ace9
Author: Robert Muir <rmuir@apache.org>
Authored: Thu Apr 7 00:08:03 2016 -0400
Committer: Robert Muir <rmuir@apache.org>
Committed: Thu Apr 7 00:08:03 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/lucene/geo/Rectangle.java   |  2 +-
 .../spatial/util/BaseGeoPointTestCase.java      | 37 +++++++++++---------
 2 files changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2965ac2c/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java b/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
index 527395e..592e202 100644
--- a/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
+++ b/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
@@ -66,7 +66,7 @@ public class Rectangle {
   @Override
   public String toString() {
     StringBuilder b = new StringBuilder();
-    b.append("GeoRect(lat=");
+    b.append("Rectangle(lat=");
     b.append(minLat);
     b.append(" TO ");
     b.append(maxLat);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2965ac2c/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
index 6ae4d20..adca466 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
@@ -738,7 +738,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
   static final boolean rectContainsPoint(Rectangle rect, double pointLat, double pointLon)
{
     assert Double.isNaN(pointLat) == false;
 
-    if (rect.minLon < rect.maxLon) {
+    if (rect.minLon <= rect.maxLon) {
       return GeoRelationUtils.pointInRectPrecise(pointLat, pointLon, rect.minLat, rect.maxLat,
rect.minLon, rect.maxLon);
     } else {
       // Rect crosses dateline:
@@ -1223,26 +1223,29 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase
{
     // exact edge cases
     assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, rect.maxLat, rect.minLon,
rect.maxLon)));
     
-    // expand 1 ulp in each direction
-    assumeFalse("can't expand box, its too big already", rect.minLat ==  -90);
-    assumeFalse("can't expand box, its too big already", rect.maxLat ==   90);
-    assumeFalse("can't expand box, its too big already", rect.minLon == -180);
-    assumeFalse("can't expand box, its too big already", rect.maxLon ==  180);
-    assertEquals(8, s.count(newRectQuery(FIELD_NAME, Math.nextDown(rect.minLat), rect.maxLat,
rect.minLon, rect.maxLon)));
-    assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, Math.nextUp(rect.maxLat),
rect.minLon, rect.maxLon)));
-    assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, rect.maxLat, Math.nextDown(rect.minLon),
rect.maxLon)));
-    assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, rect.maxLat, rect.minLon,
Math.nextUp(rect.maxLon))));
+    // expand 1 ulp in each direction if possible and test a slightly larger box!
+    if (rect.minLat != -90) {
+      assertEquals(8, s.count(newRectQuery(FIELD_NAME, Math.nextDown(rect.minLat), rect.maxLat,
rect.minLon, rect.maxLon)));
+    }
+    if (rect.maxLat != 90) {
+      assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, Math.nextUp(rect.maxLat),
rect.minLon, rect.maxLon)));
+    }
+    if (rect.minLon != -180) {
+      assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, rect.maxLat, Math.nextDown(rect.minLon),
rect.maxLon)));
+    }
+    if (rect.maxLon != 180) {
+      assertEquals(8, s.count(newRectQuery(FIELD_NAME, rect.minLat, rect.maxLat, rect.minLon,
Math.nextUp(rect.maxLon))));
+    }
     
-    // now shrink 1 ulp in each direction: it should not include bogus stuff
-    assumeFalse("can't shrink box, its too small already", rect.minLat ==   90);
-    assumeFalse("can't shrink box, its too small already", rect.maxLat ==  -90);
-    assumeFalse("can't shrink box, its too small already", rect.minLon ==  180);
-    assumeFalse("can't shrink box, its too small already", rect.maxLon == -180);
-    // note we put points on "sides" not just "corners" so we just shrink all 4 at once for
now: it should exclude all points!
-    assertEquals(0, s.count(newRectQuery(FIELD_NAME, Math.nextUp(rect.minLat), 
+    // now shrink 1 ulp in each direction if possible: it should not include bogus stuff
+    if (rect.minLat != 90 && rect.maxLat != -90 && rect.minLon != 80 &&
rect.maxLon != -180) {
+      // note we put points on "sides" not just "corners" so we just shrink all 4 at once
for now: it should exclude all points!
+      assertEquals(0, s.count(newRectQuery(FIELD_NAME, Math.nextUp(rect.minLat), 
                                                      Math.nextDown(rect.maxLat), 
                                                      Math.nextUp(rect.minLon), 
                                                      Math.nextDown(rect.maxLon))));
+    }
+
     r.close();
     w.close();
     dir.close();


Mime
View raw message