// This is a buggy quick sort implementation, QuickCheck will find the bug for // you. extern crate quickcheck; use quickcheck::quickcheck; fn smaller_than(xs: &[T], pivot: &T) -> Vec { return xs.iter().filter(|&x| *x < *pivot).map(|x| x.clone()).collect(); } fn larger_than(xs: &[T], pivot: &T) -> Vec { return xs.iter().filter(|&x| *x > *pivot).map(|x| x.clone()).collect(); } fn sortk(x: &T, xs: &[T]) -> Vec { let mut result : Vec = sort(&*smaller_than(xs, x)); let last_part = sort(&*larger_than(xs, x)); result.push(x.clone()); result.extend(last_part.iter().map(|x| x.clone())); result } fn sort(list: &[T]) -> Vec { if list.is_empty() { vec![] } else { sortk(&list[0], &list[1..]) } } fn main() { fn is_sorted(xs: Vec) -> bool { for win in xs.windows(2) { if win[0] > win[1] { return false } } true } fn keeps_length(xs: Vec) -> bool { xs.len() == sort(&*xs).len() } quickcheck(keeps_length as fn(Vec) -> bool); quickcheck(is_sorted as fn(Vec) -> bool) }