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

net.jqwik.engine.properties.shrinking.MappedValueShrinkingSequence 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 MappedValueShrinkingSequence implements ShrinkingSequence {

	private final ShrinkingSequence toMap;
	private final Function mapper;

	public MappedValueShrinkingSequence(ShrinkingSequence toMap, Function mapper) {
		this.toMap = toMap;
		this.mapper = mapper;
	}

	@Override
	public boolean next(Runnable count, Consumer> falsifiedReporter) {
		return toMap.next(count, tResult -> falsifiedReporter.accept(tResult.map(shrinkable -> shrinkable.map(mapper))));
	}

	@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 toMap.current().map(shrinkable -> shrinkable.map(mapper));
	}
}