Skip to content

Commit 53778ba

Browse files
committed
cleanup and add specific point tests
1 parent e74f950 commit 53778ba

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

server/src/test/java/org/elasticsearch/common/geo/Point2DTests.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public void testOnePoint() throws IOException {
4242
assertThat(reader.getExtent(), equalTo(Extent.fromPoint(x, y)));
4343
assertThat(reader.getExtent(), equalTo(reader.getExtent()));
4444
assertRelation(GeoRelation.QUERY_CROSSES, reader, Extent.fromPoint(x, y));
45-
assertRelation(GeoRelation.QUERY_CROSSES, reader, Extent.fromPoints(x, y, x + randomIntBetween(1, 10), y + randomIntBetween(1, 10)));
46-
assertRelation(GeoRelation.QUERY_CROSSES, reader, Extent.fromPoints(x - randomIntBetween(1, 10), y - randomIntBetween(1, 10), x, y));
47-
assertRelation(GeoRelation.QUERY_CROSSES, reader, Extent.fromPoints(x - randomIntBetween(1, 10), y - randomIntBetween(1, 10),
45+
assertRelation(GeoRelation.QUERY_CROSSES, reader,
46+
Extent.fromPoints(x, y, x + randomIntBetween(1, 10), y + randomIntBetween(1, 10)));
47+
assertRelation(GeoRelation.QUERY_CROSSES, reader,
48+
Extent.fromPoints(x - randomIntBetween(1, 10), y - randomIntBetween(1, 10), x, y));
49+
assertRelation(GeoRelation.QUERY_CROSSES, reader,
50+
Extent.fromPoints(x - randomIntBetween(1, 10), y - randomIntBetween(1, 10),
4851
x + randomIntBetween(1, 10), y + randomIntBetween(1, 10)));
49-
assertRelation(GeoRelation.QUERY_DISJOINT, reader, Extent.fromPoints(x - randomIntBetween(10, 100), y - randomIntBetween(10, 100),
52+
assertRelation(GeoRelation.QUERY_DISJOINT, reader,
53+
Extent.fromPoints(x - randomIntBetween(10, 100), y - randomIntBetween(10, 100),
5054
x - randomIntBetween(1, 10), y - randomIntBetween(1, 10)));
5155
}
5256

server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridTilerTests.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import static org.elasticsearch.common.geo.GeoTestUtils.geometryTreeReader;
3939
import static org.hamcrest.Matchers.equalTo;
4040

41-
// TODO(talevy): more tests
4241
public class GeoGridTilerTests extends ESTestCase {
4342
private static final GeoGridTiler.GeoTileGridTiler GEOTILE = GeoGridTiler.GeoTileGridTiler.INSTANCE;
4443
private static final GeoGridTiler.GeoHashGridTiler GEOHASH = GeoGridTiler.GeoHashGridTiler.INSTANCE;
@@ -120,6 +119,24 @@ public void testGeoTileSetValuesBruteAndRecursivePolygon() throws Exception {
120119
assertArrayEquals(recursiveValues, bruteForceValues);
121120
}
122121

122+
public void testGeoTileSetValuesBruteAndRecursivePoints() throws Exception {
123+
int precision = randomIntBetween(0, 10);
124+
GeoShapeIndexer indexer = new GeoShapeIndexer(true, "test");
125+
Geometry geometry = randomBoolean() ? GeometryTestUtils.randomPoint(false) : GeometryTestUtils.randomMultiPoint(false);
126+
geometry = indexer.prepareForIndexing(geometry);
127+
GeometryTreeReader reader = geometryTreeReader(geometry, GeoShapeCoordinateEncoder.INSTANCE);
128+
MultiGeoValues.GeoShapeValue value = new MultiGeoValues.GeoShapeValue(reader);
129+
int upperBound = (int) GEOTILE.getBoundingTileCount(value, precision);
130+
long[] recursiveValues = new long[upperBound];
131+
long[] bruteForceValues = new long[upperBound];
132+
int recursiveCount = GEOTILE.setValues(recursiveValues, value, precision);
133+
int bruteForceCount = GEOTILE.setValuesByBruteForceScan(bruteForceValues, value, precision);
134+
Arrays.sort(recursiveValues);
135+
Arrays.sort(bruteForceValues);
136+
assertThat(recursiveCount, equalTo(bruteForceCount));
137+
assertArrayEquals(recursiveValues, bruteForceValues);
138+
}
139+
123140
public void testGeoHash() throws Exception {
124141
double x = randomDouble();
125142
double y = randomDouble();

0 commit comments

Comments
 (0)