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

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.

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.

Implementors