@API(status=MAINTAINED,
since="1.2.3")
public class Statistics
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Statistics.StatisticsFacade |
| Modifier and Type | Method and Description |
|---|---|
static void |
collect(java.lang.Object... values)
Call this method to record an entry for statistical data about generated values.
|
static void |
coverage(java.util.function.Consumer<StatisticsCoverage> checker)
Perform coverage checking for successful property on statistics
for values collected with collect(Object...)
|
static StatisticsCollector |
label(java.lang.String label)
Call this method to get a labeled instance of StatisticsCollector.
|
public static void collect(java.lang.Object... values)
Usually you call collect(Object[]) method with all arbitraries
(parameters passed to test) and than you use coverage(Consumer)
method to ensure that certain count of some value has been tried.
NOTE: you can give descriptive name to some collections using label(String)
method. Usually you make multiple label+collect calls, i.e. for each passed arbitrary
parameter. This way you can provide parameters with descriptive names/labels.
Complete documentation is found at the jqwik documentation page for Checking Coverage of Collected Statistics.
Simple example:
@Property(generation = GenerationMode.RANDOMIZED)
void labeledStatistics(@ForAll @IntRange(min = 1, max = 10) Integer anInt) {
String range = anInt < 3 ? "small" : "large";
Statistics.label("range").collect(range);
Statistics.label("value").collect(anInt);
Statistics.label("range).coverage(
coverage -> coverage.check("small").percentage(p -> p > 20.0)
);
Statistics.label("value").coverage(
coverage -> coverage.check(0).count(c -> c > 0)
);
}
values - Can be anything. The list of these values is considered
a key for the reported table of frequencies. Constraints:
nulljava.lang.IllegalArgumentException - if one of the constraints on values is violatedlabel(String)public static StatisticsCollector label(java.lang.String label)
label - The label will be used for reporting the collected statistical valuesjavadoc of the collect(Object...) method for example usage@API(status=EXPERIMENTAL,
since="1.2.3")
public static void coverage(java.util.function.Consumer<StatisticsCoverage> checker)
Sample usage:
Statistics.coverage(coverage -> coverage.check("small").percentage(p -> p > 20.0));
Statistics.coverage(coverage -> coverage.check(0).count(c -> c > 0));
checker - Code that consumes a StatisticsCoverage objectjavadoc of the collect(Object...) method for example usage