Skip to content

Commit 7af0cac

Browse files
Add generic_test for k_smallest_by
1 parent 3346213 commit 7af0cac

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/test_std.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,17 @@ where
575575
it::assert_equal(i.k_smallest(k), j.sorted().take(k))
576576
}
577577

578+
// Similar to `k_smallest_sort` but for our custom heap implementation.
579+
fn k_smallest_by_sort<I>(i: I, k: u16)
580+
where
581+
I: Iterator + Clone,
582+
I::Item: Ord + Debug,
583+
{
584+
let j = i.clone();
585+
let k = k as usize;
586+
it::assert_equal(i.k_smallest_by(k, Ord::cmp), j.sorted().take(k))
587+
}
588+
578589
macro_rules! generic_test {
579590
($f:ident, $($t:ty),+) => {
580591
$(paste::item! {
@@ -588,6 +599,7 @@ macro_rules! generic_test {
588599
}
589600

590601
generic_test!(k_smallest_sort, u8, u16, u32, u64, i8, i16, i32, i64);
602+
generic_test!(k_smallest_by_sort, u8, u16, u32, u64, i8, i16, i32, i64);
591603

592604
#[test]
593605
fn sorted_by_key() {

0 commit comments

Comments
 (0)