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

net.jqwik.engine.properties.shrinking.MappedShrinkingSequence 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 MappedShrinkingSequence implements ShrinkingSequence {
	private final ShrinkingSequence toMap;
	private final Function, FalsificationResult> mapper;

	public MappedShrinkingSequence(ShrinkingSequence toMap, Function, FalsificationResult> mapper) {this.toMap = toMap;
		this.mapper = mapper;
	}

	@Override
	public boolean next(Runnable count, Consumer> uReporter) {
		Consumer> tReporter = tResult -> uReporter.accept(mapper.apply(tResult));
		return toMap.next(count, tReporter);
	}

	@Override
	public void init(FalsificationResult initialCurrent) {
		FalsificationResult toMapCurrent = toMap.current();
		if (toMapCurrent != null) {
			toMap.init(FalsificationResult.falsified(toMapCurrent.shrinkable(), initialCurrent.throwable().orElse(null)));
		}
	}

	@Override
	public FalsificationResult current() {
		return mapper.apply(toMap.current());
	}
}