Skip to content

Commit 55bd6ce

Browse files
committed
Test that merge sort is stable -- thanks to Jesse Jones
Closes #3399
1 parent b4e547d commit 55bd6ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libstd/sort.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,28 @@ mod tests {
307307
let v2 = merge_sort(le, v1);
308308
assert v2 == ~[1, 2, 3];
309309
}
310+
311+
#[test]
312+
fn test_merge_sort_stability()
313+
{
314+
// tjc: funny that we have to use parens
315+
pure fn ile(x: &(&static/str), y: &(&static/str)) -> bool
316+
{
317+
unchecked // to_lower is not pure...
318+
{
319+
let x = x.to_lower();
320+
let y = y.to_lower();
321+
x <= y
322+
}
323+
}
324+
325+
let names1 = ~["joe bob", "Joe Bob", "Jack Brown", "JOE Bob",
326+
"Sally Mae", "JOE BOB", "Alex Andy"];
327+
let names2 = ~["Alex Andy", "Jack Brown", "joe bob", "Joe Bob",
328+
"JOE Bob", "JOE BOB", "Sally Mae"];
329+
let names3 = merge_sort(ile, names1);
330+
assert names3 == names2;
331+
}
310332
}
311333

312334
// Local Variables:

0 commit comments

Comments
 (0)