Struct proptest::strategy::Fuse

source ·
pub struct Fuse<T> { /* private fields */ }
Expand description

Adaptor for Strategy and ValueTree which guards simplify() and complicate() to avoid contract violations.

This can be used as an intermediate when the caller would otherwise need its own separate state tracking, or as a workaround for a broken ValueTree implementation.

This wrapper specifically has the following effects:

  • Calling complicate() before simplify() was ever called does nothing and returns false.

  • Calling simplify() after it has returned false and no calls to complicate() returned true does nothing and returns false.

  • Calling complicate() after it has returned false and no calls to simplify() returned true does nothing and returns false.

There is also limited functionality to alter the internal state to assist in its usage as a state tracker.

Wrapping a Strategy in Fuse simply causes its ValueTree to also be wrapped in Fuse.

While this is similar to std::iter::Fuse, it is not exposed as a method on Strategy since the vast majority of proptest should never need this functionality; it mainly concerns implementors of strategies.

Implementations§

source§

impl<T> Fuse<T>

source

pub fn new(inner: T) -> Self

Wrap the given T in Fuse.

source§

impl<T: ValueTree> Fuse<T>

source

pub fn may_simplify(&self) -> bool

Return whether a call to simplify() may be productive.

Formally, this is true if one of the following holds:

  • simplify() has never been called.
  • The most recent call to simplify() returned true.
  • complicate() has been called more recently than simplify() and the last call returned true.
source

pub fn disallow_simplify(&mut self)

Disallow any further calls to simplify() until a call to complicate() returns true.

source

pub fn may_complicate(&self) -> bool

Return whether a call to complicate() may be productive.

Formally, this is true if one of the following holds:

  • The most recent call to complicate() returned true.
  • simplify() has been called more recently than complicate() and the last call returned true.
source

pub fn disallow_complicate(&mut self)

Disallow any further calls to complicate() until a call to simplify() returns true.

source

pub fn freeze(&mut self)

Prevent any further shrinking operations from occurring.

Trait Implementations§

source§

impl<T: Clone> Clone for Fuse<T>

source§

fn clone(&self) -> Fuse<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Fuse<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Strategy> Strategy for Fuse<T>

§

type Tree = Fuse<<T as Strategy>::Tree>

The value tree generated by this Strategy.
§

type Value = <T as Strategy>::Value

The type of value used by functions under test generated by this Strategy. Read more
source§

fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

Generate a new value tree from the given runner. Read more
source§

fn prop_map<O: Debug, F: Fn(Self::Value) -> O>(self, fun: F) -> Map<Self, F>
where Self: Sized,

Returns a strategy which produces values transformed by the function fun. Read more
source§

fn prop_map_into<O: Debug>(self) -> MapInto<Self, O>
where Self: Sized, Self::Value: Into<O>,

Returns a strategy which produces values of type O by transforming Self with Into<O>. Read more
source§

fn prop_perturb<O: Debug, F: Fn(Self::Value, TestRng) -> O>( self, fun: F ) -> Perturb<Self, F>
where Self: Sized,

Returns a strategy which produces values transformed by the function fun, which is additionally given a random number generator. Read more
source§

fn prop_flat_map<S: Strategy, F: Fn(Self::Value) -> S>( self, fun: F ) -> Flatten<Map<Self, F>>
where Self: Sized,

Maps values produced by this strategy into new strategies and picks values from those strategies. Read more
source§

fn prop_ind_flat_map<S: Strategy, F: Fn(Self::Value) -> S>( self, fun: F ) -> IndFlatten<Map<Self, F>>
where Self: Sized,

Maps values produced by this strategy into new strategies and picks values from those strategies while considering the new strategies to be independent. Read more
source§

fn prop_ind_flat_map2<S: Strategy, F: Fn(Self::Value) -> S>( self, fun: F ) -> IndFlattenMap<Self, F>
where Self: Sized,

Similar to prop_ind_flat_map(), but produces 2-tuples with the input generated from self in slot 0 and the derived strategy in slot 1. Read more
source§

fn prop_filter<R: Into<Reason>, F: Fn(&Self::Value) -> bool>( self, whence: R, fun: F ) -> Filter<Self, F>
where Self: Sized,

Returns a strategy which only produces values accepted by fun. Read more
source§

fn prop_filter_map<F: Fn(Self::Value) -> Option<O>, O: Debug>( self, whence: impl Into<Reason>, fun: F ) -> FilterMap<Self, F>
where Self: Sized,

Returns a strategy which only produces transformed values where fun returns Some(value) and rejects those where fun returns None. Read more
source§

fn prop_union(self, other: Self) -> Union<Self>
where Self: Sized,

Returns a strategy which picks uniformly from self and other. Read more
source§

fn prop_recursive<R: Strategy<Value = Self::Value> + 'static, F: Fn(BoxedStrategy<Self::Value>) -> R>( self, depth: u32, desired_size: u32, expected_branch_size: u32, recurse: F ) -> Recursive<Self::Value, F>
where Self: Sized + 'static,

Generate a recursive structure with self items as leaves. Read more
source§

fn boxed(self) -> BoxedStrategy<Self::Value>
where Self: Sized + 'static,

Erases the type of this Strategy so it can be passed around as a simple trait object. Read more
source§

fn no_shrink(self) -> NoShrink<Self>
where Self: Sized,

Wraps this strategy to prevent values from being subject to shrinking. Read more
source§

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

§

type Value = <T as ValueTree>::Value

The type of the value produced by this ValueTree.
source§

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

Returns the current value.
source§

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. Read more
source§

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. Read more
source§

impl<T: Copy> Copy for Fuse<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V