Trait proptest::strategy::ValueTree

source ·
pub trait ValueTree {
    type Value: Debug;

    // Required methods
    fn current(&self) -> Self::Value;
    fn simplify(&mut self) -> bool;
    fn complicate(&mut self) -> bool;
}
Expand description

A generated value and its associated shrinker.

Conceptually, a ValueTree represents a spectrum between a “minimally complex” value and a starting, randomly-chosen value. For values such as numbers, this can be thought of as a simple binary search, and this is how the ValueTree state machine is defined.

The ValueTree state machine notionally has three fields: low, current, and high. Initially, low is the “minimally complex” value for the type, and high and current are both the initially chosen value. It can be queried for its current state. When shrinking, the controlling code tries simplifying the value one step. If the test failure still happens with the simplified value, further simplification occurs. Otherwise, the code steps back up towards the prior complexity.

The main invariants here are that the “high” value always corresponds to a failing test case, and that repeated calls to complicate() will return false only once the “current” value has returned to what it was before the last call to simplify().

While it would be possible for default do-nothing implementations of simplify() and complicate() to be provided, this was not done deliberately since the majority of strategies will want to define their own shrinking anyway, and the minority that do not must call it out explicitly by their own implementation.

Required Associated Types§

source

type Value: Debug

The type of the value produced by this ValueTree.

Required Methods§

source

fn current(&self) -> Self::Value

Returns the current value.

source

fn simplify(&mut self) -> bool

Attempts to simplify the current value. Notionally, this sets the “high” value to the current value, and the current value to a “halfway point” between high and low, rounding towards low.

Returns whether any state changed as a result of this call. This does not necessarily imply that the value of current() has changed, since in the most general case, it is not possible for an implementation to determine this.

This call needs to correctly handle being called even immediately after it had been called previously and returned false.

source

fn complicate(&mut self) -> bool

Attempts to partially undo the last simplification. Notionally, this sets the “low” value to one plus the current value, and the current value to a “halfway point” between high and the new low, rounding towards low.

Returns whether any state changed as a result of this call. This does not necessarily imply that the value of current() has changed, since in the most general case, it is not possible for an implementation to determine this.

It is usually expected that, immediately after a call to simplify() which returns true, this call will itself return true. However, this is not always the case; in some strategies, particularly those that use some form of rejection sampling, the act of trying to simplify may change the state such that simplify() returns true, yet ultimately left the resulting value unchanged, in which case there is nothing left to complicate.

This call does not need to gracefully handle being called before simplify() was ever called, but does need to correctly handle being called even immediately after it had been called previously and returned false.

Implementations on Foreign Types§

source§

impl<T: Debug> ValueTree for fn() -> T

§

type Value = T

source§

fn simplify(&mut self) -> bool

source§

fn complicate(&mut self) -> bool

source§

fn current(&self) -> Self::Value

source§

impl<T: ValueTree + ?Sized> ValueTree for Box<T>

§

type Value = <T as ValueTree>::Value

source§

fn current(&self) -> Self::Value

source§

fn simplify(&mut self) -> bool

source§

fn complicate(&mut self) -> bool

Implementors§

source§

impl ValueTree for BoolValueTree

§

type Value = bool

source§

impl ValueTree for CharValueTree

§

type Value = char

source§

impl ValueTree for proptest::num::f32::BinarySearch

§

type Value = f32

source§

impl ValueTree for proptest::num::f64::BinarySearch

§

type Value = f64

source§

impl ValueTree for proptest::num::i8::BinarySearch

§

type Value = i8

source§

impl ValueTree for proptest::num::i16::BinarySearch

§

type Value = i16

source§

impl ValueTree for proptest::num::i32::BinarySearch

§

type Value = i32

source§

impl ValueTree for proptest::num::i64::BinarySearch

§

type Value = i64

source§

impl ValueTree for proptest::num::i128::BinarySearch

§

type Value = i128

source§

impl ValueTree for proptest::num::isize::BinarySearch

§

type Value = isize

source§

impl ValueTree for proptest::num::u8::BinarySearch

§

type Value = u8

source§

impl ValueTree for proptest::num::u16::BinarySearch

§

type Value = u16

source§

impl ValueTree for proptest::num::u32::BinarySearch

§

type Value = u32

source§

impl ValueTree for proptest::num::u64::BinarySearch

§

type Value = u64

source§

impl ValueTree for proptest::num::u128::BinarySearch

§

type Value = u128

source§

