Trait zebra_test::prelude::prop::strategy::ValueTree

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§

type Value: Debug

The type of the value produced by this ValueTree.

Required Methods§

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

Returns the current value.

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.

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§

§

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

§

type Value = T

§

fn simplify(&mut self) -> bool

§

fn complicate(&mut self) -> bool

§

fn current(&self) -> <fn() -> T as ValueTree>::Value

§

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

§

type Value = <T as ValueTree>::Value

§

fn current(&self) -> <Box<T> as ValueTree>::Value

§

fn simplify(&mut self) -> bool

§

fn complicate(&mut self) -> bool

Implementors§

§

impl ValueTree for BoolValueTree

§

type Value = bool

§

impl ValueTree for CharValueTree

§

type Value = char

§

impl ValueTree for zebra_test::prelude::prop::num::f32::BinarySearch

§

type Value = f32

§

impl ValueTree for zebra_test::prelude::prop::num::f64::BinarySearch

§

type Value = f64

§

impl ValueTree for zebra_test::prelude::prop::num::i8::BinarySearch

§

type Value = i8

§

impl ValueTree for zebra_test::prelude::prop::num::i16::BinarySearch

§

type Value = i16

§

impl ValueTree for zebra_test::prelude::prop::num::i32::BinarySearch

§

type Value = i32

§

impl ValueTree for zebra_test::prelude::prop::num::i64::BinarySearch

§

type Value = i64

§

impl ValueTree for zebra_test::prelude::prop::num::i128::BinarySearch

§

type Value = i128

§

impl ValueTree for zebra_test::prelude::prop::num::isize::BinarySearch

§

type Value = isize

§

impl ValueTree for zebra_test::prelude::prop::num::u8::BinarySearch

§

type Value = u8

§

impl ValueTree for zebra_test::prelude::prop::num::u16::BinarySearch

§

type Value = u16

§

impl ValueTree for zebra_test::prelude::prop::num::u32::BinarySearch

§

type Value = u32

§

impl ValueTree for zebra_test::prelude::prop::num::u64::BinarySearch

§

type Value = u64

§

impl ValueTree for zebra_test::prelude::prop::num::u128::BinarySearch

§

type Value = u128

§

impl ValueTree for zebra_test::prelude::prop::num::usize::BinarySearch

§

type Value = usize

§

impl ValueTree for IndexValueTree

§

type Value = Index

§

impl ValueTree for SelectorValueTree

§

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

§

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

§

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

§

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

§

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

§

type Value = <A as Strategy>::Value

§

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

§

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

§

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

§

type Value = <A as Strategy>::Value

§

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

§

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

§

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

§

type Value = <A as Strategy>::Value

§

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

§

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

§

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

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F> 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)

§

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

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F, G> 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)

§

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

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F, G, H> 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)

§

impl<A, B, C, D, E, F, G, H> 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>>)>
where A: Strategy, B: Strategy<Value = <A as Strategy>::Value>, C: Strategy<Value = <A as Strategy>::Value>, D: Strategy<Value = <A as Strategy>::Value>, E: Strategy<Value = <A as Strategy>::Value>, F: Strategy<Value = <A as Strategy>::Value>, G: Strategy<Value = <A as Strategy>::Value>, H: Strategy<Value = <A as Strategy>::Value>,

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F, G, H, I> 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)

§

impl<A, B, C, D, E, F, G, H, I> 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>>)>
where A: Strategy, B: Strategy<Value = <A as Strategy>::Value>, C: Strategy<Value = <A as Strategy>::Value>, D: Strategy<Value = <A as Strategy>::Value>, E: Strategy<Value = <A as Strategy>::Value>, F: Strategy<Value = <A as Strategy>::Value>, G: Strategy<Value = <A as Strategy>::Value>, H: Strategy<Value = <A as Strategy>::Value>, I: Strategy<Value = <A as Strategy>::Value>,

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F, G, H, I, J> 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)

§

impl<A, B, C, D, E, F, G, H, I, J> 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>>)>
where A: Strategy, B: Strategy<Value = <A as Strategy>::Value>, C: Strategy<Value = <A as Strategy>::Value>, D: Strategy<Value = <A as Strategy>::Value>, E: Strategy<Value = <A as Strategy>::Value>, F: Strategy<Value = <A as Strategy>::Value>, G: Strategy<Value = <A as Strategy>::Value>, H: Strategy<Value = <A as Strategy>::Value>, I: Strategy<Value = <A as Strategy>::Value>, J: Strategy<Value = <A as Strategy>::Value>,

§

type Value = <A as Strategy>::Value

§

impl<A, B, C, D, E, F, G, H, I, J, K> 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)

§

impl<A, B, C, D, E, F, G, H, I, J, K, L> 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)

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<S, F> ValueTree for zebra_test::prelude::prop::strategy::statics::Filter<S, F>
where S: ValueTree, F: FilterFn<<S as ValueTree>::Value>,

§

type Value = <S as ValueTree>::Value

§

impl<S, F> ValueTree for zebra_test::prelude::prop::strategy::statics::Map<S, F>
where S: ValueTree, F: MapFn<<S as ValueTree>::Value>,

§

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

§

impl<S, F> ValueTree for zebra_test::prelude::prop::strategy::Filter<S, F>
where S: ValueTree, F: Fn(&<S as ValueTree>::Value) -> bool,

§

type Value = <S as ValueTree>::Value

§

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

§

type Value = O

§

impl<S, O, F> ValueTree for zebra_test::prelude::prop::strategy::Map<S, F>
where S: ValueTree, O: Debug, F: Fn(<S as ValueTree>::Value) -> O,

§

type Value = O

§

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

§

type Value = O

§

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

§

type Value = T

§

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

§

type Value = T

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

type Value = T

§

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

§

type Value = Vec<T>

§

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

§

type Value = T

§

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

§

type Value = <T as ValueTree>::Value

§

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

§

type Value = <T as ValueTree>::Value

§

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

§

type Value = <T as Strategy>::Value

§

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

§

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

§

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

§

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

§

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

§

type Value = T

§

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

§

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

§

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

§

type Value = <V as ValueTree>::Value

§

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

§

type Value = O