pub struct TestRng { /* private fields */ }
Expand description
Proptest’s random number generator.
Implementations§
Source§impl TestRng
impl TestRng
Sourcepub fn from_seed(algorithm: RngAlgorithm, seed: &[u8]) -> Self
pub 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
.
Sourcepub fn bytes_used(&self) -> Vec<u8> ⓘ
pub 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.
Sourcepub fn deterministic_rng(algorithm: RngAlgorithm) -> Self
pub 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§
Auto Trait Implementations§
impl Freeze for TestRng
impl RefUnwindSafe for TestRng
impl Send for TestRng
impl Sync for TestRng
impl Unpin for TestRng
impl UnwindSafe for TestRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. I.e. gen_ratio(2, 3)
has chance of 2 in 3, or about 67%, of
returning true. If numerator == denominator
, then the returned value
is guaranteed to be true
. If numerator == 0
, then the returned
value is guaranteed to be false
. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 352 bytes