impl ValueTree for proptest::num::usize::BinarySearch

§

type Value = usize

source§

impl ValueTree for IndexValueTree

§

type Value = Index

source§

impl ValueTree for SelectorValueTree

source§

impl<A: Strategy, B: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>, I: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>, Option<LazyValueTree<I>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>, I: Strategy<Value = A::Value>, J: Strategy<Value = A::Value>> ValueTree for TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>, Option<LazyValueTree<I>>, Option<LazyValueTree<J>>)>

§

type Value = <A as Strategy>::Value

source§

impl<A: ValueTree> ValueTree for TupleValueTree<(A,)>

§

type Value = (<A as ValueTree>::Value,)

source§

impl<A: ValueTree, B: ValueTree> ValueTree for TupleValueTree<(A, B)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree> ValueTree for TupleValueTree<(A, B, C)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree> ValueTree for TupleValueTree<(A, B, C, D)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree, H: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G, H)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value, <H as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree, H: ValueTree, I: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G, H, I)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value, <H as ValueTree>::Value, <I as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree, H: ValueTree, I: ValueTree, J: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G, H, I, J)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value, <H as ValueTree>::Value, <I as ValueTree>::Value, <J as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree, H: ValueTree, I: ValueTree, J: ValueTree, K: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G, H, I, J, K)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value, <H as ValueTree>::Value, <I as ValueTree>::Value, <J as ValueTree>::Value, <K as ValueTree>::Value)

source§

impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree, E: ValueTree, F: ValueTree, G: ValueTree, H: ValueTree, I: ValueTree, J: ValueTree, K: ValueTree, L: ValueTree> ValueTree for TupleValueTree<(A, B, C, D, E, F, G, H, I, J, K, L)>

§

type Value = (<A as ValueTree>::Value, <B as ValueTree>::Value, <C as ValueTree>::Value, <D as ValueTree>::Value, <E as ValueTree>::Value, <F as ValueTree>::Value, <G as ValueTree>::Value, <H as ValueTree>::Value, <I as ValueTree>::Value, <J as ValueTree>::Value, <K as ValueTree>::Value, <L as ValueTree>::Value)

source§

impl<K, V> ValueTree for BTreeMapValueTree<K, V>
where K: ValueTree, V: ValueTree, K::Value: Ord,

§

type Value = BTreeMap<<K as ValueTree>::Value, <V as ValueTree>::Value>

source§

impl<K, V> ValueTree for HashMapValueTree<K, V>
where K: ValueTree, V: ValueTree, K::Value: Hash + Eq,

§

type Value = HashMap<<K as ValueTree>::Value, <V as ValueTree>::Value>

source§

impl<S: ValueTree> ValueTree for FlattenValueTree<S>
where S::Value: Strategy,

§

type Value = <<S as ValueTree>::Value as Strategy>::Value

source§

impl<S: ValueTree, F: Fn(&S::Value) -> bool> ValueTree for proptest::strategy::Filter<S, F>

§

type Value = <S as ValueTree>::Value

source§

impl<S: ValueTree, F: FilterFn<S::Value>> ValueTree for proptest::strategy::statics::Filter<S, F>

§

type Value = <S as ValueTree>::Value

source§

impl<S: ValueTree, F: MapFn<S::Value>> ValueTree for proptest::strategy::statics::Map<S, F>

§

type Value = <F as MapFn<<S as ValueTree>::Value>>::Output

source§

impl<S: ValueTree, O: Debug> ValueTree for MapInto<S, O>
where S::Value: Into<O>,

§

type Value = O

source§

impl<S: ValueTree, O: Debug, F: Fn(S::Value) -> O> ValueTree for proptest::strategy::Map<S, F>

§

type Value = O

source§

impl<S: ValueTree, O: Debug, F: Fn(S::Value, TestRng) -> O> ValueTree for PerturbValueTree<S, F>

§

type Value = O

source§

impl<T> ValueTree for BTreeSetValueTree<T>
where T: ValueTree, T::Value: Ord,

source§

impl<T> ValueTree for BinaryHeapValueTree<T>
where T: ValueTree, T::Value: Ord,

source§

impl<T> ValueTree for HashSetValueTree<T>
where T: ValueTree, T::Value: Hash + Eq,

§

type Value = HashSet<<T as ValueTree>::Value>

source§

impl<T> ValueTree for LinkedListValueTree<T>
where T: ValueTree,

source§

impl<T> ValueTree for VecDequeValueTree<T>
where T: ValueTree,

