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

net.jqwik.engine.properties.shrinking.NextShrinkingSequence Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
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