proptest::strategy

Trait 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

Source§

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>

Source§

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

Source§

impl ValueTree for CharValueTree

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl ValueTree for IndexValueTree

Source§

impl ValueTree for SelectorValueTree

Source§

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

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>>)>

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>>)>

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>>)>

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>>)>

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>>)>

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>>)>

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>>)>

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>>)>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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)>

Source§

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,

Source§

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

Available on crate feature std only.
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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>,

Source§

type Value = O

Source§

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

Source§

type Value = O

Source§

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

Source§

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,

Available on crate feature std only.
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,

Source§

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

Source§

type Value = T

Source§

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

Available on crate feature std only.
Source§

type Value = T

Source§

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

Source§

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,

Source§

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

Source§

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

Source§

type Value = T

Source§

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

Source§

type Value = T

Source§

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

Source§

type Value = Vec<T>

Source§

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

Source§

type Value = T

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T: ValueTree, const N: usize> ValueTree for ArrayValueTree<[T; N]>

Source§

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

Source§

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

Source§

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

Source§

type Value = O