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 true if the current subset contains no elements.

Returns the total number of elements in the universal set.

This remains fixed once the GrowingSubset has been created.

Returns a slice containing the items in the current subset.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The input does not need to be pre-sorted.

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.