Struct QuickCheck

Source
pub struct QuickCheck<G> {
    pub tests: usize,
    pub max_tests: usize,
    pub gen: G,
}
Expand description

The main QuickCheck type for setting configuration and running QuickCheck.

Fields§

§tests: usize§max_tests: usize§gen: G

Implementations§

Source§

impl QuickCheck<StdGen<ThreadRng>>

Source

pub fn new() -> QuickCheck<StdGen<ThreadRng>>

Creates a new QuickCheck value.

This can be used to run QuickCheck 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 set to a StdGen with a default size of 100.

Source§

impl<G: Gen> QuickCheck<G>

Source

pub fn tests(self, tests: usize) -> QuickCheck<G>

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: usize) -> QuickCheck<G>

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 QuickCheck properties can discard tests.

Source

pub fn gen(self, gen: G) -> QuickCheck<G>

Set the random number generator to be used by QuickCheck.

Source

pub fn quicktest<A>(&mut self, f: A) -> Result<usize, TestResult>
where A: Testable,

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 quickcheck method, which will panic! on failure.)

Source

pub fn quickcheck<A>(&mut self, f: A)
where A: Testable,

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 quickcheck crate, then this will include output on how many QuickCheck tests were passed.

§Example
use quickcheck::QuickCheck;

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
    }
    QuickCheck::new().quickcheck(revrev as fn(Vec<usize>) -> bool);
}

Auto Trait Implementations§

§

impl<G> Freeze for QuickCheck<G>
where G: Freeze,

§

impl<G> RefUnwindSafe for QuickCheck<G>
where G: RefUnwindSafe,

§

impl<G> Send for QuickCheck<G>
where G: Send,

§

impl<G> Sync for QuickCheck<G>
where G: Sync,

§

impl<G> Unpin for QuickCheck<G>
where G: Unpin,

§

impl<G> UnwindSafe for QuickCheck<G>
where G: 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>,

Source§

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>,

Source§

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.