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) -> TestRng

impl Debug for TestRng

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

impl RngCore for TestRng

fn next_u32(&mut self) -> u32
fn next_u64(&mut self) -> u64
fn fill_bytes(&mut self, dest: &mut [u8])

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: RngCore + ?Sized,

impl<R> TryRngCore for TestRng where R: RngCore + ?Sized,

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for TestRng where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for TestRng where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

fn borrow_mut(&mut self) -> &mut T

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

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for TestRng

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Read<Exclusive, BecauseExclusive> for TestRng where T: ?Sized,

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

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

fn vzip(self) -> V