net.jqwik.testing.ShrinkingSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jqwik-testing Show documentation
Show all versions of jqwik-testing Show documentation
Jqwik Testing support module
package net.jqwik.testing;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
import org.apiguardian.api.*;
import net.jqwik.api.*;
import net.jqwik.api.facades.*;
import net.jqwik.api.lifecycle.*;
import static org.apiguardian.api.API.Status.*;
import static org.assertj.core.api.Assertions.*;
@API(status = EXPERIMENTAL, since = "1.4.0")
public class ShrinkingSupport {
private ShrinkingSupport() {
}
public static T falsifyThenShrink(Arbitrary extends T> arbitrary, Random random) {
return falsifyThenShrink(arbitrary, random, ignore -> TryExecutionResult.falsified(null));
}
public static T falsifyThenShrink(Arbitrary extends T> arbitrary, Random random, Falsifier falsifier) {
return ShrinkingSupportFacade.implementation.falsifyThenShrink(arbitrary, random, falsifier);
}
public static T falsifyThenShrink(RandomGenerator extends T> generator, Random random, Falsifier falsifier) {
return ShrinkingSupportFacade.implementation.falsifyThenShrink(generator, random, falsifier);
}
public static T shrink(
Shrinkable falsifiedShrinkable,
Falsifier falsifier,
Throwable originalError
) {
return ShrinkingSupportFacade.implementation.shrink(falsifiedShrinkable, falsifier, originalError);
}
public static ShrunkFalsifiedSample shrinkToSample(
Shrinkable falsifiedShrinkable,
Falsifier falsifier,
Throwable originalError
) {
return ShrinkingSupportFacade.implementation.shrinkToSample(falsifiedShrinkable, falsifier, originalError);
}
public static void assertWhileShrinking(Shrinkable shrinkable, Predicate condition) {
while(true) {
List> collect = shrinkable.shrink().collect(Collectors.toList());
assertThat(collect).allMatch(s -> condition.test(s.value()));
if (collect.isEmpty()) {
break;
}
shrinkable = collect.iterator().next();
}
}
}