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

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

The newest version!
package net.jqwik.engine.properties.shrinking;

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

import net.jqwik.api.*;

import org.jspecify.annotations.*;

public class ChooseValueShrinkable extends AbstractValueShrinkable {

	private final List values;

	public ChooseValueShrinkable(T value, List values) {
		super(value);
		this.values = values;
	}

	@Override
	public ShrinkingDistance distance() {
		return ShrinkingDistance.of(values.indexOf(value()));
	}

	@Override
	public Stream> shrink() {
		int index = values.indexOf(this.value());
		if (index == 0) {
			return Stream.empty();
		}
		return values.subList(0, index)
					 .stream()
					 .map(value -> new ChooseValueShrinkable<>(value, values));
	}

	@Override
	public Stream> grow() {
		int index = values.indexOf(this.value());
		if (index == values.size() - 1) {
			return Stream.empty();
		}
		return values.subList(index + 1, values.size())
					 .stream()
					 .map(value -> new ChooseValueShrinkable<>(value, values));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy