You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/04/22 17:40:36 UTC
svn commit: r1675386 - in
/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j:
Geo3dShapeRectRelationTest.java Geo3dShapeTest.java
Author: dsmiley
Date: Wed Apr 22 15:40:36 2015
New Revision: 1675386
URL: http://svn.apache.org/r1675386
Log:
LUCENE-6196: Geo3dShapeTest -> Geo3dShapeRectRelationTest and complete testing of the 4 shape types
Added:
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
- copied, changed from r1675362, lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeTest.java
Removed:
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeTest.java
Copied: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java (from r1675362, lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java?p2=lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java&p1=lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeTest.java&r1=1675362&r2=1675386&rev=1675386&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java Wed Apr 22 15:40:36 2015
@@ -17,22 +17,26 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
+import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
import com.carrotsearch.randomizedtesting.RandomizedContext;
-import com.carrotsearch.randomizedtesting.annotations.Seed;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Point;
+import org.apache.lucene.spatial.spatial4j.geo3d.GeoBBoxFactory;
import org.apache.lucene.spatial.spatial4j.geo3d.GeoCircle;
+import org.apache.lucene.spatial.spatial4j.geo3d.GeoPath;
import org.apache.lucene.spatial.spatial4j.geo3d.GeoPoint;
+import org.apache.lucene.spatial.spatial4j.geo3d.GeoPolygonFactory;
import org.apache.lucene.spatial.spatial4j.geo3d.GeoShape;
import org.junit.Rule;
import org.junit.Test;
import static com.spatial4j.core.distance.DistanceUtils.DEGREES_TO_RADIANS;
-public class Geo3dShapeTest extends RandomizedShapeTest {
+public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {
@Rule
public final TestLog testLog = TestLog.instance;
@@ -45,15 +49,14 @@ public class Geo3dShapeTest extends Rand
}
@Test
- @Seed("FAD1BAB12B6DCCFE")
+ //@Seed("FAD1BAB12B6DCCFE")
public void testGeoCircleRect() {
new RectIntersectionTestHelper<Geo3dShape>(ctx) {
@Override
protected Geo3dShape generateRandomShape(Point nearP) {
- // Circles
while (true) {
- final int circleRadius = random().nextInt(180);
+ final int circleRadius = random().nextInt(179) + 1;//no 0-radius
final Point point = nearP;
try {
final GeoShape shape = new GeoCircle(point.getY() * DEGREES_TO_RADIANS, point.getX() * DEGREES_TO_RADIANS,
@@ -76,8 +79,106 @@ public class Geo3dShapeTest extends Rand
}.testRelateWithRectangle();
}
- //TODO PORT OTHER TESTS
+ @Test
+ public void testGeoBBoxRect() {
+ new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+
+ @Override
+ protected boolean isRandomShapeRectangular() {
+ return true;
+ }
+
+ @Override
+ protected Geo3dShape generateRandomShape(Point nearP) {
+ // (ignoring nearP)
+ Point ulhcPoint = randomPoint();
+ Point lrhcPoint = randomPoint();
+ if (ulhcPoint.getY() < lrhcPoint.getY()) {
+ //swap
+ Point temp = ulhcPoint;
+ ulhcPoint = lrhcPoint;
+ lrhcPoint = temp;
+ }
+ final GeoShape shape = GeoBBoxFactory.makeGeoBBox(ulhcPoint.getY() * DEGREES_TO_RADIANS,
+ lrhcPoint.getY() * DEGREES_TO_RADIANS,
+ ulhcPoint.getX() * DEGREES_TO_RADIANS,
+ lrhcPoint.getX() * DEGREES_TO_RADIANS);
+ return new Geo3dShape(shape, ctx);
+ }
+
+ @Override
+ protected Point randomPointInEmptyShape(Geo3dShape shape) {
+ return shape.getBoundingBox().getCenter();
+ }
+ }.testRelateWithRectangle();
+ }
+ @Test
+ public void testGeoPolygonRect() {
+ new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+
+ @Override
+ protected Geo3dShape generateRandomShape(Point nearP) {
+ final int vertexCount = random().nextInt(3) + 3;
+ while (true) {
+ final List<GeoPoint> geoPoints = new ArrayList<>();
+ while (geoPoints.size() < vertexCount) {
+ final Point point = randomPoint();
+ final GeoPoint gPt = new GeoPoint(point.getY() * DEGREES_TO_RADIANS, point.getX() * DEGREES_TO_RADIANS);
+ geoPoints.add(gPt);
+ }
+ final int convexPointIndex = random().nextInt(vertexCount); //If we get this wrong, hopefully we get IllegalArgumentException
+ try {
+ final GeoShape shape = GeoPolygonFactory.makeGeoPolygon(geoPoints, convexPointIndex);
+ return new Geo3dShape(shape, ctx);
+ } catch (IllegalArgumentException e) {
+ // This is what happens when we create a shape that is invalid. Although it is conceivable that there are cases where
+ // the exception is thrown incorrectly, we aren't going to be able to do that in this random test.
+ continue;
+ }
+ }
+ }
+
+ @Override
+ protected Point randomPointInEmptyShape(Geo3dShape shape) {
+ throw new IllegalStateException("unexpected; need to finish test code");
+ }
+
+ }.testRelateWithRectangle();
+ }
+
+ @Test
+ public void testGeoPathRect() {
+ new RectIntersectionTestHelper<Geo3dShape>(ctx) {
+
+ @Override
+ protected Geo3dShape generateRandomShape(Point nearP) {
+ final int pointCount = random().nextInt(5) + 1;
+ final double width = (random().nextInt(89)+1) * DEGREES_TO_RADIANS;
+ while (true) {
+ try {
+ final GeoPath path = new GeoPath(width);
+ for (int i = 0; i < pointCount; i++) {
+ final Point nextPoint = randomPoint();
+ path.addPoint(nextPoint.getY() * DEGREES_TO_RADIANS, nextPoint.getX() * DEGREES_TO_RADIANS);
+ }
+ path.done();
+ return new Geo3dShape(path, ctx);
+ } catch (IllegalArgumentException e) {
+ // This is what happens when we create a shape that is invalid. Although it is conceivable that there are cases where
+ // the exception is thrown incorrectly, we aren't going to be able to do that in this random test.
+ continue;
+ }
+ }
+ }
+
+ @Override
+ protected Point randomPointInEmptyShape(Geo3dShape shape) {
+ throw new IllegalStateException("unexpected; need to finish test code");
+ }
+
+ }.testRelateWithRectangle();
+ }
private Point geoPointToSpatial4jPoint(GeoPoint geoPoint) {
return ctx.makePoint(geoPoint.x * DistanceUtils.RADIANS_TO_DEGREES,