Skip to content

Commit

Permalink
Fix problem names
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Nov 2, 2024
1 parent a0dfcb1 commit 7bb2786
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
19 changes: 7 additions & 12 deletions src/problem_1470_shuffle_the_array/mod.rs
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);
}
}
}
19 changes: 12 additions & 7 deletions src/problem_1471_the_k_strongest_values_in_an_array/mod.rs
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,
);
}
}
}

0 comments on commit 7bb2786

Please sign in to comment.