Skip to content

Commit

Permalink
Ensure defaults for float/double generation result in random values (#…
Browse files Browse the repository at this point in the history
…4735)

Also ensures generating BigIntegers with a default range can contain
some nulls.

See #4743 for later follow-up.
  • Loading branch information
niloc132 authored Nov 1, 2023
1 parent d685aa3 commit c708dc6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,8 @@ public void testTDigestIncremental() {
final QueryTable queryTable = getTable(size, random,
columnInfos = initColumnInfos(new String[] {"Sym", "doubleCol", "longCol"},
new SetGenerator<>("a", "b", "c", "d"),
new DoubleGenerator(-10000, 10000, 0.05, 0.05),
// TODO (deephaven-core#4743) verify this change in range
new DoubleGenerator(0, 10000, 0.05, 0.05),
new LongGenerator(0, 1_000_000_000L)));

final Collection<? extends Aggregation> aggregations = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ static CreateResult createTestTable(int tableSize,
new ShortGenerator((short) -6000, (short) 65535, .1),
new IntGenerator(10, 100, .1),
new LongGenerator(10, 100, .1),
new FloatGenerator(-100, 100, .1),
// TODO (deephaven-core#4743) verify this change in range
new FloatGenerator(0, 100, .1),
new DoubleGenerator(10.1, 20.1, .1),
new BooleanGenerator(.5, .1),
new BigIntegerGenerator(new BigInteger("-10"), new BigInteger("10"), .1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BigIntegerGenerator() {

public BigIntegerGenerator(double nullFraction) {
this(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2)),
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), 0);
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), nullFraction);
}

public BigIntegerGenerator(BigInteger from, BigInteger to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DoubleGenerator extends AbstractGenerator<Double> {
private final double posInfFraction;

public DoubleGenerator() {
this(QueryConstants.NULL_DOUBLE + 1, Double.MAX_VALUE);
this(Math.nextUp(-Double.MAX_VALUE), Double.MAX_VALUE);
}

public DoubleGenerator(double from, double to) {
Expand Down Expand Up @@ -74,7 +74,7 @@ private double generateDouble(Random random) {
return Double.POSITIVE_INFINITY;
}
}
return from + (random.nextDouble() * to - from);
return (from / 2 + (random.nextDouble() * (to / 2 - from / 2))) * 2;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FloatGenerator extends AbstractGenerator<Float> {
private final double posInfFraction;

public FloatGenerator() {
this(QueryConstants.NULL_FLOAT + 1, Float.MAX_VALUE);
this(Math.nextUp(-Float.MAX_VALUE), Float.MAX_VALUE);
}

public FloatGenerator(float from, float to) {
Expand Down Expand Up @@ -69,7 +69,7 @@ private float generateFloat(Random random) {
return Float.POSITIVE_INFINITY;
}
}
return from + (random.nextFloat() * to - from);
return (from / 2 + (random.nextFloat() * (to / 2 - from / 2))) * 2;
}

@Override
Expand Down

0 comments on commit c708dc6

Please sign in to comment.