Struct TestRng

pub struct TestRng { /* private fields */ }

Proptest's random number generator.

Implementations

impl TestRng

fn from_seed(algorithm: RngAlgorithm, seed: &[u8]) -> Self

Create a new RNG with the given algorithm and seed.

Any RNG created with the same algorithm-seed pair will produce the same sequence of values on all systems and all supporting versions of proptest.

Panics

Panics if seed is not an appropriate length for algorithm.

fn bytes_used(&self) -> Vec<u8>

Dumps the bytes obtained from the RNG so far (only works if the RNG is set to Recorder).

Panics

Panics if this RNG does not capture generated data.

fn deterministic_rng(algorithm: RngAlgorithm) -> Self

Returns a TestRng with a particular hard-coded seed.

The seed value will always be the same for a particular version of Proptest and algorithm, but may change across releases.

This is useful for testing things like strategy implementations without risking getting "unlucky" RNGs which deviate from average behaviour enough to cause spurious failures. For example, a strategy for bool which is supposed to produce true 50% of the time might have a test which checks that the distribution is "close enough" to 50%. If every test run starts with a different RNG, occasionally there will be spurious test failures when the RNG happens to produce a very skewed distribution. Using this or TestRunner::deterministic() avoids such issues.

Trait Implementations

impl Clone for TestRng

fn clone(&self) -> Self

impl Debug for TestRng

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

impl TryRng for TestRng

type Error = never;
fn try_next_u32(&mut self) -> Result<u32, Self::Error>
fn try_next_u64(&mut self) -> Result<u64, Self::Error>
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>

Auto Trait Implementations

impl Freeze for TestRng

impl RefUnwindSafe for TestRng

impl Send for TestRng

impl Sync for TestRng

impl Unpin for TestRng

impl UnsafeUnpin for TestRng

impl UnwindSafe for TestRng

Blanket Implementations

impl<R> Rng for TestRng where R: TryRng<Error = never> + ?Sized,

impl<R> RngCore for TestRng where R: Rng,

impl<R> RngExt for TestRng where R: Rng + ?Sized,

impl<R> TryRngCore for TestRng where R: TryRng,

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

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

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

impl<T> CloneToUninit for TestRng where T: Clone,

impl<T> From<T> for TestRng

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

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

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

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