Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,15 @@ public void testSingleValueFieldGetProperty() {
assertThat(global.getAggregations().asMap().size(), equalTo(1));

CentroidAggregation geoCentroid = global.getAggregations().get(aggName());
InternalAggregation agg = (InternalAggregation) global;
assertThat(geoCentroid, notNullValue());
assertThat(geoCentroid.getName(), equalTo(aggName()));
assertThat((CentroidAggregation) ((InternalAggregation) global).getProperty(aggName()), sameInstance(geoCentroid));
assertThat((CentroidAggregation) agg.getProperty(aggName()), sameInstance(geoCentroid));
assertSameCentroid(geoCentroid.centroid(), singleCentroid);
assertThat(
((SpatialPoint) ((InternalAggregation) global).getProperty(aggName() + ".value")).getY(),
closeTo(singleCentroid.getY(), GEOHASH_TOLERANCE)
);
assertThat(
((SpatialPoint) ((InternalAggregation) global).getProperty(aggName() + ".value")).getX(),
closeTo(singleCentroid.getX(), GEOHASH_TOLERANCE)
);
assertThat(
(double) ((InternalAggregation) global).getProperty(aggName() + "." + coordinateName("y")),
closeTo(singleCentroid.getY(), GEOHASH_TOLERANCE)
);
assertThat(
(double) ((InternalAggregation) global).getProperty(aggName() + "." + coordinateName("x")),
closeTo(singleCentroid.getX(), GEOHASH_TOLERANCE)
);
assertSimilarValue(((SpatialPoint) agg.getProperty(aggName() + ".value")).getY(), singleCentroid.getY());
assertSimilarValue(((SpatialPoint) agg.getProperty(aggName() + ".value")).getX(), singleCentroid.getX());
assertSimilarValue((double) agg.getProperty(aggName() + "." + coordinateName("y")), singleCentroid.getY());
assertSimilarValue((double) agg.getProperty(aggName() + "." + coordinateName("x")), singleCentroid.getX());
assertEquals(numDocs, (long) ((InternalAggregation) global).getProperty(aggName() + ".count"));
}

Expand Down Expand Up @@ -155,6 +144,12 @@ protected double normalize(double value) {
return value;
}

protected void assertSimilarValue(double a, double b) {
a = normalize(a);
b = normalize(b);
assertThat(a, closeTo(b, tolerance(a, b)));
}

protected void assertSameCentroid(SpatialPoint centroid, SpatialPoint expectedCentroid) {
String[] names = centroid.getClass() == GeoPoint.class ? new String[] { "longitude", "latitude" } : new String[] { "x", "y" };
double x = normalize(centroid.getX());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected CartesianPoint reset(SpatialPoint point, double x, double y) {

@Override
protected double tolerance(double a, double b) {
return Math.max(Math.abs(a), Math.abs(b)) / 1e5;
return Math.max(GEOHASH_TOLERANCE, Math.max(Math.abs(a), Math.abs(b)) / 1e5);
}

@Override
Expand Down