Skip to main content

Strategy

Trait Strategy 

Source
pub trait Strategy<T> {
    type Tree: ValueTree<T>;

    // Required method
    fn new_tree(&self, runner: &mut Runner) -> Result<Self::Tree, GenError>;
}
Expand description

A source of values of type T, with shrinking, for property testing.

This is the seam between test-better’s property runner (for_all) and a concrete generation/shrinking backend. The crate ships exactly one backend, proptest: every proptest::strategy::Strategy is a Strategy here through a blanket impl.

§The blanket impl and its one limitation

Because the blanket impl<S: proptest::strategy::Strategy> Strategy for S covers every proptest strategy, a user type that also happens to be a proptest::strategy::Strategy cannot carry a hand-written Strategy impl (coherence cannot prove the two do not overlap). This is acceptable today: proptest is the one backend and every strategy is a proptest strategy already. The trait is a seam for a future backend, not a finished portability layer.

Required Associated Types§

Source

type Tree: ValueTree<T>

The shrinkable, in-progress value this strategy produces.

Required Methods§

Source

fn new_tree(&self, runner: &mut Runner) -> Result<Self::Tree, GenError>

Draws one fresh value tree from runner’s randomness.

§Errors

Returns GenError if the strategy could not produce a value (a filtered strategy that exhausted its rejection budget).

Implementors§

Source§

impl<S, T> Strategy<T> for S
where S: Strategy<Value = T>,

Source§

impl<T> Strategy<T> for ArbitraryStrategy<T>
where T: Arbitrary,