pub struct Mock<'d> { /* private fields */ }
Expand description

Mock RNG, containing invocation state and delegate closures.

Implementations

Assigns a Rand::next_u128 delegate to the mock. I.e., when the Rand::next_u128 method is invoked on the mock (directly, or via another method), it will delegate to the given closure.

Examples
use tinyrand::Rand;
use tinyrand_alloc::Mock;
let mut mock = Mock::default()
    .with_next_u128(|_| 42);
assert_eq!(42, mock.next_usize());
assert_eq!(42, mock.next_u64());
assert_eq!(42, mock.next_u128());

Assigns a Rand::next_bool delegate to the mock. I.e., when the Rand::next_bool method is invoked on the mock, it will delegate to the given closure.

Examples
use tinyrand::{Probability, Rand};
use tinyrand_alloc::Mock;
let mut mock = Mock::default()
    .with_next_bool(|_, _| true);
assert!(mock.next_bool(Probability::new(0.01)));

Assigns a Rand::next_lim_u128 delegate to the mock. I.e., when the Rand::next_lim_u128 method is invoked on the mock, it will delegate to the given closure. This delegate can be used to effectively mock Rand::next_lim and Rand::next_range methods.

Examples
use tinyrand::{Rand, RandRange};
use tinyrand_alloc::Mock;
let mut mock = Mock::default()
    .with_next_lim_u128(|_, _| 17);
assert_eq!(17, mock.next_lim_u64(66));
assert_eq!(27, mock.next_range(10..100u16));

Obtains the underlying mock state.

Trait Implementations

Returns the “default value” for a type. Read more

Delegates to the underlying closure and increments the state.next_u128_invocations counter after the closure returns.

Delegates to the underlying closure and increments the state.next_bool_invocations counter after the closure returns.

Delegates to the underlying closure and increments the state.next_lim_u128_invocations counter after the closure returns.

Returns the next random u64.

Generates a random number in 0..lim.

Generates a random number in 0..lim.

Generates a random number in 0..lim.

Returns the next random u16.

Returns the next random u32.

Returns the next random usize.

Generates a random number in 0..lim.

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

Returns the argument unchanged.

Calls U::from(self).

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

Generates a random number in 0..N.

Generates a random number in 0..N.

Generates a random number in 0..N.

Generates a random number in 0..N.

Generates a random number in 0..N.

Generates a random number in the given range.

Generates a random number in the given range.

Generates a random number in the given range.

Generates a random number in the given range.

Generates a random number in the given range.

Generates a random number in the given range.

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.