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

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

The type of the value produced by this ValueTree.

Required Methods

Returns the current value.

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.

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

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

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

Implementors

impl ValueTree for BoolValueTree
[src]

impl ValueTree for CharValueTree
[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl ValueTree for IndexValueTree
[src]

impl ValueTree for SelectorValueTree
[src]

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

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

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

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

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

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

impl<A: ValueTree, B: ValueTree<Value = A::Value>, C: ValueTree<Value = A::Value>, D: ValueTree<Value = A::Value>, E: ValueTree<Value = A::Value>, F: ValueTree<Value = A::Value>> ValueTree for TupleUnionValueTree<(A, Option<B>, Option<C>, Option<D>, Option<E>, Option<F>)>
[src]

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

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

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

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

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

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

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

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

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]

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]

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]

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]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<T> ValueTree for RegexGeneratorValueTree<T> where
    T: Debug
[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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