quickcheck

Function quickcheck

Source
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?
examples/btree_set_range.rs (line 54)
53
54
55
fn main() {
    quickcheck(check_range as fn(_, _) -> TestResult);
}
More examples
Hide additional examples
examples/reverse.rs (line 15)
11
12
13
14
15
16
fn main() {
    fn equality_after_applying_twice(xs: Vec<isize>) -> bool {
        xs == reverse(&reverse(&xs))
    }
    quickcheck(equality_after_applying_twice as fn(Vec<isize>) -> bool);
}
examples/reverse_single.rs (line 18)
11
12
13
14
15
16
17
18
19
fn main() {
    fn prop(xs: Vec<isize>) -> TestResult {
        if xs.len() != 1 {
            return TestResult::discard();
        }
        TestResult::from_bool(xs == reverse(&*xs))
    }
    quickcheck(prop as fn(Vec<isize>) -> TestResult);
}
examples/out_of_bounds.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    fn prop(length: usize, index: usize) -> TestResult {
        let v: Vec<_> = (0..length).collect();
        if index < length {
            TestResult::discard()
        } else {
            TestResult::must_fail(move || v[index])
        }
    }
    quickcheck(prop as fn(usize, usize) -> TestResult);
}
examples/sieve.rs (line 37)
28
29
30
31
32
33
34
35
36
37
38
39
fn main() {
    fn prop_all_prime(n: usize) -> bool {
        sieve(n).into_iter().all(is_prime)
    }

    fn prop_prime_iff_in_the_sieve(n: usize) -> bool {
        sieve(n) == (0..(n + 1)).filter(|&i| is_prime(i)).collect::<Vec<_>>()
    }

    quickcheck(prop_all_prime as fn(usize) -> bool);
    quickcheck(prop_prime_iff_in_the_sieve as fn(usize) -> bool);
}
examples/sort.rs (line 43)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fn main() {
    fn is_sorted(xs: Vec<isize>) -> bool {
        for win in xs.windows(2) {
            if win[0] > win[1] {
                return false;
            }
        }
        true
    }

    fn keeps_length(xs: Vec<isize>) -> bool {
        xs.len() == sort(&*xs).len()
    }
    quickcheck(keeps_length as fn(Vec<isize>) -> bool);

    quickcheck(is_sorted as fn(Vec<isize>) -> bool)
}