source§

impl<T> ValueTree for OptionValueTree<T>
where T: Strategy,

§

type Value = Option<<T as Strategy>::Value>

source§

impl<T> ValueTree for SelectValueTree<T>
where T: Clone + Debug + 'static,

§

type Value = T

source§

impl<T> ValueTree for RegexGeneratorValueTree<T>
where T: Debug,

§

type Value = T

source§

impl<T, E> ValueTree for MaybeErrValueTree<T, E>
where T: Strategy, E: Strategy,

§

type Value = Result<<T as Strategy>::Value, <E as Strategy>::Value>

source§

impl<T, E> ValueTree for MaybeOkValueTree<T, E>
where T: Strategy, E: Strategy,

§

type Value = Result<<T as Strategy>::Value, <E as Strategy>::Value>

source§

impl<T: BitSetLike> ValueTree for BitSetValueTree<T>

§

type Value = T

source§

impl<T: Clone + Debug> ValueTree for Just<T>

§

type Value = T

source§

impl<T: Debug + Clone + 'static> ValueTree for SubsequenceValueTree<T>

§

type Value = Vec<T>

source§

impl<T: Debug, F: Fn() -> T> ValueTree for LazyJust<T, F>

§

type Value = T

source§

impl<T: Strategy> ValueTree for UnionValueTree<T>

§

type Value = <T as Strategy>::Value

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 1]>

§

type Value = [<T as ValueTree>::Value; 1]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 2]>

§

type Value = [<T as ValueTree>::Value; 2]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 3]>

§

type Value = [<T as ValueTree>::Value; 3]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 4]>

§

type Value = [<T as ValueTree>::Value; 4]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 5]>

§

type Value = [<T as ValueTree>::Value; 5]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 6]>

§

type Value = [<T as ValueTree>::Value; 6]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 7]>

§

type Value = [<T as ValueTree>::Value; 7]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 8]>

§

type Value = [<T as ValueTree>::Value; 8]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 9]>

§

type Value = [<T as ValueTree>::Value; 9]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 10]>

§

type Value = [<T as ValueTree>::Value; 10]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 11]>

§

type Value = [<T as ValueTree>::Value; 11]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 12]>

§

type Value = [<T as ValueTree>::Value; 12]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 13]>

§

type Value = [<T as ValueTree>::Value; 13]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 14]>

§

type Value = [<T as ValueTree>::Value; 14]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 15]>

§

type Value = [<T as ValueTree>::Value; 15]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 16]>

§

type Value = [<T as ValueTree>::Value; 16]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 17]>

§

type Value = [<T as ValueTree>::Value; 17]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 18]>

§

type Value = [<T as ValueTree>::Value; 18]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 19]>

§

type Value = [<T as ValueTree>::Value; 19]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 20]>

§

type Value = [<T as ValueTree>::Value; 20]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 21]>

§

type Value = [<T as ValueTree>::Value; 21]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 22]>

§

type Value = [<T as ValueTree>::Value; 22]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 23]>

§

type Value = [<T as ValueTree>::Value; 23]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 24]>

§

type Value = [<T as ValueTree>::Value; 24]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 25]>

§

type Value = [<T as ValueTree>::Value; 25]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 26]>

§

type Value = [<T as ValueTree>::Value; 26]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 27]>

§

type Value = [<T as ValueTree>::Value; 27]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 28]>

§

type Value = [<T as ValueTree>::Value; 28]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 29]>

§

type Value = [<T as ValueTree>::Value; 29]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 30]>

§

type Value = [<T as ValueTree>::Value; 30]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 31]>

§

type Value = [<T as ValueTree>::Value; 31]

source§

impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 32]>

§

type Value = [<T as ValueTree>::Value; 32]

source§

impl<T: ValueTree> ValueTree for VecValueTree<T>

§

type Value = Vec<<T as ValueTree>::Value>

source§

impl<T: ValueTree> ValueTree for Fuse<T>

§

type Value = <T as ValueTree>::Value

source§

impl<T: ValueTree> ValueTree for NoShrink<T>

§

type Value = <T as ValueTree>::Value

source§

impl<V: ValueTree> ValueTree for ShuffleValueTree<V>
where V::Value: Shuffleable,

§

type Value = <V as ValueTree>::Value

source§

impl<V: ValueTree, F: Fn(V::Value) -> Option<O>, O: Debug> ValueTree for FilterMapValueTree<V, F, O>

§

type Value = O