net.jqwik.engine.properties.EdgeCasesGenerator Maven / Gradle / Ivy
package net.jqwik.engine.properties;
import java.util.*;
import java.util.stream.*;
import net.jqwik.api.*;
import net.jqwik.engine.support.*;
import static java.lang.Math.*;
public class EdgeCasesGenerator implements Iterator>> {
// Caveat: Always make sure that the number is greater than 1.
// Otherwise only edge cases will be generated
// Currently the value is always between 5 and 20
public static int calculateBaseToEdgeCaseRatio(int genSize, int countEdgeCases) {
return min(
max(genSize / countEdgeCases, 5),
20
);
}
private final List> edgeCases;
private final Iterator>> iterator;
EdgeCasesGenerator(List> edgeCases) {
this.edgeCases = edgeCases;
this.iterator = createIterator();
}
private Iterator>> createIterator() {
if (this.edgeCases.isEmpty()) {
return Collections.emptyIterator();
}
List>> iterables =
edgeCases
.stream()
.map(edge -> (Iterable>) edge)
.collect(Collectors.toList());
return Combinatorics.combine(iterables);
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public List> next() {
return iterator.next();
}
}