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

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

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.shrinking;

import java.util.*;
import java.util.stream.*;

import net.jqwik.api.*;

public class SampleShrinkable extends AbstractValueShrinkable {

	private final List samples;
	private final int index;

	@SafeVarargs
	public static List> listOf(T ... samples) {
		List samplesList = Arrays.asList(samples);
		List> shrinkables = new ArrayList<>();
		for (int i = 0; i < samples.length; i++) {
			shrinkables.add(new SampleShrinkable<>(samplesList, i));
		}
		return shrinkables;
	}

	private SampleShrinkable(List samples, int index) {
		super(samples.get(index));
		this.samples = samples;
		this.index = index;
	}

	@Override
	public Stream> shrink() {
		int sampleIndex = this.index;
		if (sampleIndex == 0)
			return Stream.empty();
		return Stream.of(new SampleShrinkable<>(samples, sampleIndex - 1));
	}

	@Override
	public ShrinkingDistance distance() {
		return ShrinkingDistance.of(index);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy