Skip to content

Apache Lucene open-source search software

LUCENE-7327: fix rare test bug

Mike McCandlessa923d945b4f6
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
index b5ce2507d61..6d7321025f8 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
@@ -45,8 +45,8 @@ class Geo3DUtil {
private static final int BITS = 32;
private static final double MUL = (0x1L<<BITS)/(2*MAX_VALUE);
static final double DECODE = getNextSafeDouble(1/MUL);
- private static final int MIN_ENCODED_VALUE = encodeValue(-MAX_VALUE);
- private static final int MAX_ENCODED_VALUE = encodeValue(MAX_VALUE);
+ static final int MIN_ENCODED_VALUE = encodeValue(-MAX_VALUE);
+ static final int MAX_ENCODED_VALUE = encodeValue(MAX_VALUE);
public static int encodeValue(double x) {
if (x > MAX_VALUE) {
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
index 85ec54856e6..fed5ada275c 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
@@ -1207,13 +1207,19 @@ public class TestGeo3DPoint extends LuceneTestCase {
/**
* step through some integers, ensuring they decode to their expected double values.
- * double values start at -90 and increase by LATITUDE_DECODE for each integer.
+ * double values start at -planetMax and increase by Geo3DUtil.DECODE for each integer.
* check edge cases within the double range and random doubles within the range too.
*/
public void testQuantization() throws Exception {
Random random = random();
for (int i = 0; i < 10000; i++) {
int encoded = random.nextInt();
+ if (encoded < Geo3DUtil.MIN_ENCODED_VALUE) {
+ continue;
+ }
+ if (encoded > Geo3DUtil.MAX_ENCODED_VALUE) {
+ continue;
+ }
double min = encoded * Geo3DUtil.DECODE;
double decoded = Geo3DUtil.decodeValueFloor(encoded);
// should exactly equal expected value