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

net.jqwik.engine.properties.EdgeCasesGenerator Maven / Gradle / Ivy

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

import java.util.*;
import java.util.stream.*;

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

import static java.lang.Math.*;

public class EdgeCasesGenerator implements Iterator>> {

	// Caveat: Always make sure that the number is greater than 1.
	// Otherwise only edge cases will be generated
	// Currently the value is always between 5 and 20
	public static int calculateBaseToEdgeCaseRatio(int genSize, int countEdgeCases) {
		return min(
			max(genSize / countEdgeCases, 5),
			20
		);
	}

	private final List> edgeCases;
	private final Iterator>> iterator;

	EdgeCasesGenerator(List> edgeCases) {
		this.edgeCases = edgeCases;
		this.iterator = createIterator();
	}

	private Iterator>> createIterator() {
		if (this.edgeCases.isEmpty()) {
			return Collections.emptyIterator();
		}
		List>> iterables =
			edgeCases
				.stream()
				.map(edge -> (Iterable>) edge)
				.collect(Collectors.toList());
		return Combinatorics.combine(iterables);
	}

	@Override
	public boolean hasNext() {
		return iterator.hasNext();
	}

	@Override
	public List> next() {
		return iterator.next();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy