net.jqwik.vavr.arbitraries.base.ListBasedArbitrary Maven / Gradle / Ivy
package net.jqwik.vavr.arbitraries.base;
import io.vavr.collection.Traversable;
import net.jqwik.api.Arbitrary;
import net.jqwik.api.arbitraries.StreamableArbitrary;
import net.jqwik.api.arbitraries.ArbitraryDecorator;
import net.jqwik.api.arbitraries.ListArbitrary;
import net.jqwik.api.RandomDistribution;
import java.util.function.BiFunction;
import java.util.function.Function;
public abstract class ListBasedArbitrary> extends ArbitraryDecorator
implements StreamableArbitrary {
private ListArbitrary listArbitrary;
public ListBasedArbitrary(final Arbitrary elementArbitrary) {
this.listArbitrary = elementArbitrary.list();
}
protected abstract U convertJavaListToVavrCollection(java.util.List javaList);
@Override
protected Arbitrary arbitrary() {
return listArbitrary.map(this::convertJavaListToVavrCollection);
}
@Override
public ListBasedArbitrary ofMinSize(final int minSize) {
final ListBasedArbitrary clone = typedClone();
clone.listArbitrary = listArbitrary.ofMinSize(minSize);
return clone;
}
@Override
public ListBasedArbitrary ofMaxSize(final int maxSize) {
final ListBasedArbitrary clone = typedClone();
clone.listArbitrary = listArbitrary.ofMaxSize(maxSize);
return clone;
}
@Override
public ListBasedArbitrary withSizeDistribution(final RandomDistribution distribution) {
final ListBasedArbitrary clone = typedClone();
clone.listArbitrary = listArbitrary.withSizeDistribution(distribution);
return clone;
}
@Override
public Arbitrary reduce(final R initial, final BiFunction accumulator) {
return listArbitrary.reduce(initial, accumulator);
}
public ListBasedArbitrary uniqueElements(final Function by) {
final ListBasedArbitrary clone = typedClone();
clone.listArbitrary = listArbitrary.uniqueElements(by);
return clone;
}
@Override
public ListBasedArbitrary uniqueElements() {
final ListBasedArbitrary clone = typedClone();
clone.listArbitrary = listArbitrary.uniqueElements();
return clone;
}
}