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

net.jqwik.engine.properties.arbitraries.randomized.WithSamplesGenerator 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.concurrent.atomic.*;

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

public class WithSamplesGenerator implements RandomGenerator {
	private final AtomicInteger tryCount = new AtomicInteger(0);
	private final RandomGenerator samplesGenerator;
	private final RandomGenerator base;
	private final int numberOfSamples;

	public WithSamplesGenerator(RandomGenerator base, T[] samples) {
		List> shrinkables = SampleShrinkable.listOf(samples);
		this.samplesGenerator = RandomGenerators.samplesFromShrinkables(shrinkables);
		this.numberOfSamples = shrinkables.size();
		this.base = base;
	}

	@Override
	public Shrinkable next(Random random) {
		if (tryCount.getAndIncrement() < numberOfSamples)
			return samplesGenerator.next(random);
		return base.next(random);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy