pub fn quickcheck<A: Testable>(f: A)
Expand description
Convenience function for running QuickCheck.
This is an alias for QuickCheck::new().quickcheck(f)
.
Examples found in repository?
More examples
examples/out_of_bounds.rs (line 16)
5fn main() {
6 fn prop(length: usize, index: usize) -> TestResult {
7 let v: Vec<_> = (0..length).collect();
8 if index < length {
9 TestResult::discard()
10 } else {
11 TestResult::must_fail(move || {
12 v[index]
13 })
14 }
15 }
16 quickcheck(prop as fn(usize, usize) -> TestResult);
17}
examples/sieve.rs (line 38)
29fn main() {
30 fn prop_all_prime(n: usize) -> bool {
31 sieve(n).into_iter().all(is_prime)
32 }
33
34 fn prop_prime_iff_in_the_sieve(n: usize) -> bool {
35 sieve(n) == (0..(n + 1)).filter(|&i| is_prime(i)).collect::<Vec<_>>()
36 }
37
38 quickcheck(prop_all_prime as fn(usize) -> bool);
39 quickcheck(prop_prime_iff_in_the_sieve as fn(usize) -> bool);
40}
examples/sort.rs (line 45)
32fn main() {
33 fn is_sorted(xs: Vec<isize>) -> bool {
34 for win in xs.windows(2) {
35 if win[0] > win[1] {
36 return false
37 }
38 }
39 true
40 }
41
42 fn keeps_length(xs: Vec<isize>) -> bool {
43 xs.len() == sort(&*xs).len()
44 }
45 quickcheck(keeps_length as fn(Vec<isize>) -> bool);
46
47 quickcheck(is_sorted as fn(Vec<isize>) -> bool)
48}