rust/src/test/run-pass/lib-sort.rs

51 lines
747 B
Rust
Raw Normal View History

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