LUCENE-6196: RectIntersectionTestHelper: fix to work with testing rectangles, and more clearly test when the shape.getBoundingBox may be faulty

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene6196@1675385 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2015-04-22 15:37:41 +00:00
parent 1242bf1519
commit c2deaeb066
1 changed files with 17 additions and 3 deletions

View File

@ -34,15 +34,24 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
super(ctx); super(ctx);
} }
/** Override to return true if generateRandomShape is essentially a Rectangle. */
protected boolean isRandomShapeRectangular() {
return false;
}
protected abstract S generateRandomShape(Point nearP); protected abstract S generateRandomShape(Point nearP);
/** shape has no area; return a point in it */
protected abstract Point randomPointInEmptyShape(S shape); protected abstract Point randomPointInEmptyShape(S shape);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected Point randomPointIn(Shape shape) { protected Point randomPointIn(Shape shape) {
if (!shape.hasArea()) if (!shape.hasArea()) {
return randomPointInEmptyShape((S) shape); final Point pt = randomPointInEmptyShape((S) shape);
assert shape.relate(pt).intersects() : "faulty randomPointInEmptyShape";
return pt;
}
return super.randomPointIn(shape); return super.randomPointIn(shape);
} }
@ -52,7 +61,7 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
int laps = 0; int laps = 0;
final int MINLAPSPERCASE = scaledRandomIntBetween(20, 200); final int MINLAPSPERCASE = scaledRandomIntBetween(20, 200);
while(i_C < MINLAPSPERCASE || i_I < MINLAPSPERCASE || i_W < MINLAPSPERCASE while(i_C < MINLAPSPERCASE || i_I < MINLAPSPERCASE || i_W < MINLAPSPERCASE
|| i_D < MINLAPSPERCASE || i_bboxD < MINLAPSPERCASE) { || (!isRandomShapeRectangular() && i_D < MINLAPSPERCASE) || i_bboxD < MINLAPSPERCASE) {
laps++; laps++;
TestLog.clear(); TestLog.clear();
@ -67,6 +76,11 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
TestLog.log("S-R Rel: {}, Shape {}, Rectangle {}", ic, s, r); TestLog.log("S-R Rel: {}, Shape {}, Rectangle {}", ic, s, r);
if (ic != DISJOINT) {
assertTrue("if not disjoint then the shape's bbox shouldn't be disjoint",
s.getBoundingBox().relate(r).intersects());
}
try { try {
int MAX_TRIES = scaledRandomIntBetween(10, 100); int MAX_TRIES = scaledRandomIntBetween(10, 100);
switch (ic) { switch (ic) {