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

This commit is contained in:
Nicholas Knize 2016-09-15 11:29:57 -05:00
parent 70fd627ca7
commit ea31811e42
4 changed files with 76 additions and 60 deletions

View File

@ -43,11 +43,13 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase {
double[] min = new double[dimensions]; double[] min = new double[dimensions];
double[] max = new double[dimensions]; double[] max = new double[dimensions];
double minV, maxV;
for (int d=0; d<dimensions; ++d) { for (int d=0; d<dimensions; ++d) {
min[d] = nextDoubleInternal(); minV = nextDoubleInternal();
max[d] = nextDoubleInternal(); maxV = nextDoubleInternal();
min[d] = Math.min(minV, maxV);
max[d] = Math.max(minV, maxV);
} }
return new DoubleRange(min, max); 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 assert min != null && max != null && min.length > 0 && max.length > 0
: "test box: min/max cannot be null or empty"; : "test box: min/max cannot be null or empty";
assert min.length == max.length : "test box: min/max length do not agree"; assert min.length == max.length : "test box: min/max length do not agree";
this.min = new double[min.length]; this.min = min;
this.max = new double[max.length]; this.max = max;
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;
}
}
} }
@Override @Override
@ -164,7 +158,12 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMin(int dim, Object val) { 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 @Override
@ -174,7 +173,12 @@ public class TestDoubleRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMax(int dim, Object val) { 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 @Override

View File

@ -43,11 +43,13 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase {
float[] min = new float[dimensions]; float[] min = new float[dimensions];
float[] max = new float[dimensions]; float[] max = new float[dimensions];
float minV, maxV;
for (int d=0; d<dimensions; ++d) { for (int d=0; d<dimensions; ++d) {
min[d] = nextFloatInternal(); minV = nextFloatInternal();
max[d] = nextFloatInternal(); maxV = nextFloatInternal();
min[d] = Math.min(minV, maxV);
max[d] = Math.max(minV, maxV);
} }
return new FloatRange(min, max); 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 assert min != null && max != null && min.length > 0 && max.length > 0
: "test box: min/max cannot be null or empty"; : "test box: min/max cannot be null or empty";
assert min.length == max.length : "test box: min/max length do not agree"; assert min.length == max.length : "test box: min/max length do not agree";
this.min = new float[min.length]; this.min = min;
this.max = new float[max.length]; this.max = max;
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;
}
}
} }
@Override @Override
@ -164,7 +158,12 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMin(int dim, Object val) { 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 @Override
@ -174,7 +173,12 @@ public class TestFloatRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMax(int dim, Object val) { 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 @Override

View File

@ -43,11 +43,13 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase {
int[] min = new int[dimensions]; int[] min = new int[dimensions];
int[] max = new int[dimensions]; int[] max = new int[dimensions];
int minV, maxV;
for (int d=0; d<dimensions; ++d) { for (int d=0; d<dimensions; ++d) {
min[d] = nextIntInternal(); minV = nextIntInternal();
max[d] = nextIntInternal(); maxV = nextIntInternal();
min[d] = Math.min(minV, maxV);
max[d] = Math.max(minV, maxV);
} }
return new IntRange(min, max); 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 assert min != null && max != null && min.length > 0 && max.length > 0
: "test box: min/max cannot be null or empty"; : "test box: min/max cannot be null or empty";
assert min.length == max.length : "test box: min/max length do not agree"; assert min.length == max.length : "test box: min/max length do not agree";
this.min = new int[min.length]; this.min = min;
this.max = new int[max.length]; this.max = max;
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;
}
}
} }
@Override @Override
@ -164,7 +158,12 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMin(int dim, Object val) { 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 @Override
@ -174,7 +173,12 @@ public class TestIntRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMax(int dim, Object val) { 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 @Override

View File

@ -43,11 +43,13 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase {
long[] min = new long[dimensions]; long[] min = new long[dimensions];
long[] max = new long[dimensions]; long[] max = new long[dimensions];
long minV, maxV;
for (int d=0; d<dimensions; ++d) { for (int d=0; d<dimensions; ++d) {
min[d] = nextLongInternal(); minV = nextLongInternal();
max[d] = nextLongInternal(); maxV = nextLongInternal();
min[d] = Math.min(minV, maxV);
max[d] = Math.max(minV, maxV);
} }
return new LongRange(min, max); 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 assert min != null && max != null && min.length > 0 && max.length > 0
: "test box: min/max cannot be null or empty"; : "test box: min/max cannot be null or empty";
assert min.length == max.length : "test box: min/max length do not agree"; assert min.length == max.length : "test box: min/max length do not agree";
this.min = new long[min.length]; this.min = min;
this.max = new long[max.length]; this.max = max;
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;
}
}
} }
@Override @Override
@ -164,7 +158,12 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMin(int dim, Object val) { 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 @Override
@ -174,7 +173,12 @@ public class TestLongRangeFieldQueries extends BaseRangeFieldQueryTestCase {
@Override @Override
protected void setMax(int dim, Object val) { 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 @Override