rust/src/test/stdtest/sort.rs
Brian Anderson 518dc52f85 Reformat
This changes the indexing syntax from .() to [], the vector syntax from ~[] to
[] and the extension syntax from #fmt() to #fmt[]
2011-08-20 11:04:00 -07:00

29 lines
747 B
Rust

use std;
fn check_sort(v1: &[int], v2: &[int]) {
let len = std::vec::len::<int>(v1);
fn lteq(a: &int, b: &int) -> bool { ret a <= b; }
let f = lteq;
let v3 = std::sort::merge_sort::<int>(f, v1);
let i = 0u;
while i < len { log v3[i]; assert (v3[i] == v2[i]); i += 1u; }
}
#[test]
fn test() {
{
let v1 = [3, 7, 4, 5, 2, 9, 5, 8];
let v2 = [2, 3, 4, 5, 5, 7, 8, 9];
check_sort(v1, v2);
}
{ let v1 = [1, 1, 1]; let v2 = [1, 1, 1]; check_sort(v1, v2); }
{ let v1: [int] = []; let v2: [int] = []; check_sort(v1, v2); }
{ let v1 = [9]; let v2 = [9]; check_sort(v1, v2); }
{
let v1 = [9, 3, 3, 3, 9];
let v2 = [3, 3, 3, 9, 9];
check_sort(v1, v2);
}
}