[][src]Struct libra_proptest_helpers::GrowingSubset

pub struct GrowingSubset<Ix, T> { /* fields omitted */ }

A set of elements, each with an associated key, that grows over time.

This is called GrowingSubset because the universal set the subset grows from is provided upfront. At any time, the items included form the current subset.

GrowingSubset integrates with proptest through the pick_item and pick_value methods.


use libra_proptest_helpers::GrowingSubset;
let items = vec![(1, "a"), (3, "c"), (2, "b"), (2, "d")];
let mut subset: GrowingSubset<_, _> = items.into_iter().collect();

assert_eq!(subset.total_len(), 4);
assert_eq!(subset.len(), 0);
assert_eq!(subset.current(), &[]);

assert_eq!(subset.len(), 1);
assert_eq!(subset.current(), &[(1, "a")]);

assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);

assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);


impl<Ix, T> GrowingSubset<Ix, T> where
    Ix: Ord

pub fn len(&self) -> usize[src]

Returns the number of elements in the current subset.

See total_len for the length of the universal set.

pub fn is_empty(&self) -> bool[src]

Returns true if the current subset contains no elements.

pub fn total_len(&self) -> usize[src]

Returns the total number of elements in the universal set.

This remains fixed once the GrowingSubset has been created.

pub fn current(&self) -> &[(Ix, T)][src]

Returns a slice containing the items in the current subset.

pub fn pick_item(&self, index: &Index) -> &(Ix, T)[src]

Chooses an (index, value) pair from the current subset using the provided Index instance as the source of randomness.

pub fn pick_value(&self, index: &Index) -> &T[src]

Chooses a value from the current subset using the provided Index instance as the source of randomness.

pub fn advance_to(&mut self, to_idx: &Ix)[src]

Advances the valid subset to the provided index. After the end of this, the current subset will contain all elements where the index is less than to_idx.

If duplicate indexes exist, advance_to will cause all of the corresponding items to be included.

It is expected that advance_to will be called with larger indexes over time.

Trait Implementations

impl<Ix: Clone, T: Clone> Clone for GrowingSubset<Ix, T>[src]

impl<Ix: Debug, T: Debug> Debug for GrowingSubset<Ix, T>[src]

impl<Ix, T> FromIterator<(Ix, T)> for GrowingSubset<Ix, T> where
    Ix: Ord

Constructs a GrowingSubset from an iterator of (index, value) pairs.

The input does not need to be pre-sorted.

Auto Trait Implementations

impl<Ix, T> RefUnwindSafe for GrowingSubset<Ix, T> where
    Ix: RefUnwindSafe,
    T: RefUnwindSafe

impl<Ix, T> Send for GrowingSubset<Ix, T> where
    Ix: Send,
    T: Send

impl<Ix, T> Sync for GrowingSubset<Ix, T> where
    Ix: Sync,
    T: Sync

impl<Ix, T> Unpin for GrowingSubset<Ix, T> where
    Ix: Unpin,
    T: Unpin

impl<Ix, T> UnwindSafe for GrowingSubset<Ix, T> where
    Ix: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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.

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