net.jqwik.engine.properties.shrinking.NextShrinkingSequence Maven / Gradle / Ivy
package net.jqwik.engine.properties.shrinking;
import java.util.function.*;
import net.jqwik.api.*;
public class NextShrinkingSequence implements ShrinkingSequence {
private final ShrinkingSequence before;
private final Function, ShrinkingSequence> nextShrinkingStep;
private ShrinkingSequence nextSequence = null;
private FalsificationResult current = null;
public NextShrinkingSequence(ShrinkingSequence before, Function, ShrinkingSequence> nextShrinkingStep) {
this.before = before;
this.nextShrinkingStep = nextShrinkingStep;
this.current = before.current();
}
@Override
public void init(FalsificationResult initialCurrent) {
if (current == null) {
current = initialCurrent;
} else {
current = FalsificationResult.falsified(current.shrinkable(), initialCurrent.throwable().orElse(null));
}
this.before.init(initialCurrent);
}
@Override
public boolean next(Runnable count, Consumer> falsifiedReporter) {
if (nextSequence == null) {
if (before.next(count, falsifiedReporter)) {
current = before.current();
return true;
} else {
nextSequence = nextShrinkingStep.apply(current.shrinkable());
nextSequence.init(current);
}
}
boolean next = nextSequence.next(count, falsifiedReporter);
if (next) {
current = nextSequence.current();
}
return next;
}
@Override
public FalsificationResult current() {
return current;
}
@Override
public String toString() {
return String.format("Next [%s, %s]", before, nextSequence);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy