From ea31811e42b2d16a7c0fcd180dc2089bfd6985b4 Mon Sep 17 00:00:00 2001 From: Nicholas Knize Date: Thu, 15 Sep 2016 11:29:57 -0500 Subject: [PATCH] fix RangeField tests so they use actual ranges, not just 0 ranges --- .../search/TestDoubleRangeFieldQueries.java | 34 +++++++++++-------- .../search/TestFloatRangeFieldQueries.java | 34 +++++++++++-------- .../search/TestIntRangeFieldQueries.java | 34 +++++++++++-------- .../search/TestLongRangeFieldQueries.java | 34 +++++++++++-------- 4 files changed, 76 insertions(+), 60 deletions(-) diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestDoubleRangeFieldQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestDoubleRangeFieldQueries.java index 26b8b99a136..ad7e6b13b46 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestDoubleRangeFieldQueries.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestDoubleRangeFieldQueries.java @@ -43,11 +43,13 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase { double[] min = new double[dimensions]; double[] max = new double[dimensions]; + double minV, maxV; for (int d=0; d 0 && max.length > 0 : "test box: min/max cannot be null or empty"; assert min.length == max.length : "test box: min/max length do not agree"; - this.min = new double[min.length]; - this.max = new double[max.length]; - for (int d=0; d max[d]) { - // swap if max < min: - double temp = min[d]; - min[d] = max[d]; - max[d] = temp; - } - } + this.min = min; + this.max = max; } @Override @@ -164,7 +158,12 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMin(int dim, Object val) { - min[dim] = (Double)val; + double v = (Double)val; + if (min[dim] < v) { + max[dim] = v; + } else { + min[dim] = v; + } } @Override @@ -174,7 +173,12 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMax(int dim, Object val) { - max[dim] = (Double)val; + double v = (Double)val; + if (max[dim] > v) { + min[dim] = v; + } else { + max[dim] = v; + } } @Override diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestFloatRangeFieldQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestFloatRangeFieldQueries.java index c5a95d5fbe9..1980782304e 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestFloatRangeFieldQueries.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestFloatRangeFieldQueries.java @@ -43,11 +43,13 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase { float[] min = new float[dimensions]; float[] max = new float[dimensions]; + float minV, maxV; for (int d=0; d 0 && max.length > 0 : "test box: min/max cannot be null or empty"; assert min.length == max.length : "test box: min/max length do not agree"; - this.min = new float[min.length]; - this.max = new float[max.length]; - for (int d=0; d max[d]) { - // swap if max < min: - float temp = min[d]; - min[d] = max[d]; - max[d] = temp; - } - } + this.min = min; + this.max = max; } @Override @@ -164,7 +158,12 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMin(int dim, Object val) { - min[dim] = (Float)val; + float v = (Float)val; + if (min[dim] < v) { + max[dim] = v; + } else { + min[dim] = v; + } } @Override @@ -174,7 +173,12 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMax(int dim, Object val) { - max[dim] = (Float)val; + float v = (Float)val; + if (max[dim] > v) { + min[dim] = v; + } else { + max[dim] = v; + } } @Override diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestIntRangeFieldQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestIntRangeFieldQueries.java index 6ec8defd774..64da22913b7 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestIntRangeFieldQueries.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestIntRangeFieldQueries.java @@ -43,11 +43,13 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase { int[] min = new int[dimensions]; int[] max = new int[dimensions]; + int minV, maxV; for (int d=0; d 0 && max.length > 0 : "test box: min/max cannot be null or empty"; assert min.length == max.length : "test box: min/max length do not agree"; - this.min = new int[min.length]; - this.max = new int[max.length]; - for (int d=0; d max[d]) { - // swap if max < min: - int temp = min[d]; - min[d] = max[d]; - max[d] = temp; - } - } + this.min = min; + this.max = max; } @Override @@ -164,7 +158,12 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMin(int dim, Object val) { - min[dim] = (Integer)val; + int v = (Integer)val; + if (min[dim] < v) { + max[dim] = v; + } else { + min[dim] = v; + } } @Override @@ -174,7 +173,12 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMax(int dim, Object val) { - max[dim] = (Integer)val; + int v = (Integer)val; + if (max[dim] > v) { + min[dim] = v; + } else { + max[dim] = v; + } } @Override diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLongRangeFieldQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestLongRangeFieldQueries.java index 558609b95a7..0f947ff18f3 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLongRangeFieldQueries.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLongRangeFieldQueries.java @@ -43,11 +43,13 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase { long[] min = new long[dimensions]; long[] max = new long[dimensions]; + long minV, maxV; for (int d=0; d 0 && max.length > 0 : "test box: min/max cannot be null or empty"; assert min.length == max.length : "test box: min/max length do not agree"; - this.min = new long[min.length]; - this.max = new long[max.length]; - for (int d=0; d max[d]) { - // swap if max < min: - long temp = min[d]; - min[d] = max[d]; - max[d] = temp; - } - } + this.min = min; + this.max = max; } @Override @@ -164,7 +158,12 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMin(int dim, Object val) { - min[dim] = (Long)val; + long v = (Long)val; + if (min[dim] < v) { + max[dim] = v; + } else { + min[dim] = v; + } } @Override @@ -174,7 +173,12 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase { @Override protected void setMax(int dim, Object val) { - max[dim] = (Long)val; + long v = (Long)val; + if (max[dim] > v) { + min[dim] = v; + } else { + max[dim] = v; + } } @Override