Test that merge sort is stable -- thanks to Jesse Jones

Closes #3399
This commit is contained in:
Tim Chevalier 2012-09-06 12:11:48 -07:00
parent b4e547d71a
commit 55bd6cee2f
1 changed files with 22 additions and 0 deletions

View File

@ -307,6 +307,28 @@ mod tests {
let v2 = merge_sort(le, v1);
assert v2 == ~[1, 2, 3];
}
#[test]
fn test_merge_sort_stability()
{
// tjc: funny that we have to use parens
pure fn ile(x: &(&static/str), y: &(&static/str)) -> bool
{
unchecked // to_lower is not pure...
{
let x = x.to_lower();
let y = y.to_lower();
x <= y
}
}
let names1 = ~["joe bob", "Joe Bob", "Jack Brown", "JOE Bob",
"Sally Mae", "JOE BOB", "Alex Andy"];
let names2 = ~["Alex Andy", "Jack Brown", "joe bob", "Joe Bob",
"JOE Bob", "JOE BOB", "Sally Mae"];
let names3 = merge_sort(ile, names1);
assert names3 == names2;
}
}
// Local Variables: