Struct proptest::test_runner::TestRng
source · [−]pub struct TestRng { /* private fields */ }
Expand description
Proptest’s random number generator.
Implementations
sourceimpl 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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn bytes_used(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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 RefUnwindSafe for TestRng
impl Send for TestRng
impl Sync for TestRng
impl Unpin for TestRng
impl UnwindSafe for TestRng
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<R> Rng for R where
R: RngCore + ?Sized,
impl<R> Rng for R where
R: RngCore + ?Sized,
sourcefn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
fn gen<T>(&mut self) -> T where
Standard: Distribution<T>,
sourcefn gen_range<T, R>(&mut self, range: R) -> T where
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> T where
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
sourcefn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> T where
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
sourcefn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> where
D: Distribution<T>,
Create an iterator that generates values using the given distribution. Read more
sourcefn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
Return a bool with a probability p
of being true. Read more
sourcefn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of 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 more