Struct arbtest::ArbTest

source ·
pub struct ArbTest<P>
where P: FnMut(&mut Unstructured<'_>) -> Result<()>,
{ /* private fields */ }
Expand description

A builder for a property-based test.

This builder allows customizing various aspects of the test, such as the initial random seed, the amount of iterations to try, or the amount of random numbers (entropy) each test run gets.

For convenience, ArbTest automatically runs the test on drop. You can use ArbTest::run to run the test explicitly.

Implementations§

source§

impl<P> ArbTest<P>
where P: FnMut(&mut Unstructured<'_>) -> Result<()>,

source

pub fn size_min(self, size: u32) -> Self

Sets the lower bound on the amount of random bytes each test run gets.

Defaults to 32.

Each randomized test gets an arbitrary::Unstructured as a source of randomness. Unstructured can be thought of as a finite pseudo random number generator, or, alternatively, as a finite sequence of random numbers. The intuition here is that shorter sequences lead to simpler test cases.

The size parameter controls the length of the initial random sequence. More specifically, arbtest will run the test function multiple times, increasing the amount of entropy from size_min to size_max.

source

pub fn size_max(self, size: u32) -> Self

Sets the upper bound on the amount of random bytes each test run gets.

Defaults to 64 536.

See ArbTest::size_min.

source

pub fn budget(self, value: Duration) -> Self

Sets the approximate duration for the tests.

Defaults to 100ms, can be overridden via ARBTEST_BUDGET_MS environmental variable.

arbtest will re-run the test function until the time runs out or until it panics.

source

pub fn budget_ms(self, value: u64) -> Self

Sets the approximate duration for the tests, in milliseconds.

source

pub fn seed(self, seed: u64) -> Self

Fixes the random seed.

Normally, arbtest runs the test function multiple times, picking a fresh random seed of an increased complexity every time.

If the seed is set explicitly, the test function is run only once.

source

pub fn minimize(self) -> Self

Whether to try to minimize the seed after failure.

source

pub fn run(self)

Runs the test.

This is equivalent to just dropping ArbTest.

Trait Implementations§

source§

impl<P> Drop for ArbTest<P>
where P: FnMut(&mut Unstructured<'_>) -> Result<()>,

source§

fn drop(&mut self)

Runs property test.

See ArbTest::run.

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for ArbTest<P>
where P: RefUnwindSafe,

§

impl<P> Send for ArbTest<P>
where P: Send,

§

impl<P> Sync for ArbTest<P>
where P: Sync,

§

impl<P> Unpin for ArbTest<P>
where P: Unpin,

§

impl<P> UnwindSafe for ArbTest<P>
where P: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.