Skip to content

Commit

Permalink
Inject extreme values into RandomValuesGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Oct 3, 2018
1 parent 0dc50f7 commit 8a6d568
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Expand Up @@ -46,6 +46,7 @@ class ValueCreatorUtil<KEY extends NativeIndexKey<KEY>, VALUE extends NativeInde
{
static final double FRACTION_DUPLICATE_UNIQUE = 0;
static final double FRACTION_DUPLICATE_NON_UNIQUE = 0.1;
private static final double FRACTION_EXTREME_VALUE = 0.25;
private static final Comparator<IndexEntryUpdate<IndexDescriptor>> UPDATE_COMPARATOR = ( u1, u2 ) ->
Values.COMPARATOR.compare( u1.values()[0], u2.values()[0] );
private static final int N_VALUES = 10;
Expand Down Expand Up @@ -222,12 +223,24 @@ protected Value fetchNextOrNull()

private Value newUniqueValue( RandomValues random, Set<Value> uniqueCompareValues, List<Value> uniqueValues )
{
int attempts = 0;
int maxAttempts = 10; // To avoid infinite loop on booleans
Value value;
do
{
value = random.nextValueOfTypes( types );
attempts++;
ValueType type = randomValues.among( types );
boolean useExtremeValue = attempts == 1 && randomValues.nextDouble() < FRACTION_EXTREME_VALUE;
if ( useExtremeValue )
{
value = randomValues.among( type.extremeValues() );
}
else
{
value = random.nextValueOfType( type );
}
}
while ( !uniqueCompareValues.add( value ) );
while ( attempts < maxAttempts && !uniqueCompareValues.add( value ) );
uniqueValues.add( value );
return value;
}
Expand Down
Expand Up @@ -573,12 +573,23 @@ public float nextFloat()
*/
public DoubleValue nextDoubleValue()
{
return doubleValue( generator.nextDouble() );
return doubleValue( nextDouble() );
}

/**
* Returns the next {@code double} between 0 (inclusive) and 1.0 (exclusive)
*
* @return {@code float}
* @see RandomValues
*/
public double nextDouble()
{
return generator.nextDouble();
}

private double doubleBetween( double min, double max )
{
return generator.nextDouble() * (max - min) + min;
return nextDouble() * (max - min) + min;
}

/**
Expand Down Expand Up @@ -996,7 +1007,7 @@ public double[] nextDoubleArrayRaw( int minLength, int maxLength )
double[] doubles = new double[length];
for ( int i = 0; i < length; i++ )
{
doubles[i] = generator.nextDouble();
doubles[i] = nextDouble();
}
return doubles;
}
Expand Down

0 comments on commit 8a6d568

Please sign in to comment.