All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.properties.arbitraries.DefaultIteratorArbitrary Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.arbitraries;

import java.util.*;
import java.util.function.*;

import net.jqwik.api.*;
import net.jqwik.api.arbitraries.*;
import net.jqwik.engine.properties.*;
import net.jqwik.engine.properties.arbitraries.exhaustive.*;
import net.jqwik.engine.properties.shrinking.*;

import org.jspecify.annotations.*;

public class DefaultIteratorArbitrary extends MultivalueArbitraryBase> implements IteratorArbitrary {

	public DefaultIteratorArbitrary(Arbitrary elementArbitrary) {
		super(elementArbitrary);
	}

	@Override
	protected Iterable toIterable(Iterator streamable) {
		return () -> streamable;
	}

	@Override
	public RandomGenerator> generator(int genSize) {
		return createListGenerator(genSize, false).map(List::iterator);
	}

	@Override
	public RandomGenerator> generatorWithEmbeddedEdgeCases(int genSize) {
		return createListGenerator(genSize, true).map(List::iterator);
	}

	@Override
	public Optional>> exhaustive(long maxNumberOfSamples) {
		return ExhaustiveGenerators.list(elementArbitrary, minSize, maxSize(), uniquenessExtractors, maxNumberOfSamples)
								   .map(generator -> generator.map(List::iterator));
	}

	@Override
	public EdgeCases> edgeCases(int maxEdgeCases) {
		return EdgeCasesSupport.map(
				edgeCases((elements, minimalSize) -> new ShrinkableList<>(elements, minimalSize, maxSize(), uniquenessExtractors, elementArbitrary), maxEdgeCases),
				List::iterator
		);
	}

	@Override
	public IteratorArbitrary ofMaxSize(int maxSize) {
		return (IteratorArbitrary) super.ofMaxSize(maxSize);
	}

	@Override
	public IteratorArbitrary ofMinSize(int minSize) {
		return (IteratorArbitrary) super.ofMinSize(minSize);
	}

	@Override
	public IteratorArbitrary withSizeDistribution(RandomDistribution distribution) {
		return (IteratorArbitrary) super.withSizeDistribution(distribution);
	}

	@Override
	public IteratorArbitrary uniqueElements(Function by) {
		FeatureExtractor featureExtractor = by::apply;
		return (IteratorArbitrary) super.uniqueElements(featureExtractor);
	}

	@Override
	public IteratorArbitrary uniqueElements() {
		return (IteratorArbitrary) super.uniqueElements();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy