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

net.jqwik.engine.properties.arbitraries.exhaustive.PermutationExhaustiveGenerator Maven / Gradle / Ivy

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

import java.util.*;

import net.jqwik.api.*;
import net.jqwik.engine.support.*;

import org.jspecify.annotations.*;

import static net.jqwik.engine.support.MathSupport.*;

class PermutationExhaustiveGenerator implements ExhaustiveGenerator> {
	private final List values;
	private final Long maxCount;

	public PermutationExhaustiveGenerator(List values, Long maxCount) {
		this.values = values;
		this.maxCount = maxCount;
	}

	static Optional calculateMaxCount(List values, long maxNumberOfSamples) {
		try {
			long choices = factorial(values.size());
			if (choices > maxNumberOfSamples || choices < 0) {
				return Optional.empty();
			}
			return Optional.of(choices);
		} catch (ArithmeticException ae) {
			return Optional.empty();
		}
	}

	@Override
	public long maxCount() {
		return maxCount;
	}

	@Override
	public Iterator> iterator() {
		return Combinatorics.listPermutations(values);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy