-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
19 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
pub mod quick_select; | ||
pub mod reuse_upper_bits; | ||
|
||
pub trait Solution { | ||
fn get_strongest(arr: Vec<i32>, k: i32) -> Vec<i32>; | ||
fn shuffle(nums: Vec<i32>, n: i32) -> Vec<i32>; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Solution; | ||
use crate::test_utilities; | ||
|
||
pub fn run<S: Solution>() { | ||
let test_cases = [ | ||
((&[1, 2, 3, 4, 5] as &[_], 2), &[1, 5] as &[_]), | ||
((&[1, 1, 3, 5, 5], 2), &[5, 5]), | ||
((&[6, 7, 11, 7, 6, 8], 5), &[6, 6, 7, 8, 11]), | ||
((&[513], 1), &[513]), | ||
((&[2, 5, 1, 3, 4, 7] as &[_], 3), &[2, 3, 5, 4, 1, 7] as &[_]), | ||
((&[1, 2, 3, 4, 4, 3, 2, 1], 4), &[1, 4, 2, 3, 3, 2, 4, 1]), | ||
((&[1, 1, 2, 2], 2), &[1, 2, 1, 2]), | ||
]; | ||
|
||
for ((arr, k), expected) in test_cases { | ||
assert_eq!( | ||
test_utilities::unstable_sorted(S::get_strongest(arr.to_vec(), k)), | ||
expected, | ||
); | ||
for ((nums, n), expected) in test_cases { | ||
assert_eq!(S::shuffle(nums.to_vec(), n), expected); | ||
} | ||
} | ||
} |
File renamed without changes.
19 changes: 12 additions & 7 deletions
19
src/problem_1471_the_k_strongest_values_in_an_array/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
pub mod reuse_upper_bits; | ||
pub mod quick_select; | ||
|
||
pub trait Solution { | ||
fn shuffle(nums: Vec<i32>, n: i32) -> Vec<i32>; | ||
fn get_strongest(arr: Vec<i32>, k: i32) -> Vec<i32>; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Solution; | ||
use crate::test_utilities; | ||
|
||
pub fn run<S: Solution>() { | ||
let test_cases = [ | ||
((&[2, 5, 1, 3, 4, 7] as &[_], 3), &[2, 3, 5, 4, 1, 7] as &[_]), | ||
((&[1, 2, 3, 4, 4, 3, 2, 1], 4), &[1, 4, 2, 3, 3, 2, 4, 1]), | ||
((&[1, 1, 2, 2], 2), &[1, 2, 1, 2]), | ||
((&[1, 2, 3, 4, 5] as &[_], 2), &[1, 5] as &[_]), | ||
((&[1, 1, 3, 5, 5], 2), &[5, 5]), | ||
((&[6, 7, 11, 7, 6, 8], 5), &[6, 6, 7, 8, 11]), | ||
((&[513], 1), &[513]), | ||
]; | ||
|
||
for ((nums, n), expected) in test_cases { | ||
assert_eq!(S::shuffle(nums.to_vec(), n), expected); | ||
for ((arr, k), expected) in test_cases { | ||
assert_eq!( | ||
test_utilities::unstable_sorted(S::get_strongest(arr.to_vec(), k)), | ||
expected, | ||
); | ||
} | ||
} | ||
} |
File renamed without changes.