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

net.jqwik.engine.properties.arbitraries.randomized.ContainerGenerator Maven / Gradle / Ivy

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

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

import net.jqwik.api.*;

class ContainerGenerator implements RandomGenerator {
	private final RandomGenerator elementGenerator;
	private final Function>, Shrinkable> createShrinkable;
	private final Function sizeGenerator;

	ContainerGenerator(
		RandomGenerator elementGenerator,
		Function>, Shrinkable> createShrinkable,
		Function sizeGenerator
	) {
		this.elementGenerator = elementGenerator;
		this.createShrinkable = createShrinkable;
		this.sizeGenerator = sizeGenerator;
	}

	@Override
	public Shrinkable next(Random random) {
		int listSize = sizeGenerator.apply(random);
		List> list = new ArrayList<>();
		while (list.size() < listSize) {
			list.add(elementGenerator.next(random));
		}
		return createShrinkable.apply(list);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy