Struct diem_proptest_helpers::GrowingSubset [−][src]
pub struct GrowingSubset<Ix, T> { /* fields omitted */ }Expand description
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.
Examples
use diem_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(), &[]);
subset.advance_to(&2);
assert_eq!(subset.len(), 1);
assert_eq!(subset.current(), &[(1, "a")]);
subset.advance_to(&4);
assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);
subset.advance_to(&5);
assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);Implementations
Returns the number of elements in the current subset.
See total_len for the length of the universal set.
Returns the total number of elements in the universal set.
This remains fixed once the GrowingSubset has been created.
Chooses an (index, value) pair from the current subset using the provided
Index instance as the source of randomness.
Chooses a value from the current subset using the provided
Index instance as the source of randomness.
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
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
Mutably borrows from an owned value. Read more