Skip to content

Commit c94846f

Browse files
committed
Added test for sorted_unstable
Added test for `sorted_unstable_by` Added test for `sorted_unstable_by_key`
1 parent 2276be9 commit c94846f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_std.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,26 @@ fn join() {
343343
assert_eq!(none.iter().join(", "), "");
344344
}
345345

346+
#[test]
347+
fn sorted_unstable_by() {
348+
let sc = [3, 4, 1, 2].iter().cloned().sorted_by(|&a, &b| {
349+
a.cmp(&b)
350+
});
351+
it::assert_equal(sc, vec![1, 2, 3, 4]);
352+
353+
let v = (0..5).sorted_unstable_by(|&a, &b| a.cmp(&b).reverse());
354+
it::assert_equal(v, vec![4, 3, 2, 1, 0]);
355+
}
356+
357+
#[test]
358+
fn sorted_unstable_by_key() {
359+
let sc = [3, 4, 1, 2].iter().cloned().sorted_unstable_by_key(|&x| x);
360+
it::assert_equal(sc, vec![1, 2, 3, 4]);
361+
362+
let v = (0..5).sorted_unstable_by_key(|&x| -x);
363+
it::assert_equal(v, vec![4, 3, 2, 1, 0]);
364+
}
365+
346366
#[test]
347367
fn sorted_by() {
348368
let sc = [3, 4, 1, 2].iter().cloned().sorted_by(|&a, &b| {

0 commit comments

Comments
 (0)