improve geo tests

This commit is contained in:
Mike McCandless 2016-01-26 05:14:20 -05:00
parent bf00c961a2
commit f31560bd8e
3 changed files with 56 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -781,4 +781,3 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
return dir;
}
}