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

net.jqwik.engine.properties.arbitraries.DefaultStreamArbitrary 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 java.util.stream.*;

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.*;

public class DefaultStreamArbitrary extends MultivalueArbitraryBase> implements StreamArbitrary {

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

	@Override
	protected Iterable toIterable(Stream streamable) {
		return streamable::iterator;
	}

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

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

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

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

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

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

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

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

	@Override
	public StreamArbitrary uniqueElements() {
		return (StreamArbitrary) uniqueElements(FeatureExtractor.identity());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy