Trait proptest::strategy::ValueTree[][src]

pub trait ValueTree {
    type Value: Debug;
    fn current(&self) -> Self::Value;
fn simplify(&mut self) -> bool;
fn complicate(&mut self) -> bool; }

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.

Associated Types

type Value: Debug[src]

The type of the value produced by this ValueTree.

Loading content...

Required methods

fn current(&self) -> Self::Value[src]

Returns the current value.

fn simplify(&mut self) -> bool[src]

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.

fn complicate(&mut self) -> bool[src]

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.

Loading content...

Implementations on Foreign Types

impl<T: ValueTree + ?Sized> ValueTree for Box<T>[src]

type Value = T::Value

Loading content...

Implementors

impl ValueTree for BoolValueTree[src]

type Value = bool

impl ValueTree for CharValueTree[src]

type Value = char

impl ValueTree for proptest::num::f32::BinarySearch[src]

type Value = f32

impl ValueTree for proptest::num::f64::BinarySearch[src]

type Value = f64

impl ValueTree for proptest::num::i8::BinarySearch[src]

type Value = i8

impl ValueTree for proptest::num::i16::BinarySearch[src]

type Value = i16

impl ValueTree for proptest::num::i32::BinarySearch[src]

type Value = i32

impl ValueTree for proptest::num::i64::BinarySearch[src]

type Value = i64

impl ValueTree for proptest::num::i128::BinarySearch[src]

type Value = i128

impl ValueTree for proptest::num::isize::BinarySearch[src]

type Value = isize

impl ValueTree for proptest::num::u8::BinarySearch[src]

type Value = u8

impl ValueTree for proptest::num::u16::BinarySearch[src]

type Value = u16

impl ValueTree for proptest::num::u32::BinarySearch[src]

type Value = u32

impl ValueTree for proptest::num::u64::BinarySearch[src]

type Value = u64

impl ValueTree for proptest::num::u128::BinarySearch[src]

type Value = u128

impl ValueTree for proptest::num::usize::BinarySearch[src]

type Value = usize

impl ValueTree for IndexValueTree[src]

type Value = Index

impl ValueTree for SelectorValueTree[src]

type Value = Selector

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

type Value = A::Value

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

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

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>>)>[src]

type Value = A::Value

impl<A: ValueTree> ValueTree for TupleValueTree<(A,)>[src]

type Value = (A::Value,)

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

type Value = (A::Value, B::Value)

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

type Value = (A::Value, B::Value, C::Value)

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

type Value = (A::Value, B::Value, C::Value, D::Value)

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

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value)

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

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value)

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)>[src]

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value)

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)>[src]

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value)

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)>[src]

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

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)>[src]

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

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)>[src]

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

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)>[src]

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

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

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

impl<S: ValueTree> ValueTree for FlattenValueTree<S> where
    S::Value: Strategy
[src]

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

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

type Value = S::Value

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

type Value = F::Output

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

type Value = S::Value

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

type Value = O

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

type Value = O

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

type Value = O

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

type Value = BTreeSet<T::Value>

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

type Value = BinaryHeap<T::Value>

impl<T> ValueTree for LinkedListValueTree<T> where
    T: ValueTree
[src]

type Value = LinkedList<T::Value>

impl<T> ValueTree for VecDequeValueTree<T> where
    T: ValueTree
[src]

type Value = VecDeque<T::Value>

impl<T> ValueTree for OptionValueTree<T> where
    T: Strategy
[src]

type Value = Option<T::Value>

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

type Value = T

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

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

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

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

impl<T: BitSetLike> ValueTree for BitSetValueTree<T>[src]

type Value = T

impl<T: Strategy> ValueTree for UnionValueTree<T>[src]

type Value = T::Value

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

type Value = [T::Value; 1]

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

type Value = [T::Value; 2]

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

type Value = [T::Value; 3]

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

type Value = [T::Value; 4]

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

type Value = [T::Value; 5]

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

type Value = [T::Value; 6]

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

type Value = [T::Value; 7]

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

type Value = [T::Value; 8]

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

type Value = [T::Value; 9]

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

type Value = [T::Value; 10]

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

type Value = [T::Value; 11]

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

type Value = [T::Value; 12]

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

type Value = [T::Value; 13]

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

type Value = [T::Value; 14]

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

type Value = [T::Value; 15]

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

type Value = [T::Value; 16]

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

type Value = [T::Value; 17]

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

type Value = [T::Value; 18]

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

type Value = [T::Value; 19]

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

type Value = [T::Value; 20]

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

type Value = [T::Value; 21]

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

type Value = [T::Value; 22]

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

type Value = [T::Value; 23]

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

type Value = [T::Value; 24]

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

type Value = [T::Value; 25]

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

type Value = [T::Value; 26]

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

type Value = [T::Value; 27]

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

type Value = [T::Value; 28]

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

type Value = [T::Value; 29]

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

type Value = [T::Value; 30]

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

type Value = [T::Value; 31]

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

type Value = [T::Value; 32]

impl<T: ValueTree> ValueTree for VecValueTree<T>[src]

type Value = Vec<T::Value>

impl<T: ValueTree> ValueTree for Fuse<T>[src]

type Value = T::Value

impl<T: ValueTree> ValueTree for NoShrink<T>[src]

type Value = T::Value

impl<T: Clone + Debug> ValueTree for Just<T>[src]

type Value = T

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

type Value = Vec<T>

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

type Value = T

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

type Value = T

impl<V: ValueTree> ValueTree for ShuffleValueTree<V> where
    V::Value: Shuffleable
[src]

type Value = V::Value

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

type Value = O

Loading content...