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()
.
Associated Types
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 + ?Sized> ValueTree for Box<T>
[src]
Implementors
impl<T: Clone + Debug> ValueTree for Just<T> type Value = T;
impl<T: ValueTree> ValueTree for NoShrink<T> type Value = T::Value;
impl<S: ValueTree, O: Debug, F: Fn(S::Value) -> O> ValueTree for proptest::strategy::Map<S, F> type Value = O;
impl<S: ValueTree, O: Debug, F: Fn(S::Value, XorShiftRng) -> O> ValueTree for PerturbValueTree<S, F> type Value = O;
impl<S: ValueTree, F: Fn(&S::Value) -> bool> ValueTree for proptest::strategy::Filter<S, F> type Value = S::Value;
impl<S: ValueTree> ValueTree for FlattenValueTree<S> where
S::Value: Strategy, type Value = ValueFor<S::Value>;impl<T: ValueTree> ValueTree for UnionValueTree<T> type Value = T::Value;
impl<A: ValueTree, B: ValueTree<Value = A::Value>> ValueTree for TupleUnionValueTree<(A, Option<B>)> type Value = A::Value;
impl<A: ValueTree, B: ValueTree<Value = A::Value>, C: ValueTree<Value = A::Value>> ValueTree for TupleUnionValueTree<(A, Option<B>, Option<C>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
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>)> type Value = A::Value;
impl<V: ValueTree> ValueTree for ShuffleValueTree<V> where
V::Value: Shuffleable, type Value = V::Value;impl<T: ValueTree> ValueTree for Fuse<T> type Value = T::Value;
impl<S: ValueTree, F: FilterFn<S::Value>> ValueTree for proptest::strategy::statics::Filter<S, F> type Value = S::Value;
impl<S: ValueTree, F: MapFn<S::Value>> ValueTree for proptest::strategy::statics::Map<S, F> type Value = F::Output;
impl ValueTree for BoolValueTree type Value = bool;
impl ValueTree for proptest::num::i8::BinarySearch type Value = i8;
impl ValueTree for proptest::num::i16::BinarySearch type Value = i16;
impl ValueTree for proptest::num::i32::BinarySearch type Value = i32;
impl ValueTree for proptest::num::i64::BinarySearch type Value = i64;
impl ValueTree for proptest::num::isize::BinarySearch type Value = isize;
impl ValueTree for proptest::num::u8::BinarySearch type Value = u8;
impl ValueTree for proptest::num::u16::BinarySearch type Value = u16;
impl ValueTree for proptest::num::u32::BinarySearch type Value = u32;
impl ValueTree for proptest::num::u64::BinarySearch type Value = u64;
impl ValueTree for proptest::num::usize::BinarySearch type Value = usize;
impl ValueTree for proptest::num::f32::BinarySearch type Value = f32;
impl ValueTree for proptest::num::f64::BinarySearch type Value = f64;
impl<T: BitSetLike> ValueTree for BitSetValueTree<T> type Value = T;
impl<A: ValueTree> ValueTree for TupleValueTree<(A,)> type Value = (A::Value,);
impl<A: ValueTree, B: ValueTree> ValueTree for TupleValueTree<(A, B)> type Value = (A::Value, B::Value);
impl<A: ValueTree, B: ValueTree, C: ValueTree> ValueTree for TupleValueTree<(A, B, C)> type Value = (A::Value, B::Value, C::Value);
impl<A: ValueTree, B: ValueTree, C: ValueTree, D: ValueTree> ValueTree for TupleValueTree<(A, B, C, D)> 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)> 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)> 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)> 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)> 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)> 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)> type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value);
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 1]> type Value = [T::Value; 1];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 2]> type Value = [T::Value; 2];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 3]> type Value = [T::Value; 3];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 4]> type Value = [T::Value; 4];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 5]> type Value = [T::Value; 5];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 6]> type Value = [T::Value; 6];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 7]> type Value = [T::Value; 7];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 8]> type Value = [T::Value; 8];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 9]> type Value = [T::Value; 9];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 10]> type Value = [T::Value; 10];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 11]> type Value = [T::Value; 11];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 12]> type Value = [T::Value; 12];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 13]> type Value = [T::Value; 13];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 14]> type Value = [T::Value; 14];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 15]> type Value = [T::Value; 15];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 16]> type Value = [T::Value; 16];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 17]> type Value = [T::Value; 17];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 18]> type Value = [T::Value; 18];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 19]> type Value = [T::Value; 19];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 20]> type Value = [T::Value; 20];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 21]> type Value = [T::Value; 21];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 22]> type Value = [T::Value; 22];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 23]> type Value = [T::Value; 23];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 24]> type Value = [T::Value; 24];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 25]> type Value = [T::Value; 25];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 26]> type Value = [T::Value; 26];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 27]> type Value = [T::Value; 27];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 28]> type Value = [T::Value; 28];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 29]> type Value = [T::Value; 29];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 30]> type Value = [T::Value; 30];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 31]> type Value = [T::Value; 31];
impl<T: ValueTree> ValueTree for ArrayValueTree<[T; 32]> type Value = [T::Value; 32];
impl<T> ValueTree for VecDequeValueTree<T> where
T: ValueTree, type Value = VecDeque<T::Value>;impl<T> ValueTree for LinkedListValueTree<T> where
T: ValueTree, type Value = LinkedList<T::Value>;impl<T> ValueTree for BinaryHeapValueTree<T> where
T: ValueTree,
T::Value: Ord, type Value = BinaryHeap<T::Value>;impl<T> ValueTree for HashSetValueTree<T> where
T: ValueTree,
T::Value: Hash + Eq, type Value = HashSet<T::Value>;impl<T> ValueTree for BTreeSetValueTree<T> where
T: ValueTree,
T::Value: Ord, type Value = BTreeSet<T::Value>;impl<K, V> ValueTree for HashMapValueTree<K, V> where
K: ValueTree,
V: ValueTree,
K::Value: Hash + Eq, type Value = HashMap<K::Value, V::Value>;impl<K, V> ValueTree for BTreeMapValueTree<K, V> where
K: ValueTree,
V: ValueTree,
K::Value: Ord, type Value = BTreeMap<K::Value, V::Value>;impl<T: ValueTree> ValueTree for VecValueTree<T> type Value = Vec<T::Value>;
impl ValueTree for CharValueTree type Value = char;
impl<T> ValueTree for RegexGeneratorValueTree<T> where
T: Debug, type Value = T;impl<T> ValueTree for OptionValueTree<T> where
T: ValueTree, type Value = Option<T::Value>;impl<T, E> ValueTree for MaybeOkValueTree<T, E> where
T: ValueTree,
E: ValueTree, type Value = Result<T::Value, E::Value>;impl<T, E> ValueTree for MaybeErrValueTree<T, E> where
T: ValueTree,
E: ValueTree, type Value = Result<T::Value, E::Value>;impl<T: Debug + Clone + 'static> ValueTree for SubsequenceValueTree<T> type Value = Vec<T>;
impl<T> ValueTree for SelectValueTree<T> where
T: Clone + Debug + 'static, type Value = T;