LUCENE-6196: Fix RandomizedShapeTestCase.randomPointIn(Shape)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1678059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2015-05-06 18:49:32 +00:00
parent 42d19cb26b
commit f06df3cc1d
2 changed files with 14 additions and 9 deletions

View File

@ -272,15 +272,17 @@ public abstract class RandomizedShapeTestCase extends RandomizedTest {
return p;
}
protected Point randomPointIn(Shape shape) {
protected Point randomPointInOrNull(Shape shape) {
if (!shape.hasArea())// or try the center?
throw new UnsupportedOperationException("Need area to define shape!");
Rectangle bbox = shape.getBoundingBox();
Point p;
do {
p = randomPointIn(bbox);
} while (!bbox.relate(p).intersects());
return p;
for (int i = 0; i < 1000; i++) {
Point p = randomPointIn(bbox);
if (shape.relate(p).intersects()) {
return p;
}
}
return null;//tried too many times and failed
}
}

View File

@ -72,13 +72,13 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
@SuppressWarnings("unchecked")
@Override
protected Point randomPointIn(Shape shape) {
protected Point randomPointInOrNull(Shape shape) {
if (!shape.hasArea()) {
final Point pt = randomPointInEmptyShape((S) shape);
assert shape.relate(pt).intersects() : "faulty randomPointInEmptyShape";
return pt;
}
return super.randomPointIn(shape);
return super.randomPointInOrNull(shape);
}
public void testRelateWithRectangle() {
@ -132,7 +132,10 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
case WITHIN:
i_W++;
for (int j = 0; j < MAX_TRIES; j++) {
Point p = randomPointIn(s);
Point p = randomPointInOrNull(s);
if (p == null) {//couldn't find a random point in shape
break;
}
assertRelation(null, CONTAINS, r, p);
}
break;