net.jqwik.vavr.arbitraries.base.SetBasedArbitrary Maven / Gradle / Ivy
package net.jqwik.vavr.arbitraries.base;
import io.vavr.collection.Set;
import net.jqwik.api.Arbitrary;
import net.jqwik.api.arbitraries.ArbitraryDecorator;
import net.jqwik.api.arbitraries.SetArbitrary;
import net.jqwik.api.arbitraries.StreamableArbitrary;
import net.jqwik.api.RandomDistribution;
import java.util.function.Function;
import java.util.function.BiFunction;
public abstract class SetBasedArbitrary> extends ArbitraryDecorator
implements StreamableArbitrary {
private SetArbitrary setArbitrary;
public SetBasedArbitrary(final Arbitrary elementArbitrary) {
this.setArbitrary = elementArbitrary.set();
}
protected abstract U convertJavaSetToVavrCollection(java.util.Set javaSet);
@Override
protected Arbitrary arbitrary() {
return setArbitrary.map(this::convertJavaSetToVavrCollection);
}
@Override
public SetBasedArbitrary ofMinSize(final int minSize) {
final SetBasedArbitrary clone = typedClone();
clone.setArbitrary = setArbitrary.ofMinSize(minSize);
return clone;
}
@Override
public SetBasedArbitrary ofMaxSize(final int maxSize) {
final SetBasedArbitrary clone = typedClone();
clone.setArbitrary = setArbitrary.ofMaxSize(maxSize);
return clone;
}
@Override
public SetBasedArbitrary withSizeDistribution(final RandomDistribution distribution) {
final SetBasedArbitrary clone = typedClone();
clone.setArbitrary = setArbitrary.withSizeDistribution(distribution);
return clone;
}
@Override
public Arbitrary reduce(final R initial, final BiFunction accumulator) {
return setArbitrary.reduce(initial, accumulator);
}
public SetBasedArbitrary uniqueElements(final Function by) {
final SetBasedArbitrary clone = typedClone();
clone.setArbitrary = setArbitrary.uniqueElements(by);
return clone;
}
@Override
public SetBasedArbitrary uniqueElements() {
// Set based arbitraries have unique elements by default
return this;
}
}