Skip to content
Permalink
Browse files
Add option to list a range of the RandomSource enum
  • Loading branch information
aherbert committed Mar 10, 2022
1 parent d4a8346 commit 18d88c0634d1d151f64863b951f7f18dd1b6929e
Showing 3 changed files with 39 additions and 1 deletion.
@@ -58,6 +58,16 @@ class ListCommand implements Callable<Void> {
paramLabel = "<provider>")
private ProviderType providerType = ProviderType.ALL;

/** The minimum entry in the provider enum. */
@Option(names = {"--min"},
description = {"The minimum entry in the provider enum (inclusive)."})
private int min = 0;

/** The maximum entry in the provider enum. */
@Option(names = {"--max"},
description = {"The maximum entry in the provider enum (inclusive)."})
private int max = Integer.MAX_VALUE;

/** The prefix for each ID in the template list of random generators. */
@Option(names = {"-p", "--prefix"},
description = {"The ID prefix.",
@@ -104,6 +114,9 @@ public Void call() throws Exception {
} else if (providerType == ProviderType.LONG) {
list = list.subsetLongSource();
}
if (min != 0 || max != Integer.MAX_VALUE) {
list = list.subsetRandomSource(min, max);
}
// Write in one call to the output
final StringBuilder sb = new StringBuilder();
switch (listFormat) {
@@ -168,7 +181,7 @@ static void writePlainData(Appendable appendable,
static void writeStressTestData(Appendable appendable,
Iterable<StressTestData> testData) throws IOException {
// Build the widths for each column
int idWidth = 0;
int idWidth = 1;
int randomSourceWidth = 15;
for (final StressTestData data : testData) {
idWidth = Math.max(idWidth, data.getId().length());
@@ -119,4 +119,23 @@ private StressTestDataList subsetOf(Class<?> type) {
}
return subset;
}

/**
* Create a subset of the list containing only instances of RandomSource within the
* specified range of the enum. The first value in the enum corresponds to entry 1.
*
* @param min Minimum entry (inclusive)
* @param max Maximum entry (inclusive)
* @return the stress test data list
*/
public StressTestDataList subsetRandomSource(int min, int max) {
final StressTestDataList subset = new StressTestDataList();
for (final StressTestData data : list) {
final int entry = data.getRandomSource().ordinal() + 1;
if (min <= entry && entry <= max) {
subset.list.add(data);
}
}
return subset;
}
}
@@ -153,6 +153,12 @@ This will produce a list of generators:
2 WELL_512_A 1
...

A subset range of the `RandomSource` enum can be specified using a minimum and/or maximum
entry in the enum order, starting from 1. This can be used to create a list of recently
added generators, for example:

java -jar target/examples-stress.jar list --min 34

Arguments can be specified for those generators that require them. Note that the identifier for
each line, corresponding to a tested generator, must be unique. The identifier will be used to name
the output results file for the generator.

0 comments on commit 18d88c0

Please sign in to comment.