pub struct QuickCheck {/* private fields */ }Expand description
The main QuickCheck type for setting configuration and running QuickCheck.
Implementations§
Source§implQuickCheck
implQuickCheck
Sourcepub fnnew() ->QuickCheck
pub fnnew() ->QuickCheck
Creates a new QuickCheck value.
This can be used to run QuickCheck on things that implementTestable.You may also adjust the configuration, such as the number of tests torun.
By default, the maximum number of passed tests is set to100, the maxnumber of overall tests is set to10000 and the generator is createdwith a size of100.
Sourcepub fngen(self, gen:Gen) ->QuickCheck
pub fngen(self, gen:Gen) ->QuickCheck
Set the random number generator to be used by QuickCheck.
Sourcepub fntests(self, tests:u64) ->QuickCheck
pub fntests(self, tests:u64) ->QuickCheck
Set the number of tests to run.
This actually refers to the maximum number ofpassed tests thatcan occur. Namely, if a test causes a failure, future testing on thatproperty stops. Additionally, if tests are discarded, there may befewer thantests passed.
Sourcepub fnmax_tests(self, max_tests:u64) ->QuickCheck
pub fnmax_tests(self, max_tests:u64) ->QuickCheck
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 QuickCheckproperties can discard tests.
Sourcepub fnmin_tests_passed(self, min_tests_passed:u64) ->QuickCheck
pub fnmin_tests_passed(self, min_tests_passed:u64) ->QuickCheck
Set the minimum number of tests that needs to pass.
This actually refers to the minimum number ofvalidpassed teststhat needs to pass for the property to be considered successful.
Sourcepub fnquicktest<A>(&mut self, f: A) ->Result<u64,TestResult>where A:Testable,
pub fnquicktest<A>(&mut self, f: A) ->Result<u64,TestResult>where A:Testable,
Tests a property and returns the result.
The result returned is either the number of tests passed or a witnessof failure.
(If you’re using Rust’s unit testing infrastructure, then you’llwant to use thequickcheck method, which willpanic! on failure.)
Sourcepub fnquickcheck<A>(&mut self, f: A)where A:Testable,
pub fnquickcheck<A>(&mut self, f: A)where A:Testable,
Tests a property and callspanic! on failure.
Thepanic! message will include a (hopefully) minimal witness offailure.
It is appropriate to use this method with Rust’s unit testinginfrastructure.
Note that if the environment variableRUST_LOG is set to enableinfo level log messages for thequickcheck crate, then this willinclude output on how many QuickCheck tests were passed.
§Example
usequickcheck::QuickCheck;fnprop_reverse_reverse() {fnrevrev(xs: Vec<usize>) -> bool {letrev: Vec<_> = xs.clone().into_iter().rev().collect();letrevrev: Vec<_> = rev.into_iter().rev().collect(); xs == revrev } QuickCheck::new().quickcheck(revrevas fn(Vec<usize>) -> bool);}