net.jqwik.engine.properties.arbitraries.randomized.ContainerGenerator Maven / Gradle / Ivy
package net.jqwik.engine.properties.arbitraries.randomized;
import java.util.*;
import java.util.function.*;
import net.jqwik.api.*;
class ContainerGenerator implements RandomGenerator {
private final RandomGenerator elementGenerator;
private final Function>, Shrinkable> createShrinkable;
private final Function sizeGenerator;
ContainerGenerator(
RandomGenerator elementGenerator,
Function>, Shrinkable> createShrinkable,
Function sizeGenerator
) {
this.elementGenerator = elementGenerator;
this.createShrinkable = createShrinkable;
this.sizeGenerator = sizeGenerator;
}
@Override
public Shrinkable next(Random random) {
int listSize = sizeGenerator.apply(random);
List> list = new ArrayList<>();
while (list.size() < listSize) {
list.add(elementGenerator.next(random));
}
return createShrinkable.apply(list);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy