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

net.jqwik.engine.properties.arbitraries.FrequencyArbitrary Maven / Gradle / Ivy

The newest version!
package net.jqwik.engine.properties.arbitraries;

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

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

import org.jspecify.annotations.*;

public class FrequencyArbitrary extends UseGeneratorsArbitrary {
	private final List> frequencies;

	public FrequencyArbitrary(List> frequencies) {
		super(
			RandomGenerators.frequency(frequencies),
			max -> ExhaustiveGenerators.choose(valuesOf(frequencies), max),
			maxEdgeCases -> EdgeCasesSupport.choose(valuesOf(frequencies), maxEdgeCases)
		);
		this.frequencies = frequencies;
	}

	private static  List valuesOf(List> frequencies) {
		return frequencies.stream().map(Tuple.Tuple2::get2).collect(Collectors.toList());
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		FrequencyArbitrary that = (FrequencyArbitrary) o;
		return frequencies.equals(that.frequencies);
	}

	@Override
	public int hashCode() {
		return frequencies.hashCode();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy