lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkn...@apache.org
Subject lucene-solr:master: fix RangeField tests so they use actual ranges, not just 0 ranges
Date Thu, 15 Sep 2016 17:26:58 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 70fd627ca -> ea31811e4


fix RangeField tests so they use actual ranges, not just 0 ranges


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ea31811e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ea31811e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ea31811e

Branch: refs/heads/master
Commit: ea31811e42b2d16a7c0fcd180dc2089bfd6985b4
Parents: 70fd627
Author: Nicholas Knize <nknize@gmail.com>
Authored: Thu Sep 15 11:29:57 2016 -0500
Committer: Nicholas Knize <nknize@gmail.com>
Committed: Thu Sep 15 11:29:57 2016 -0500

----------------------------------------------------------------------
 .../search/TestDoubleRangeFieldQueries.java     | 34 +++++++++++---------
 .../search/TestFloatRangeFieldQueries.java      | 34 +++++++++++---------
 .../lucene/search/TestIntRangeFieldQueries.java | 34 +++++++++++---------
 .../search/TestLongRangeFieldQueries.java       | 34 +++++++++++---------
 4 files changed, 76 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ea31811e/lucene/sandbox/src/test/org/apache/lucene/search/TestDoubleRangeFieldQueries.java
----------------------------------------------------------------------
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 26b8b99..ad7e6b1 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<dimensions; ++d) {
-      min[d] = nextDoubleInternal();
-      max[d] = nextDoubleInternal();
+      minV = nextDoubleInternal();
+      maxV = nextDoubleInternal();
+      min[d] = Math.min(minV, maxV);
+      max[d] = Math.max(minV, maxV);
     }
-
     return new DoubleRange(min, max);
   }
 
@@ -140,16 +142,8 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase
{
       assert min != null && max != null && min.length > 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<min.length; ++d) {
-        if (min[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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ea31811e/lucene/sandbox/src/test/org/apache/lucene/search/TestFloatRangeFieldQueries.java
----------------------------------------------------------------------
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 c5a95d5..1980782 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<dimensions; ++d) {
-      min[d] = nextFloatInternal();
-      max[d] = nextFloatInternal();
+      minV = nextFloatInternal();
+      maxV = nextFloatInternal();
+      min[d] = Math.min(minV, maxV);
+      max[d] = Math.max(minV, maxV);
     }
-
     return new FloatRange(min, max);
   }
 
@@ -140,16 +142,8 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase
{
       assert min != null && max != null && min.length > 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<min.length; ++d) {
-        if (min[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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ea31811e/lucene/sandbox/src/test/org/apache/lucene/search/TestIntRangeFieldQueries.java
----------------------------------------------------------------------
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 6ec8def..64da229 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<dimensions; ++d) {
-      min[d] = nextIntInternal();
-      max[d] = nextIntInternal();
+      minV = nextIntInternal();
+      maxV = nextIntInternal();
+      min[d] = Math.min(minV, maxV);
+      max[d] = Math.max(minV, maxV);
     }
-
     return new IntRange(min, max);
   }
 
@@ -140,16 +142,8 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase
{
       assert min != null && max != null && min.length > 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<min.length; ++d) {
-        if (min[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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ea31811e/lucene/sandbox/src/test/org/apache/lucene/search/TestLongRangeFieldQueries.java
----------------------------------------------------------------------
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 558609b..0f947ff 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<dimensions; ++d) {
-      min[d] = nextLongInternal();
-      max[d] = nextLongInternal();
+      minV = nextLongInternal();
+      maxV = nextLongInternal();
+      min[d] = Math.min(minV, maxV);
+      max[d] = Math.max(minV, maxV);
     }
-
     return new LongRange(min, max);
   }
 
@@ -140,16 +142,8 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase
{
       assert min != null && max != null && min.length > 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<min.length; ++d) {
-        if (min[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


Mime
View raw message