Skip to content

Commit

Permalink
Add generic_test for k_smallest_by
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Feb 27, 2024
1 parent 3346213 commit 7af0cac
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,17 @@ where
it::assert_equal(i.k_smallest(k), j.sorted().take(k))
}

// Similar to `k_smallest_sort` but for our custom heap implementation.
fn k_smallest_by_sort<I>(i: I, k: u16)
where
I: Iterator + Clone,
I::Item: Ord + Debug,
{
let j = i.clone();
let k = k as usize;
it::assert_equal(i.k_smallest_by(k, Ord::cmp), j.sorted().take(k))
}

macro_rules! generic_test {
($f:ident, $($t:ty),+) => {
$(paste::item! {
Expand All @@ -588,6 +599,7 @@ macro_rules! generic_test {
}

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

#[test]
fn sorted_by_key() {
Expand Down

0 comments on commit 7af0cac

Please sign in to comment.