pub struct SampleTest { /* private fields */ }
Expand description

The main SampleTest type for setting configuration and running sample-based testing.

Implementations§

source§

impl SampleTest

source

pub fn new() -> SampleTest

Creates a new SampleTest value.

This can be used to run SampleTest on things that implement Testable. You may also adjust the configuration, such as the number of tests to run.

By default, the maximum number of passed tests is set to 100, the max number of overall tests is set to 10000 and the generator is created with a size of 100.

source

pub fn tests(self, tests: u64) -> SampleTest

Set the number of tests to run.

This actually refers to the maximum number of passed tests that can occur. Namely, if a test causes a failure, future testing on that property stops. Additionally, if tests are discarded, there may be fewer than tests passed.

source

pub fn max_tests(self, max_tests: u64) -> SampleTest

Set the maximum number of tests to run.

The number of invocations of a property will never exceed this number. This is necessary to cap the number of tests because SampleTest properties can discard tests.

source

pub fn min_tests_passed(self, min_tests_passed: u64) -> SampleTest

Set the minimum number of tests that needs to pass.

This actually refers to the minimum number of valid passed tests that needs to pass for the property to be considered successful.

source

pub fn sample_test_count<S, A>(&mut self, s: S, f: A) -> Result<u64, TestResult>
where A: Testable<S>, S: Sample, S::Output: Clone + Debug,

Tests a property and returns the result.

The result returned is either the number of tests passed or a witness of failure.

(If you’re using Rust’s unit testing infrastructure, then you’ll want to use the sample_test method, which will panic! on failure.)

source

pub fn sample_test<S, A>(&mut self, s: S, f: A)
where A: Testable<S>, S: Sample, S::Output: Clone + Debug,

Tests a property and calls panic! on failure.

The panic! message will include a (hopefully) minimal witness of failure.

It is appropriate to use this method with Rust’s unit testing infrastructure.

Note that if the environment variable RUST_LOG is set to enable info level log messages for the sample_test crate, then this will include output on how many SampleTest tests were passed.

§Example
use sample_test::{SampleTest};
use sample_std::VecSampler;

fn prop_reverse_reverse() {
    fn revrev(xs: Vec<usize>) -> bool {
        let rev: Vec<_> = xs.clone().into_iter().rev().collect();
        let revrev: Vec<_> = rev.into_iter().rev().collect();
        xs == revrev
    }
    let sampler = (VecSampler { length: (0..20), el: (0..100usize) },);
    SampleTest::new().sample_test(sampler, revrev as fn(Vec<usize>) -> bool);
}

Auto Trait Implementations§

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.