Skip to content

Commit 01bfcc0

Browse files
committed
Add test cases
Signed-off-by: tison <[email protected]>
1 parent bbca3c0 commit 01bfcc0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎library/alloctests/tests/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#![feature(binary_heap_into_iter_sorted)]
2121
#![feature(binary_heap_drain_sorted)]
2222
#![feature(slice_ptr_get)]
23+
#![feature(slice_range)]
24+
#![feature(slice_partial_sort_unstable)]
2325
#![feature(inplace_iteration)]
2426
#![feature(iter_advance_by)]
2527
#![feature(iter_next_chunk)]
@@ -66,6 +68,7 @@ mod heap;
6668
mod linked_list;
6769
mod misc_tests;
6870
mod num;
71+
mod partial_sort;
6972
mod rc;
7073
mod slice;
7174
mod sort;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::fmt::Debug;
2+
use std::ops::{Range, RangeBounds};
3+
use std::slice;
4+
5+
fn check_is_partial_sorted<T: Ord + Clone + Debug, R: RangeBounds<usize>>(v: &mut [T], range: R) {
6+
let Range { start, end } = slice::range(range, ..v.len());
7+
v.partial_sort_unstable(start..end);
8+
9+
let max_before = v[..start].iter().max().into_iter();
10+
let sorted_range = v[start..end].into_iter();
11+
let min_after = v[end..].iter().min().into_iter();
12+
let seq = max_before.chain(sorted_range).chain(min_after);
13+
assert!(seq.is_sorted());
14+
}
15+
16+
#[test]
17+
fn basic_impl() {
18+
check_is_partial_sorted::<i32, _>(&mut [], ..);
19+
check_is_partial_sorted::<(), _>(&mut [], ..);
20+
check_is_partial_sorted::<(), _>(&mut [()], ..);
21+
check_is_partial_sorted::<(), _>(&mut [(), ()], ..);
22+
check_is_partial_sorted::<(), _>(&mut [(), (), ()], ..);
23+
check_is_partial_sorted::<i32, _>(&mut [], ..);
24+
25+
check_is_partial_sorted::<i32, _>(&mut [77], ..);
26+
check_is_partial_sorted::<i32, _>(&mut [2, 3], ..);
27+
check_is_partial_sorted::<i32, _>(&mut [2, 3, 6], ..);
28+
check_is_partial_sorted::<i32, _>(&mut [2, 3, 99, 6], ..);
29+
check_is_partial_sorted::<i32, _>(&mut [2, 7709, 400, 90932], ..);
30+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], ..);
31+
32+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 0..0);
33+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 0..1);
34+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 0..5);
35+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 0..7);
36+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 7..7);
37+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 6..7);
38+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 5..7);
39+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 5..5);
40+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 4..5);
41+
check_is_partial_sorted::<i32, _>(&mut [15, -1, 3, -1, -3, -1, 7], 4..6);
42+
}

0 commit comments

Comments
 (0)