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 extends Tuple.Tuple2> 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();
}
}