Skip to content

Apache Lucene open-source search software

improve geo tests

Mike McCandlessf31560bd8ee7
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
index 5d0de98e829..e674a95483c 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestGeoPointQuery.java
@@ -348,4 +348,39 @@ public class TestGeoPointQuery extends BaseGeoPointTestCase {
assertEquals(180.0, GeoUtils.mortonUnhashLon(hash), 0);
assertEquals(90.0, GeoUtils.mortonUnhashLat(hash), 0);
}
+
+ public void testEncodeDecode() throws Exception {
+ int iters = atLeast(10000);
+ boolean small = random().nextBoolean();
+ for(int iter=0;iter<iters;iter++) {
+ double lat = randomLat(small);
+ double lon = randomLon(small);
+
+ long enc = GeoUtils.mortonHash(lon, lat);
+ double latEnc = GeoUtils.mortonUnhashLat(enc);
+ double lonEnc = GeoUtils.mortonUnhashLon(enc);
+
+ assertEquals("lat=" + lat + " latEnc=" + latEnc + " diff=" + (lat - latEnc), lat, latEnc, GeoUtils.TOLERANCE);
+ assertEquals("lon=" + lon + " lonEnc=" + lonEnc + " diff=" + (lon - lonEnc), lon, lonEnc, GeoUtils.TOLERANCE);
+ }
+ }
+
+ public void testScaleUnscaleIsStable() throws Exception {
+ int iters = atLeast(1000);
+ boolean small = random().nextBoolean();
+ for(int iter=0;iter<iters;iter++) {
+ double lat = randomLat(small);
+ double lon = randomLon(small);
+
+ long enc = GeoUtils.mortonHash(lon, lat);
+ double latEnc = GeoUtils.mortonUnhashLat(enc);
+ double lonEnc = GeoUtils.mortonUnhashLon(enc);
+
+ long enc2 = GeoUtils.mortonHash(lon, lat);
+ double latEnc2 = GeoUtils.mortonUnhashLat(enc2);
+ double lonEnc2 = GeoUtils.mortonUnhashLon(enc2);
+ assertEquals(latEnc, latEnc2, 0.0);
+ assertEquals(lonEnc, lonEnc2, 0.0);
+ }
+ }
}
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
index 313ec21f289..26a52826d16 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
@@ -112,12 +112,29 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
boolean small = random().nextBoolean();
for(int iter=0;iter<iters;iter++) {
double lat = randomLat(small);
- double latQuantized = LatLonPoint.decodeLat(LatLonPoint.encodeLat(lat));
- assertEquals(lat, latQuantized, LatLonPoint.TOLERANCE);
+ double latEnc = LatLonPoint.decodeLat(LatLonPoint.encodeLat(lat));
+ assertEquals("lat=" + lat + " latEnc=" + latEnc + " diff=" + (lat - latEnc), lat, latEnc, LatLonPoint.TOLERANCE);
double lon = randomLon(small);
- double lonQuantized = LatLonPoint.decodeLon(LatLonPoint.encodeLon(lon));
- assertEquals(lon, lonQuantized, LatLonPoint.TOLERANCE);
+ double lonEnc = LatLonPoint.decodeLon(LatLonPoint.encodeLon(lon));
+ assertEquals("lon=" + lon + " lonEnc=" + lonEnc + " diff=" + (lon - lonEnc), lon, lonEnc, LatLonPoint.TOLERANCE);
+ }
+ }
+
+ public void testScaleUnscaleIsStable() throws Exception {
+ int iters = atLeast(1000);
+ boolean small = random().nextBoolean();
+ for(int iter=0;iter<iters;iter++) {
+ double lat = randomLat(small);
+ double lon = randomLon(small);
+
+ double latEnc = LatLonPoint.decodeLat(LatLonPoint.encodeLat(lat));
+ double lonEnc = LatLonPoint.decodeLon(LatLonPoint.encodeLon(lon));
+
+ double latEnc2 = LatLonPoint.decodeLat(LatLonPoint.encodeLat(latEnc));
+ double lonEnc2 = LatLonPoint.decodeLon(LatLonPoint.encodeLon(lonEnc));
+ assertEquals(latEnc, latEnc2, 0.0);
+ assertEquals(lonEnc, lonEnc2, 0.0);
}
}
}
diff --git a/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java b/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
index 4904d1f5338..91f74803909 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/util/BaseGeoPointTestCase.java
@@ -781,4 +781,3 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
return dir;
}
}
-