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

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

import net.jqwik.api.*;
import net.jqwik.api.arbitraries.*;
import net.jqwik.engine.properties.arbitraries.randomized.*;

abstract class MultivalueArbitraryBase extends AbstractArbitraryBase {

	protected Arbitrary elementArbitrary;
	protected int minSize = 0;
	protected int maxSize = RandomGenerators.DEFAULT_COLLECTION_SIZE;

	protected MultivalueArbitraryBase(Arbitrary elementArbitrary) {
		this.elementArbitrary = elementArbitrary;
	}

	protected RandomGenerator> createListGenerator(int genSize) {
		RandomGenerator elementGenerator = elementGenerator(elementArbitrary, genSize);
		List>> samples = edgeCases(new ArrayList<>());
		return RandomGenerators
				   .list(elementGenerator, minSize, maxSize, cutoffSize(genSize)) //
				   .withEdgeCases(genSize, samples);
	}

	protected int cutoffSize(int genSize) {
		return RandomGenerators.defaultCutoffSize(minSize, maxSize, genSize);
	}

	protected  List> edgeCases(C sample) {
		return Stream.of(sample)
					 .filter(l -> l.size() >= minSize)
					 .filter(l -> maxSize == 0 || l.size() <= maxSize)
					 .map(Shrinkable::unshrinkable)
					 .collect(Collectors.toList());
	}

	protected RandomGenerator elementGenerator(Arbitrary elementArbitrary, int genSize) {
		return elementArbitrary.generator(genSize);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy