From c3566eb117653593b77f2440a6b7a05d6a7a6c1e Mon Sep 17 00:00:00 2001 From: EFanZh Date: Sat, 7 Sep 2024 10:40:14 +0800 Subject: [PATCH] Fix Clippy warnings --- .../backtracking_1.rs | 2 +- .../backtracking_2.rs | 2 +- src/problem_0048_rotate_image/naive.rs | 2 +- .../reverse_then_transpose.rs | 2 +- .../newtons_method_with_f32.rs | 2 +- .../two_passes.rs | 1 - .../two_passes_2.rs | 2 +- src/problem_0075_sort_colors/counting_sort.rs | 1 - .../iterative.rs | 2 +- .../recursive.rs | 2 +- .../iterative.rs | 2 +- .../partial_iterative.rs | 2 +- .../iterative.rs | 2 +- src/problem_0130_surrounded_regions/bfs_2.rs | 1 - .../memoized_recursive.rs | 2 +- .../iterative.rs | 2 +- .../partial_iterative.rs | 2 +- .../iterative.rs | 2 +- .../iterative_2.rs | 2 +- .../iterative.rs | 4 +- .../mod.rs | 2 +- src/problem_0189_rotate_array/cheating.rs | 2 +- .../cyclic_replacements.rs | 2 +- .../triple_reverses.rs | 2 +- .../divide_and_conquer.rs | 2 +- src/problem_0191_number_of_1_bits/cheating.rs | 2 +- .../iterative.rs | 2 +- .../iterative_2.rs | 2 +- .../recursive.rs | 2 +- src/problem_0223_rectangle_area/mod.rs | 2 +- src/problem_0223_rectangle_area/normalize.rs | 4 +- .../iterative.rs | 2 +- .../binary_search.rs | 1 - src/problem_0278_first_bad_version/mod.rs | 2 +- src/problem_0283_move_zeroes/iterative.rs | 2 +- .../level_order_traversal.rs | 4 +- .../preorder_traversal.rs | 4 +- .../find_median.rs | 2 +- src/problem_0344_reverse_string/cheating.rs | 2 +- src/problem_0344_reverse_string/indices.rs | 2 +- src/problem_0344_reverse_string/iterator.rs | 2 +- .../mod.rs | 1176 ++++++++--------- .../binary_heap.rs | 8 +- .../binary_heap_2.rs | 8 +- src/problem_0355_design_twitter/mod.rs | 2 +- .../binary_search.rs | 2 +- .../mod.rs | 2 +- .../mod.rs | 273 ++-- .../iterative.rs | 2 +- .../preorder_traversal.rs | 4 +- .../iterative.rs | 3 +- .../hash_map.rs | 2 +- .../bfs.rs | 2 +- .../cached_hash_values.rs | 2 +- src/problem_0682_baseball_game/stack.rs | 2 +- .../recursive_descent.rs | 4 +- .../recursive.rs | 4 +- src/problem_0855_exam_room/mod.rs | 147 ++- .../brute_force.rs | 2 +- src/problem_0912_sort_an_array/cheating.rs | 2 +- .../queue.rs | 2 +- .../mod.rs | 218 +-- .../mod.rs | 1 - .../iterative.rs | 2 +- src/problem_1048_longest_string_chain/dfs.rs | 2 +- .../recursive.rs | 2 +- .../count_zeros.rs | 2 +- .../iterative.rs | 2 +- .../parse_and_expand.rs | 1 - .../mod.rs | 185 +-- src/problem_1172_dinner_plate_stacks/mod.rs | 145 +- .../iterative.rs | 2 +- .../iterative.rs | 2 +- .../mod.rs | 243 ++-- .../dfs.rs | 2 +- .../iterator.rs | 7 +- .../mod.rs | 212 +-- .../standard.rs | 2 +- .../state_machine.rs | 2 +- .../dynamic_programming.rs | 6 +- .../mod.rs | 207 +-- .../iterative.rs | 6 +- .../mod.rs | 426 +++--- .../quick_select.rs | 6 +- .../greedy.rs | 2 +- .../mathematical.rs | 5 +- .../mathematical.rs | 2 +- .../btree_map.rs | 4 +- .../iterative.rs | 2 +- .../newtons_method.rs | 2 +- .../newtons_method_2.rs | 2 +- src/problem_1993_operations_on_tree/mod.rs | 1 - .../modular_arithmetic.rs | 4 +- src/problem_2103_rings_and_rods/iterative.rs | 2 +- .../dense_storage.rs | 2 +- src/problem_2166_design_bitset/mod.rs | 2 +- .../mathematical.rs | 2 +- .../greedy.rs | 2 +- .../greedy_2.rs | 2 +- src/problem_2241_design_an_atm_machine/mod.rs | 2 +- tools/check-cpp-code-format/src/main.rs | 2 +- xtask/src/utilities.rs | 1 - 102 files changed, 1738 insertions(+), 1721 deletions(-) diff --git a/src/problem_0037_sudoku_solver/backtracking_1.rs b/src/problem_0037_sudoku_solver/backtracking_1.rs index d4a7e8657..97fa22eed 100644 --- a/src/problem_0037_sudoku_solver/backtracking_1.rs +++ b/src/problem_0037_sudoku_solver/backtracking_1.rs @@ -36,7 +36,7 @@ impl Solution { } } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn solve_sudoku(board: &mut Vec>) { Self::solve_sudoku_helper(board, 0).unwrap_err(); } diff --git a/src/problem_0037_sudoku_solver/backtracking_2.rs b/src/problem_0037_sudoku_solver/backtracking_2.rs index a48767429..f427ae95c 100644 --- a/src/problem_0037_sudoku_solver/backtracking_2.rs +++ b/src/problem_0037_sudoku_solver/backtracking_2.rs @@ -50,7 +50,7 @@ impl Solution { } } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn solve_sudoku(board: &mut Vec>) { let mut row_hits = [false; 81]; let mut column_hits = [false; 81]; diff --git a/src/problem_0048_rotate_image/naive.rs b/src/problem_0048_rotate_image/naive.rs index 104700df7..10c8e2b43 100644 --- a/src/problem_0048_rotate_image/naive.rs +++ b/src/problem_0048_rotate_image/naive.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn rotate(matrix: &mut Vec>) { let n = matrix.len(); diff --git a/src/problem_0048_rotate_image/reverse_then_transpose.rs b/src/problem_0048_rotate_image/reverse_then_transpose.rs index a040d4c72..60411d823 100644 --- a/src/problem_0048_rotate_image/reverse_then_transpose.rs +++ b/src/problem_0048_rotate_image/reverse_then_transpose.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn rotate(matrix: &mut Vec>) { let n = matrix.len(); diff --git a/src/problem_0069_sqrtx/newtons_method_with_f32.rs b/src/problem_0069_sqrtx/newtons_method_with_f32.rs index 8e2eb1da5..df0ac2cda 100644 --- a/src/problem_0069_sqrtx/newtons_method_with_f32.rs +++ b/src/problem_0069_sqrtx/newtons_method_with_f32.rs @@ -6,7 +6,7 @@ impl Solution { pub fn my_sqrt(x: i32) -> i32 { let x = x as u32; - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mut guess = f32::from_bits((x as f32).to_bits() / 2 + 0x1FC0_0000) as u32; if guess * guess > x { diff --git a/src/problem_0073_set_matrix_zeroes/two_passes.rs b/src/problem_0073_set_matrix_zeroes/two_passes.rs index 4f575ca4d..9a48905ee 100644 --- a/src/problem_0073_set_matrix_zeroes/two_passes.rs +++ b/src/problem_0073_set_matrix_zeroes/two_passes.rs @@ -3,7 +3,6 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. pub fn set_zeroes(matrix: &mut Vec>) { if let Some((first_row, rest_rows)) = matrix.split_first_mut() { if let Some((first_row_first_cell, first_row_rest_cells)) = first_row.split_first_mut() { diff --git a/src/problem_0073_set_matrix_zeroes/two_passes_2.rs b/src/problem_0073_set_matrix_zeroes/two_passes_2.rs index 5d142a00c..032a4815d 100644 --- a/src/problem_0073_set_matrix_zeroes/two_passes_2.rs +++ b/src/problem_0073_set_matrix_zeroes/two_passes_2.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn set_zeroes(matrix: &mut Vec>) { if let Some((first_row, rest_rows)) = matrix.split_first_mut() { let first_row_has_zero = first_row.iter().any(|x| *x == 0); diff --git a/src/problem_0075_sort_colors/counting_sort.rs b/src/problem_0075_sort_colors/counting_sort.rs index 2bbb69e1e..dac9e4aab 100644 --- a/src/problem_0075_sort_colors/counting_sort.rs +++ b/src/problem_0075_sort_colors/counting_sort.rs @@ -3,7 +3,6 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. pub fn sort_colors(nums: &mut Vec) { let mut counts = [0; 3]; diff --git a/src/problem_0088_merge_sorted_array/iterative.rs b/src/problem_0088_merge_sorted_array/iterative.rs index bb8e51cbc..9c4d44f6b 100644 --- a/src/problem_0088_merge_sorted_array/iterative.rs +++ b/src/problem_0088_merge_sorted_array/iterative.rs @@ -33,7 +33,7 @@ impl Solution { } } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { let mut m = m as usize; let n = n as usize; diff --git a/src/problem_0088_merge_sorted_array/recursive.rs b/src/problem_0088_merge_sorted_array/recursive.rs index 73fa3fad5..43d2e9229 100644 --- a/src/problem_0088_merge_sorted_array/recursive.rs +++ b/src/problem_0088_merge_sorted_array/recursive.rs @@ -34,7 +34,7 @@ impl Solution { } } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { let m = m as usize; let n = n as usize; diff --git a/src/problem_0094_binary_tree_inorder_traversal/iterative.rs b/src/problem_0094_binary_tree_inorder_traversal/iterative.rs index 1c264ffad..9d1086438 100644 --- a/src/problem_0094_binary_tree_inorder_traversal/iterative.rs +++ b/src/problem_0094_binary_tree_inorder_traversal/iterative.rs @@ -14,7 +14,7 @@ impl Solution { let mut stack = Vec::new(); loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { root = node.borrow().left.clone(); stack.push(node); diff --git a/src/problem_0094_binary_tree_inorder_traversal/partial_iterative.rs b/src/problem_0094_binary_tree_inorder_traversal/partial_iterative.rs index dc66f78a2..2f6afcafc 100644 --- a/src/problem_0094_binary_tree_inorder_traversal/partial_iterative.rs +++ b/src/problem_0094_binary_tree_inorder_traversal/partial_iterative.rs @@ -9,7 +9,7 @@ use std::rc::Rc; impl Solution { fn inorder_traversal_helper(mut root: Option>>, result: &mut Vec) { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] while let Some(node) = root { let node_ref = node.borrow(); diff --git a/src/problem_0104_maximum_depth_of_binary_tree/iterative.rs b/src/problem_0104_maximum_depth_of_binary_tree/iterative.rs index 86b18b061..4669f36f6 100644 --- a/src/problem_0104_maximum_depth_of_binary_tree/iterative.rs +++ b/src/problem_0104_maximum_depth_of_binary_tree/iterative.rs @@ -15,7 +15,7 @@ impl Solution { let mut root = root; loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { let node = node.borrow(); diff --git a/src/problem_0130_surrounded_regions/bfs_2.rs b/src/problem_0130_surrounded_regions/bfs_2.rs index b013ef4fe..5e484acd1 100644 --- a/src/problem_0130_surrounded_regions/bfs_2.rs +++ b/src/problem_0130_surrounded_regions/bfs_2.rs @@ -30,7 +30,6 @@ impl Solution { } } - #[allow(clippy::ptr_arg)] // Expected. pub fn solve(board: &mut Vec>) { let rows = board.len(); let columns = board.first().map_or(0, Vec::len); diff --git a/src/problem_0140_word_break_ii/memoized_recursive.rs b/src/problem_0140_word_break_ii/memoized_recursive.rs index fdb582e86..e75d951ff 100644 --- a/src/problem_0140_word_break_ii/memoized_recursive.rs +++ b/src/problem_0140_word_break_ii/memoized_recursive.rs @@ -12,7 +12,7 @@ struct Node { } impl Solution { - #[allow(clippy::option_if_let_else)] // False positive. + #[expect(clippy::option_if_let_else, reason = "false positive")] fn word_break_helper(s: &[u8], root: &Node, cache: &mut HashMap<*const u8, Rc<[String]>>) -> Rc<[String]> { Rc::clone(if let Some(result) = cache.get(&s.as_ptr()) { result diff --git a/src/problem_0144_binary_tree_preorder_traversal/iterative.rs b/src/problem_0144_binary_tree_preorder_traversal/iterative.rs index 346ff6d79..59b84ac3a 100644 --- a/src/problem_0144_binary_tree_preorder_traversal/iterative.rs +++ b/src/problem_0144_binary_tree_preorder_traversal/iterative.rs @@ -14,7 +14,7 @@ impl Solution { let mut root = root; loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { let node_ref = node.borrow(); diff --git a/src/problem_0144_binary_tree_preorder_traversal/partial_iterative.rs b/src/problem_0144_binary_tree_preorder_traversal/partial_iterative.rs index e708fb02d..0ac7eb576 100644 --- a/src/problem_0144_binary_tree_preorder_traversal/partial_iterative.rs +++ b/src/problem_0144_binary_tree_preorder_traversal/partial_iterative.rs @@ -9,7 +9,7 @@ use std::rc::Rc; impl Solution { fn preorder_traversal_helper(mut root: Option>>, result: &mut Vec) { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] while let Some(node) = root { let node_ref = node.borrow(); diff --git a/src/problem_0145_binary_tree_postorder_traversal/iterative.rs b/src/problem_0145_binary_tree_postorder_traversal/iterative.rs index adc8f7dd7..99817b2ec 100644 --- a/src/problem_0145_binary_tree_postorder_traversal/iterative.rs +++ b/src/problem_0145_binary_tree_postorder_traversal/iterative.rs @@ -19,7 +19,7 @@ impl Solution { let mut root = root; 'r: loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { root = node.borrow().left.clone(); diff --git a/src/problem_0145_binary_tree_postorder_traversal/iterative_2.rs b/src/problem_0145_binary_tree_postorder_traversal/iterative_2.rs index 70ec7b4c1..f80564713 100644 --- a/src/problem_0145_binary_tree_postorder_traversal/iterative_2.rs +++ b/src/problem_0145_binary_tree_postorder_traversal/iterative_2.rs @@ -16,7 +16,7 @@ impl Solution { let mut root = root; 'r: loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { root = node.borrow().left.clone(); diff --git a/src/problem_0173_binary_search_tree_iterator/iterative.rs b/src/problem_0173_binary_search_tree_iterator/iterative.rs index 54f7021f8..a389fcfe4 100644 --- a/src/problem_0173_binary_search_tree_iterator/iterative.rs +++ b/src/problem_0173_binary_search_tree_iterator/iterative.rs @@ -13,7 +13,7 @@ impl BSTIterator { fn new(mut root: Option>>) -> Self { let mut stack = Vec::new(); - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] while let Some(node) = root { root = node.borrow().left.clone(); @@ -28,7 +28,7 @@ impl BSTIterator { let node_ref = node.borrow(); let mut root = node_ref.right.clone(); - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] while let Some(node) = root { root = node.borrow().left.clone(); diff --git a/src/problem_0173_binary_search_tree_iterator/mod.rs b/src/problem_0173_binary_search_tree_iterator/mod.rs index 421f0c61f..db3e0ef3d 100644 --- a/src/problem_0173_binary_search_tree_iterator/mod.rs +++ b/src/problem_0173_binary_search_tree_iterator/mod.rs @@ -15,7 +15,7 @@ mod tests { use super::BSTIterator; use crate::test_utilities; - #[allow(variant_size_differences)] + #[expect(variant_size_differences, reason = "optimal")] enum Operation { Next(i32), HasNext(bool), diff --git a/src/problem_0189_rotate_array/cheating.rs b/src/problem_0189_rotate_array/cheating.rs index 1a6da88eb..197893bcf 100644 --- a/src/problem_0189_rotate_array/cheating.rs +++ b/src/problem_0189_rotate_array/cheating.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn rotate(nums: &mut Vec, k: i32) { let k = k as usize; let length = nums.len(); diff --git a/src/problem_0189_rotate_array/cyclic_replacements.rs b/src/problem_0189_rotate_array/cyclic_replacements.rs index 6d981af87..06ec69fa8 100644 --- a/src/problem_0189_rotate_array/cyclic_replacements.rs +++ b/src/problem_0189_rotate_array/cyclic_replacements.rs @@ -16,7 +16,7 @@ impl Solution { x } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn rotate(nums: &mut Vec, k: i32) { let length = nums.len(); let k = (k as usize) % length; diff --git a/src/problem_0189_rotate_array/triple_reverses.rs b/src/problem_0189_rotate_array/triple_reverses.rs index f403fd692..aae3dbd18 100644 --- a/src/problem_0189_rotate_array/triple_reverses.rs +++ b/src/problem_0189_rotate_array/triple_reverses.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn rotate(nums: &mut Vec, k: i32) { let length = nums.len(); let k = (k as usize) % length; diff --git a/src/problem_0190_reverse_bits/divide_and_conquer.rs b/src/problem_0190_reverse_bits/divide_and_conquer.rs index 3d02a290d..a541f1ffd 100644 --- a/src/problem_0190_reverse_bits/divide_and_conquer.rs +++ b/src/problem_0190_reverse_bits/divide_and_conquer.rs @@ -6,7 +6,7 @@ impl Solution { pub fn reverse_bits(n: u32) -> u32 { let mut n = n; - n = (n >> 16) | (n << 16); + n = n.rotate_left(16); n = ((n & 0xff00_ff00) >> 8) | ((n & 0x00ff_00ff) << 8); n = ((n & 0xf0f0_f0f0) >> 4) | ((n & 0x0f0f_0f0f) << 4); n = ((n & 0xcccc_cccc) >> 2) | ((n & 0x3333_3333) << 2); diff --git a/src/problem_0191_number_of_1_bits/cheating.rs b/src/problem_0191_number_of_1_bits/cheating.rs index 48533be96..d42c8fd79 100644 --- a/src/problem_0191_number_of_1_bits/cheating.rs +++ b/src/problem_0191_number_of_1_bits/cheating.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(non_snake_case)] // Expected. + #[expect(non_snake_case, reason = "required")] pub fn hammingWeight(n: u32) -> i32 { n.count_ones() as _ } diff --git a/src/problem_0191_number_of_1_bits/iterative.rs b/src/problem_0191_number_of_1_bits/iterative.rs index a00f316dc..a1baaeb4c 100644 --- a/src/problem_0191_number_of_1_bits/iterative.rs +++ b/src/problem_0191_number_of_1_bits/iterative.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(non_snake_case)] // Expected. + #[expect(non_snake_case, reason = "required")] pub fn hammingWeight(n: u32) -> i32 { let mut result = 0; let mut n = n; diff --git a/src/problem_0191_number_of_1_bits/iterative_2.rs b/src/problem_0191_number_of_1_bits/iterative_2.rs index 06d4629a1..5e3338ca5 100644 --- a/src/problem_0191_number_of_1_bits/iterative_2.rs +++ b/src/problem_0191_number_of_1_bits/iterative_2.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(non_snake_case)] // Expected. + #[expect(non_snake_case, reason = "required")] pub fn hammingWeight(n: u32) -> i32 { let mut result = 0; let mut n = n; diff --git a/src/problem_0222_count_complete_tree_nodes/recursive.rs b/src/problem_0222_count_complete_tree_nodes/recursive.rs index 3ff70fe76..6978ed468 100644 --- a/src/problem_0222_count_complete_tree_nodes/recursive.rs +++ b/src/problem_0222_count_complete_tree_nodes/recursive.rs @@ -11,7 +11,7 @@ impl Solution { fn get_left_height(mut root: Option>>) -> i32 { let mut result = 0; - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] while let Some(node) = root { result += 1; diff --git a/src/problem_0223_rectangle_area/mod.rs b/src/problem_0223_rectangle_area/mod.rs index 276cd79c3..0715f4d9e 100644 --- a/src/problem_0223_rectangle_area/mod.rs +++ b/src/problem_0223_rectangle_area/mod.rs @@ -1,7 +1,7 @@ pub mod normalize; pub trait Solution { - #[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected. + #[expect(clippy::too_many_arguments, reason = "required")] fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32; } diff --git a/src/problem_0223_rectangle_area/normalize.rs b/src/problem_0223_rectangle_area/normalize.rs index 8fe30bde9..fcb024887 100644 --- a/src/problem_0223_rectangle_area/normalize.rs +++ b/src/problem_0223_rectangle_area/normalize.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected. + #[expect(clippy::many_single_char_names, clippy::too_many_arguments, reason = "required")] pub fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32 { let left = a.max(e); let right = c.min(g); @@ -26,7 +26,7 @@ impl Solution { // ------------------------------------------------------ snip ------------------------------------------------------ // impl super::Solution for Solution { - #[allow(clippy::many_single_char_names, clippy::too_many_arguments)] // Expected. + #[expect(clippy::many_single_char_names, reason = "required")] fn compute_area(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) -> i32 { Self::compute_area(a, b, c, d, e, f, g, h) } diff --git a/src/problem_0230_kth_smallest_element_in_a_bst/iterative.rs b/src/problem_0230_kth_smallest_element_in_a_bst/iterative.rs index c6b4770cf..1abc2f221 100644 --- a/src/problem_0230_kth_smallest_element_in_a_bst/iterative.rs +++ b/src/problem_0230_kth_smallest_element_in_a_bst/iterative.rs @@ -14,7 +14,7 @@ impl Solution { let mut k = k; loop { - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node) = root { root = node.borrow().left.clone(); stack.push(node); diff --git a/src/problem_0278_first_bad_version/binary_search.rs b/src/problem_0278_first_bad_version/binary_search.rs index 90d519fbb..f6a385ea1 100644 --- a/src/problem_0278_first_bad_version/binary_search.rs +++ b/src/problem_0278_first_bad_version/binary_search.rs @@ -34,7 +34,6 @@ impl super::Solution for Solution { Self { bad } } - #[allow(non_snake_case)] // Expected. fn isBadVersion(&self, version: i32) -> bool { version >= self.bad } diff --git a/src/problem_0278_first_bad_version/mod.rs b/src/problem_0278_first_bad_version/mod.rs index 9602b2c3a..96d4aa941 100644 --- a/src/problem_0278_first_bad_version/mod.rs +++ b/src/problem_0278_first_bad_version/mod.rs @@ -3,7 +3,7 @@ pub mod binary_search; pub trait Solution { fn new(bad: i32) -> Self; - #[allow(non_snake_case)] // Expected. + #[expect(non_snake_case, reason = "required")] fn isBadVersion(&self, version: i32) -> bool; fn first_bad_version(&self, n: i32) -> i32; diff --git a/src/problem_0283_move_zeroes/iterative.rs b/src/problem_0283_move_zeroes/iterative.rs index 92ef89175..c68c26bf3 100644 --- a/src/problem_0283_move_zeroes/iterative.rs +++ b/src/problem_0283_move_zeroes/iterative.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn move_zeroes(nums: &mut Vec) { let mut i = 0; let mut tail; diff --git a/src/problem_0297_serialize_and_deserialize_binary_tree/level_order_traversal.rs b/src/problem_0297_serialize_and_deserialize_binary_tree/level_order_traversal.rs index b955157ca..465b5741b 100644 --- a/src/problem_0297_serialize_and_deserialize_binary_tree/level_order_traversal.rs +++ b/src/problem_0297_serialize_and_deserialize_binary_tree/level_order_traversal.rs @@ -13,7 +13,7 @@ impl Codec { Self } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn serialize(&self, root: Option>>) -> String { use std::fmt::Write; @@ -58,7 +58,7 @@ impl Codec { result } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn deserialize(&self, data: String) -> Option>> { let mut iter = data[1..data.len() - 1].split_terminator(','); diff --git a/src/problem_0297_serialize_and_deserialize_binary_tree/preorder_traversal.rs b/src/problem_0297_serialize_and_deserialize_binary_tree/preorder_traversal.rs index 160b68300..b823dc1f6 100644 --- a/src/problem_0297_serialize_and_deserialize_binary_tree/preorder_traversal.rs +++ b/src/problem_0297_serialize_and_deserialize_binary_tree/preorder_traversal.rs @@ -28,7 +28,7 @@ impl Codec { } } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn serialize(&self, root: Option>>) -> String { let mut result = String::new(); @@ -47,7 +47,7 @@ impl Codec { }) } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn deserialize(&self, data: String) -> Option>> { Self::deserialize_helper(&mut data.split(' ')) } diff --git a/src/problem_0324_wiggle_sort_ii/find_median.rs b/src/problem_0324_wiggle_sort_ii/find_median.rs index 7d87c852f..25c59b2de 100644 --- a/src/problem_0324_wiggle_sort_ii/find_median.rs +++ b/src/problem_0324_wiggle_sort_ii/find_median.rs @@ -7,7 +7,7 @@ use rand::{Rng, SeedableRng}; use std::cmp::Ordering; impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn wiggle_sort(nums: &mut Vec) { let mut start = 0; let mut end = nums.len(); diff --git a/src/problem_0344_reverse_string/cheating.rs b/src/problem_0344_reverse_string/cheating.rs index 72d424fd1..f6b2f2ab8 100644 --- a/src/problem_0344_reverse_string/cheating.rs +++ b/src/problem_0344_reverse_string/cheating.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn reverse_string(s: &mut Vec) { s.reverse(); } diff --git a/src/problem_0344_reverse_string/indices.rs b/src/problem_0344_reverse_string/indices.rs index 0d18803aa..29bf55604 100644 --- a/src/problem_0344_reverse_string/indices.rs +++ b/src/problem_0344_reverse_string/indices.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn reverse_string(s: &mut Vec) { let length = s.len(); diff --git a/src/problem_0344_reverse_string/iterator.rs b/src/problem_0344_reverse_string/iterator.rs index a7b7eb8e6..85b06283f 100644 --- a/src/problem_0344_reverse_string/iterator.rs +++ b/src/problem_0344_reverse_string/iterator.rs @@ -5,7 +5,7 @@ pub struct Solution; use std::mem; impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn reverse_string(s: &mut Vec) { let mut iter = s.iter_mut(); diff --git a/src/problem_0352_data_stream_as_disjoint_intervals/mod.rs b/src/problem_0352_data_stream_as_disjoint_intervals/mod.rs index f0e47eacf..810421051 100644 --- a/src/problem_0352_data_stream_as_disjoint_intervals/mod.rs +++ b/src/problem_0352_data_stream_as_disjoint_intervals/mod.rs @@ -11,606 +11,604 @@ pub trait SummaryRanges { mod tests { use super::SummaryRanges; - #[allow(variant_size_differences)] // Expected. enum Operation { AddNum(i32), GetIntervals(&'static [[i32; 2]]), } - #[allow(clippy::too_many_lines)] - pub fn run() { - use Operation::{AddNum, GetIntervals}; + const EXTRA_TEST_CASE: &[Operation] = &[ + Operation::AddNum(49), + Operation::GetIntervals(&[[49, 49]]), + Operation::AddNum(97), + Operation::GetIntervals(&[[49, 49], [97, 97]]), + Operation::AddNum(53), + Operation::GetIntervals(&[[49, 49], [53, 53], [97, 97]]), + Operation::AddNum(5), + Operation::GetIntervals(&[[5, 5], [49, 49], [53, 53], [97, 97]]), + Operation::AddNum(33), + Operation::GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [97, 97]]), + Operation::AddNum(65), + Operation::GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [65, 65], [97, 97]]), + Operation::AddNum(62), + Operation::GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [62, 62], [65, 65], [97, 97]]), + Operation::AddNum(51), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [49, 49], + [51, 51], + [53, 53], + [62, 62], + [65, 65], + [97, 97], + ]), + Operation::AddNum(100), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [49, 49], + [51, 51], + [53, 53], + [62, 62], + [65, 65], + [97, 97], + [100, 100], + ]), + Operation::AddNum(38), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [38, 38], + [49, 49], + [51, 51], + [53, 53], + [62, 62], + [65, 65], + [97, 97], + [100, 100], + ]), + Operation::AddNum(61), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [38, 38], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [65, 65], + [97, 97], + [100, 100], + ]), + Operation::AddNum(45), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [65, 65], + [97, 97], + [100, 100], + ]), + Operation::AddNum(74), + Operation::GetIntervals(&[ + [5, 5], + [33, 33], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [65, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(27), + Operation::GetIntervals(&[ + [5, 5], + [27, 27], + [33, 33], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [65, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(64), + Operation::GetIntervals(&[ + [5, 5], + [27, 27], + [33, 33], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(17), + Operation::GetIntervals(&[ + [5, 5], + [17, 17], + [27, 27], + [33, 33], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(36), + Operation::GetIntervals(&[ + [5, 5], + [17, 17], + [27, 27], + [33, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(17), + Operation::GetIntervals(&[ + [5, 5], + [17, 17], + [27, 27], + [33, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [97, 97], + [100, 100], + ]), + Operation::AddNum(96), + Operation::GetIntervals(&[ + [5, 5], + [17, 17], + [27, 27], + [33, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [96, 97], + [100, 100], + ]), + Operation::AddNum(12), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [33, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [96, 97], + [100, 100], + ]), + Operation::AddNum(79), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [33, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [79, 79], + [96, 97], + [100, 100], + ]), + Operation::AddNum(32), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [32, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [74, 74], + [79, 79], + [96, 97], + [100, 100], + ]), + Operation::AddNum(68), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [32, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [79, 79], + [96, 97], + [100, 100], + ]), + Operation::AddNum(90), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [32, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [79, 79], + [90, 90], + [96, 97], + [100, 100], + ]), + Operation::AddNum(77), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 17], + [27, 27], + [32, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [96, 97], + [100, 100], + ]), + Operation::AddNum(18), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 38], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [96, 97], + [100, 100], + ]), + Operation::AddNum(39), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [96, 97], + [100, 100], + ]), + Operation::AddNum(12), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [96, 97], + [100, 100], + ]), + Operation::AddNum(93), + Operation::GetIntervals(&[ + [5, 5], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [93, 93], + [96, 97], + [100, 100], + ]), + Operation::AddNum(9), + Operation::GetIntervals(&[ + [5, 5], + [9, 9], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [90, 90], + [93, 93], + [96, 97], + [100, 100], + ]), + Operation::AddNum(87), + Operation::GetIntervals(&[ + [5, 5], + [9, 9], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [87, 87], + [90, 90], + [93, 93], + [96, 97], + [100, 100], + ]), + Operation::AddNum(42), + Operation::GetIntervals(&[ + [5, 5], + [9, 9], + [12, 12], + [17, 18], + [27, 27], + [32, 33], + [36, 36], + [38, 39], + [42, 42], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [61, 62], + [64, 65], + [68, 68], + [74, 74], + [77, 77], + [79, 79], + [87, 87], + [90, 90], + [93, 93], + [96, 97], + [100, 100], + ]), + Operation::AddNum(60), + Operation::AddNum(71), + Operation::AddNum(12), + Operation::AddNum(45), + Operation::AddNum(55), + Operation::AddNum(40), + Operation::AddNum(78), + Operation::AddNum(81), + Operation::AddNum(26), + Operation::AddNum(70), + Operation::AddNum(61), + Operation::AddNum(56), + Operation::AddNum(66), + Operation::AddNum(33), + Operation::AddNum(7), + Operation::AddNum(70), + Operation::AddNum(1), + Operation::AddNum(11), + Operation::AddNum(92), + Operation::AddNum(51), + Operation::AddNum(90), + Operation::AddNum(100), + Operation::AddNum(85), + Operation::AddNum(80), + Operation::GetIntervals(&[ + [1, 1], + [5, 5], + [7, 7], + [9, 9], + [11, 12], + [17, 18], + [26, 27], + [32, 33], + [36, 36], + [38, 40], + [42, 42], + [45, 45], + [49, 49], + [51, 51], + [53, 53], + [55, 56], + [60, 62], + [64, 66], + [68, 68], + [70, 71], + [74, 74], + [77, 81], + [85, 85], + [87, 87], + [90, 90], + [92, 93], + [96, 97], + [100, 100], + ]), + ]; + pub fn run() { let test_cases = [ &[ - AddNum(1), - GetIntervals(&[[1, 1]]), - AddNum(3), - GetIntervals(&[[1, 1], [3, 3]]), - AddNum(7), - GetIntervals(&[[1, 1], [3, 3], [7, 7]]), - AddNum(2), - GetIntervals(&[[1, 3], [7, 7]]), - AddNum(6), - GetIntervals(&[[1, 3], [6, 7]]), + Operation::AddNum(1), + Operation::GetIntervals(&[[1, 1]]), + Operation::AddNum(3), + Operation::GetIntervals(&[[1, 1], [3, 3]]), + Operation::AddNum(7), + Operation::GetIntervals(&[[1, 1], [3, 3], [7, 7]]), + Operation::AddNum(2), + Operation::GetIntervals(&[[1, 3], [7, 7]]), + Operation::AddNum(6), + Operation::GetIntervals(&[[1, 3], [6, 7]]), ] as &[_], &[ - AddNum(6), - GetIntervals(&[[6, 6]]), - AddNum(6), - GetIntervals(&[[6, 6]]), - AddNum(0), - GetIntervals(&[[0, 0], [6, 6]]), - AddNum(4), - GetIntervals(&[[0, 0], [4, 4], [6, 6]]), - AddNum(8), - GetIntervals(&[[0, 0], [4, 4], [6, 6], [8, 8]]), - AddNum(7), - GetIntervals(&[[0, 0], [4, 4], [6, 8]]), - AddNum(6), - GetIntervals(&[[0, 0], [4, 4], [6, 8]]), - AddNum(4), - GetIntervals(&[[0, 0], [4, 4], [6, 8]]), - AddNum(7), - GetIntervals(&[[0, 0], [4, 4], [6, 8]]), - AddNum(5), - GetIntervals(&[[0, 0], [4, 8]]), - ], - &[ - AddNum(1), - GetIntervals(&[[1, 1]]), - AddNum(9), - GetIntervals(&[[1, 1], [9, 9]]), - AddNum(2), - GetIntervals(&[[1, 2], [9, 9]]), + Operation::AddNum(6), + Operation::GetIntervals(&[[6, 6]]), + Operation::AddNum(6), + Operation::GetIntervals(&[[6, 6]]), + Operation::AddNum(0), + Operation::GetIntervals(&[[0, 0], [6, 6]]), + Operation::AddNum(4), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 6]]), + Operation::AddNum(8), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 6], [8, 8]]), + Operation::AddNum(7), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 8]]), + Operation::AddNum(6), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 8]]), + Operation::AddNum(4), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 8]]), + Operation::AddNum(7), + Operation::GetIntervals(&[[0, 0], [4, 4], [6, 8]]), + Operation::AddNum(5), + Operation::GetIntervals(&[[0, 0], [4, 8]]), ], &[ - AddNum(49), - GetIntervals(&[[49, 49]]), - AddNum(97), - GetIntervals(&[[49, 49], [97, 97]]), - AddNum(53), - GetIntervals(&[[49, 49], [53, 53], [97, 97]]), - AddNum(5), - GetIntervals(&[[5, 5], [49, 49], [53, 53], [97, 97]]), - AddNum(33), - GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [97, 97]]), - AddNum(65), - GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [65, 65], [97, 97]]), - AddNum(62), - GetIntervals(&[[5, 5], [33, 33], [49, 49], [53, 53], [62, 62], [65, 65], [97, 97]]), - AddNum(51), - GetIntervals(&[ - [5, 5], - [33, 33], - [49, 49], - [51, 51], - [53, 53], - [62, 62], - [65, 65], - [97, 97], - ]), - AddNum(100), - GetIntervals(&[ - [5, 5], - [33, 33], - [49, 49], - [51, 51], - [53, 53], - [62, 62], - [65, 65], - [97, 97], - [100, 100], - ]), - AddNum(38), - GetIntervals(&[ - [5, 5], - [33, 33], - [38, 38], - [49, 49], - [51, 51], - [53, 53], - [62, 62], - [65, 65], - [97, 97], - [100, 100], - ]), - AddNum(61), - GetIntervals(&[ - [5, 5], - [33, 33], - [38, 38], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [65, 65], - [97, 97], - [100, 100], - ]), - AddNum(45), - GetIntervals(&[ - [5, 5], - [33, 33], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [65, 65], - [97, 97], - [100, 100], - ]), - AddNum(74), - GetIntervals(&[ - [5, 5], - [33, 33], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [65, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(27), - GetIntervals(&[ - [5, 5], - [27, 27], - [33, 33], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [65, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(64), - GetIntervals(&[ - [5, 5], - [27, 27], - [33, 33], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(17), - GetIntervals(&[ - [5, 5], - [17, 17], - [27, 27], - [33, 33], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(36), - GetIntervals(&[ - [5, 5], - [17, 17], - [27, 27], - [33, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(17), - GetIntervals(&[ - [5, 5], - [17, 17], - [27, 27], - [33, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [97, 97], - [100, 100], - ]), - AddNum(96), - GetIntervals(&[ - [5, 5], - [17, 17], - [27, 27], - [33, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [96, 97], - [100, 100], - ]), - AddNum(12), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [33, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [96, 97], - [100, 100], - ]), - AddNum(79), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [33, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [79, 79], - [96, 97], - [100, 100], - ]), - AddNum(32), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [32, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [74, 74], - [79, 79], - [96, 97], - [100, 100], - ]), - AddNum(68), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [32, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [79, 79], - [96, 97], - [100, 100], - ]), - AddNum(90), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [32, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [79, 79], - [90, 90], - [96, 97], - [100, 100], - ]), - AddNum(77), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 17], - [27, 27], - [32, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [96, 97], - [100, 100], - ]), - AddNum(18), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 38], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [96, 97], - [100, 100], - ]), - AddNum(39), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [96, 97], - [100, 100], - ]), - AddNum(12), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [96, 97], - [100, 100], - ]), - AddNum(93), - GetIntervals(&[ - [5, 5], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [93, 93], - [96, 97], - [100, 100], - ]), - AddNum(9), - GetIntervals(&[ - [5, 5], - [9, 9], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [90, 90], - [93, 93], - [96, 97], - [100, 100], - ]), - AddNum(87), - GetIntervals(&[ - [5, 5], - [9, 9], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [87, 87], - [90, 90], - [93, 93], - [96, 97], - [100, 100], - ]), - AddNum(42), - GetIntervals(&[ - [5, 5], - [9, 9], - [12, 12], - [17, 18], - [27, 27], - [32, 33], - [36, 36], - [38, 39], - [42, 42], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [61, 62], - [64, 65], - [68, 68], - [74, 74], - [77, 77], - [79, 79], - [87, 87], - [90, 90], - [93, 93], - [96, 97], - [100, 100], - ]), - AddNum(60), - AddNum(71), - AddNum(12), - AddNum(45), - AddNum(55), - AddNum(40), - AddNum(78), - AddNum(81), - AddNum(26), - AddNum(70), - AddNum(61), - AddNum(56), - AddNum(66), - AddNum(33), - AddNum(7), - AddNum(70), - AddNum(1), - AddNum(11), - AddNum(92), - AddNum(51), - AddNum(90), - AddNum(100), - AddNum(85), - AddNum(80), - GetIntervals(&[ - [1, 1], - [5, 5], - [7, 7], - [9, 9], - [11, 12], - [17, 18], - [26, 27], - [32, 33], - [36, 36], - [38, 40], - [42, 42], - [45, 45], - [49, 49], - [51, 51], - [53, 53], - [55, 56], - [60, 62], - [64, 66], - [68, 68], - [70, 71], - [74, 74], - [77, 81], - [85, 85], - [87, 87], - [90, 90], - [92, 93], - [96, 97], - [100, 100], - ]), + Operation::AddNum(1), + Operation::GetIntervals(&[[1, 1]]), + Operation::AddNum(9), + Operation::GetIntervals(&[[1, 1], [9, 9]]), + Operation::AddNum(2), + Operation::GetIntervals(&[[1, 2], [9, 9]]), ], + EXTRA_TEST_CASE, ]; for operations in test_cases { @@ -618,8 +616,8 @@ mod tests { for operation in operations { match *operation { - AddNum(val) => summary_ranges.add_num(val), - GetIntervals(expected) => assert_eq!(summary_ranges.get_intervals(), expected), + Operation::AddNum(val) => summary_ranges.add_num(val), + Operation::GetIntervals(expected) => assert_eq!(summary_ranges.get_intervals(), expected), } } } diff --git a/src/problem_0355_design_twitter/binary_heap.rs b/src/problem_0355_design_twitter/binary_heap.rs index 81054485d..421cd1bd9 100644 --- a/src/problem_0355_design_twitter/binary_heap.rs +++ b/src/problem_0355_design_twitter/binary_heap.rs @@ -68,7 +68,7 @@ impl Twitter { result } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn follow(&mut self, follower_id: i32, followee_id: i32) { self.users .entry(follower_id) @@ -81,7 +81,7 @@ impl Twitter { }); } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn unfollow(&mut self, follower_id: i32, followee_id: i32) { if follower_id != followee_id { if let Some(user) = self.users.get_mut(&follower_id) { @@ -106,12 +106,12 @@ impl super::Twitter for Twitter { self.get_news_feed(user_id) } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn follow(&mut self, follower_id: i32, followee_id: i32) { self.follow(follower_id, followee_id); } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn unfollow(&mut self, follower_id: i32, followee_id: i32) { self.unfollow(follower_id, followee_id); } diff --git a/src/problem_0355_design_twitter/binary_heap_2.rs b/src/problem_0355_design_twitter/binary_heap_2.rs index 251c5cd23..5e1e64d01 100644 --- a/src/problem_0355_design_twitter/binary_heap_2.rs +++ b/src/problem_0355_design_twitter/binary_heap_2.rs @@ -64,7 +64,7 @@ impl Twitter { result } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn follow(&mut self, follower_id: i32, followee_id: i32) { self.followees .entry(follower_id) @@ -74,7 +74,7 @@ impl Twitter { .or_insert_with(|| [follower_id, followee_id].iter().copied().collect()); } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn unfollow(&mut self, follower_id: i32, followee_id: i32) { if follower_id != followee_id { if let Some(followees) = self.followees.get_mut(&follower_id) { @@ -99,12 +99,12 @@ impl super::Twitter for Twitter { self.get_news_feed(user_id) } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn follow(&mut self, follower_id: i32, followee_id: i32) { self.follow(follower_id, followee_id); } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] fn unfollow(&mut self, follower_id: i32, followee_id: i32) { self.unfollow(follower_id, followee_id); } diff --git a/src/problem_0355_design_twitter/mod.rs b/src/problem_0355_design_twitter/mod.rs index 5d0bd96d6..b7933ba3b 100644 --- a/src/problem_0355_design_twitter/mod.rs +++ b/src/problem_0355_design_twitter/mod.rs @@ -20,7 +20,7 @@ mod tests { Unfollow(i32, i32), } - #[allow(clippy::similar_names)] // Expected. + #[expect(clippy::similar_names, reason = "required")] pub fn run() { use Operation::{Follow, GetNewsFeed, PostTweet, Unfollow}; diff --git a/src/problem_0374_guess_number_higher_or_lower/binary_search.rs b/src/problem_0374_guess_number_higher_or_lower/binary_search.rs index 73751bc9b..5435ba993 100644 --- a/src/problem_0374_guess_number_higher_or_lower/binary_search.rs +++ b/src/problem_0374_guess_number_higher_or_lower/binary_search.rs @@ -5,7 +5,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(non_snake_case, unsafe_code)] // Expected. + #[expect(non_snake_case, unsafe_code, reason = "required")] pub fn guessNumber(n: i32) -> i32 { let mut left = 1; let mut right = n; diff --git a/src/problem_0374_guess_number_higher_or_lower/mod.rs b/src/problem_0374_guess_number_higher_or_lower/mod.rs index 00dffd865..d51da53c6 100644 --- a/src/problem_0374_guess_number_higher_or_lower/mod.rs +++ b/src/problem_0374_guess_number_higher_or_lower/mod.rs @@ -24,7 +24,7 @@ fn internal_guess(num: i32) -> i32 { /// # Safety /// /// The `unsafe` here is used to match official function signature, the function is actually safe to use. -#[allow(unsafe_code)] // Expected. +#[expect(unsafe_code, reason = "required")] pub unsafe fn guess(num: i32) -> i32 { internal_guess(num) } diff --git a/src/problem_0432_all_oone_data_structure/mod.rs b/src/problem_0432_all_oone_data_structure/mod.rs index 5b29c3fc7..b42c5eae7 100644 --- a/src/problem_0432_all_oone_data_structure/mod.rs +++ b/src/problem_0432_all_oone_data_structure/mod.rs @@ -19,151 +19,154 @@ mod tests { GetMinKey(&'static [&'static str]), } - #[allow(clippy::too_many_lines)] - pub fn run() { - use Operation::{Dec, GetMaxKey, GetMinKey, Inc}; + const EXTRA_TEST_CASE_1: &[Operation] = &[ + Operation::Inc("hello"), + Operation::Inc("world"), + Operation::Inc("leet"), + Operation::Inc("code"), + Operation::Inc("DS"), + Operation::Inc("leet"), + Operation::GetMaxKey(&["leet"]), + Operation::Inc("DS"), + Operation::Dec("leet"), + Operation::GetMaxKey(&["DS"]), + Operation::Dec("DS"), + Operation::Inc("hello"), + Operation::GetMaxKey(&["hello"]), + Operation::Inc("hello"), + Operation::Inc("hello"), + Operation::Dec("world"), + Operation::Dec("leet"), + Operation::Dec("code"), + Operation::Dec("DS"), + Operation::GetMaxKey(&["hello"]), + Operation::Inc("new"), + Operation::Inc("new"), + Operation::Inc("new"), + Operation::Inc("new"), + Operation::Inc("new"), + Operation::Inc("new"), + Operation::GetMaxKey(&["new"]), + Operation::GetMinKey(&["hello"]), + ]; + + const EXTRA_TEST_CASE_2: &[Operation] = &[ + Operation::Inc("hello"), + Operation::Inc("hello"), + Operation::Inc("world"), + Operation::Inc("world"), + Operation::Inc("hello"), + Operation::Dec("world"), + Operation::GetMaxKey(&["hello"]), + Operation::GetMinKey(&["world"]), + Operation::Inc("world"), + Operation::Inc("world"), + Operation::Inc("leet"), + Operation::GetMaxKey(&["hello", "world"]), + Operation::GetMinKey(&["leet"]), + Operation::Inc("leet"), + Operation::Inc("leet"), + Operation::GetMinKey(&["hello", "leet", "world"]), + ]; + + const EXTRA_TEST_CASE_3: &[Operation] = &[ + Operation::Inc("a"), + Operation::Inc("b"), + Operation::Inc("b"), + Operation::Inc("c"), + Operation::Inc("c"), + Operation::Inc("c"), + Operation::Inc("b"), + Operation::GetMaxKey(&["b", "c"]), + Operation::GetMinKey(&["a"]), + Operation::Dec("b"), + Operation::GetMaxKey(&["c"]), + Operation::GetMinKey(&["a"]), + Operation::Dec("a"), + Operation::Dec("c"), + Operation::Dec("b"), + Operation::GetMaxKey(&["c"]), + Operation::GetMinKey(&["b"]), + ]; + pub fn run() { let test_cases = [ &[ - Inc("hello"), - Inc("hello"), - GetMaxKey(&["hello"]), - GetMinKey(&["hello"]), - Inc("leet"), - GetMaxKey(&["hello"]), - GetMinKey(&["leet"]), + Operation::Inc("hello"), + Operation::Inc("hello"), + Operation::GetMaxKey(&["hello"]), + Operation::GetMinKey(&["hello"]), + Operation::Inc("leet"), + Operation::GetMaxKey(&["hello"]), + Operation::GetMinKey(&["leet"]), ] as &[_], &[ - Inc("hello"), - Inc("goodbye"), - Inc("hello"), - Inc("hello"), - GetMaxKey(&["hello"]), - Inc("leet"), - Inc("code"), - Inc("leet"), - Dec("hello"), - Inc("leet"), - Inc("code"), - Inc("code"), - GetMaxKey(&["code", "hello", "leet"]), - ], - &[ - Inc("a"), - Inc("b"), - Inc("c"), - Inc("d"), - Inc("a"), - Inc("b"), - Inc("c"), - Inc("d"), - Inc("c"), - Inc("d"), - Inc("d"), - Inc("a"), - GetMinKey(&["b"]), - ], - &[ - Inc("hello"), - Inc("world"), - Inc("leet"), - Inc("code"), - Inc("DS"), - Inc("leet"), - GetMaxKey(&["leet"]), - Inc("DS"), - Dec("leet"), - GetMaxKey(&["DS"]), - Dec("DS"), - Inc("hello"), - GetMaxKey(&["hello"]), - Inc("hello"), - Inc("hello"), - Dec("world"), - Dec("leet"), - Dec("code"), - Dec("DS"), - GetMaxKey(&["hello"]), - Inc("new"), - Inc("new"), - Inc("new"), - Inc("new"), - Inc("new"), - Inc("new"), - GetMaxKey(&["new"]), - GetMinKey(&["hello"]), - ], - &[ - Inc("a"), - Inc("b"), - Inc("b"), - Inc("c"), - Inc("c"), - Inc("c"), - Dec("b"), - Dec("b"), - GetMinKey(&["a"]), - Dec("a"), - GetMaxKey(&["c"]), - GetMinKey(&["c"]), + Operation::Inc("hello"), + Operation::Inc("goodbye"), + Operation::Inc("hello"), + Operation::Inc("hello"), + Operation::GetMaxKey(&["hello"]), + Operation::Inc("leet"), + Operation::Inc("code"), + Operation::Inc("leet"), + Operation::Dec("hello"), + Operation::Inc("leet"), + Operation::Inc("code"), + Operation::Inc("code"), + Operation::GetMaxKey(&["code", "hello", "leet"]), ], &[ - Inc("a"), - Inc("b"), - Inc("b"), - Inc("b"), - Inc("b"), - Dec("b"), - Dec("b"), - GetMaxKey(&["b"]), - GetMinKey(&["a"]), + Operation::Inc("a"), + Operation::Inc("b"), + Operation::Inc("c"), + Operation::Inc("d"), + Operation::Inc("a"), + Operation::Inc("b"), + Operation::Inc("c"), + Operation::Inc("d"), + Operation::Inc("c"), + Operation::Inc("d"), + Operation::Inc("d"), + Operation::Inc("a"), + Operation::GetMinKey(&["b"]), ], &[ - Inc("hello"), - Inc("hello"), - Inc("world"), - Inc("world"), - Inc("hello"), - Dec("world"), - GetMaxKey(&["hello"]), - GetMinKey(&["world"]), - Inc("world"), - Inc("world"), - Inc("leet"), - GetMaxKey(&["hello", "world"]), - GetMinKey(&["leet"]), - Inc("leet"), - Inc("leet"), - GetMinKey(&["hello", "leet", "world"]), + Operation::Inc("a"), + Operation::Inc("b"), + Operation::Inc("b"), + Operation::Inc("c"), + Operation::Inc("c"), + Operation::Inc("c"), + Operation::Dec("b"), + Operation::Dec("b"), + Operation::GetMinKey(&["a"]), + Operation::Dec("a"), + Operation::GetMaxKey(&["c"]), + Operation::GetMinKey(&["c"]), ], &[ - Inc("a"), - Inc("b"), - Inc("b"), - Inc("c"), - Inc("c"), - Inc("c"), - Inc("b"), - GetMaxKey(&["b", "c"]), - GetMinKey(&["a"]), - Dec("b"), - GetMaxKey(&["c"]), - GetMinKey(&["a"]), - Dec("a"), - Dec("c"), - Dec("b"), - GetMaxKey(&["c"]), - GetMinKey(&["b"]), + Operation::Inc("a"), + Operation::Inc("b"), + Operation::Inc("b"), + Operation::Inc("b"), + Operation::Inc("b"), + Operation::Dec("b"), + Operation::Dec("b"), + Operation::GetMaxKey(&["b"]), + Operation::GetMinKey(&["a"]), ], &[ - Inc("a"), - Dec("a"), - GetMaxKey(&[""]), - GetMinKey(&[""]), - Dec("a"), - GetMaxKey(&[""]), - GetMinKey(&[""]), + Operation::Inc("a"), + Operation::Dec("a"), + Operation::GetMaxKey(&[""]), + Operation::GetMinKey(&[""]), + Operation::Dec("a"), + Operation::GetMaxKey(&[""]), + Operation::GetMinKey(&[""]), ], + EXTRA_TEST_CASE_1, + EXTRA_TEST_CASE_2, + EXTRA_TEST_CASE_3, ]; for operations in test_cases { @@ -171,10 +174,10 @@ mod tests { for operation in operations { match *operation { - Inc(key) => all_one.inc(key.to_string()), - Dec(key) => all_one.dec(key.to_string()), - GetMaxKey(keys) => assert!(keys.contains(&all_one.get_max_key().as_str())), - GetMinKey(keys) => assert!(keys.contains(&all_one.get_min_key().as_str())), + Operation::Inc(key) => all_one.inc(key.to_string()), + Operation::Dec(key) => all_one.dec(key.to_string()), + Operation::GetMaxKey(keys) => assert!(keys.contains(&all_one.get_max_key().as_str())), + Operation::GetMinKey(keys) => assert!(keys.contains(&all_one.get_min_key().as_str())), } } } diff --git a/src/problem_0443_string_compression/iterative.rs b/src/problem_0443_string_compression/iterative.rs index 592a91ea8..2d87ca6fd 100644 --- a/src/problem_0443_string_compression/iterative.rs +++ b/src/problem_0443_string_compression/iterative.rs @@ -21,7 +21,7 @@ impl Solution { i } - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn compress(chars: &mut Vec) -> i32 { if let Some(mut i) = chars .get(1..) diff --git a/src/problem_0449_serialize_and_deserialize_bst/preorder_traversal.rs b/src/problem_0449_serialize_and_deserialize_bst/preorder_traversal.rs index 9b32ce851..e7367f0fe 100644 --- a/src/problem_0449_serialize_and_deserialize_bst/preorder_traversal.rs +++ b/src/problem_0449_serialize_and_deserialize_bst/preorder_traversal.rs @@ -25,7 +25,7 @@ impl Codec { } } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn serialize(&self, root: Option>>) -> String { let mut result = Vec::new(); @@ -53,7 +53,7 @@ impl Codec { }) } - #[allow(clippy::unused_self)] // Expected. + #[expect(clippy::unused_self, reason = "required")] fn deserialize(&self, data: String) -> Option>> { let mut iter = data .bytes() diff --git a/src/problem_0483_smallest_good_base/iterative.rs b/src/problem_0483_smallest_good_base/iterative.rs index c98712716..fe168b6ff 100644 --- a/src/problem_0483_smallest_good_base/iterative.rs +++ b/src/problem_0483_smallest_good_base/iterative.rs @@ -22,11 +22,10 @@ impl Solution { pub fn smallest_good_base(n: String) -> String { let n_value = n.parse::().unwrap(); - #[allow(clippy::cast_precision_loss)] // Expected; + #[expect(clippy::cast_precision_loss, reason = "optimal")] let n_f64 = n_value as f64; for length in (3..65 - n_value.leading_zeros()).rev() { - #[allow(clippy::cast_precision_loss)] // Expected; let base = n_f64.powf(f64::from(length - 1).recip()) as u64; if Self::get_value(base, length) == n_value { diff --git a/src/problem_0609_find_duplicate_file_in_system/hash_map.rs b/src/problem_0609_find_duplicate_file_in_system/hash_map.rs index 75c681718..58376b9cb 100644 --- a/src/problem_0609_find_duplicate_file_in_system/hash_map.rs +++ b/src/problem_0609_find_duplicate_file_in_system/hash_map.rs @@ -19,7 +19,7 @@ impl Solution { let dir_length = path_buffer.len(); for file in path_iter { - let mut file_iter = file.split(|c: char| c == '(' || c == ')'); + let mut file_iter = file.split(['(', ')']); let file_name = file_iter.next().unwrap(); let file_content = file_iter.next().unwrap(); diff --git a/src/problem_0637_average_of_levels_in_binary_tree/bfs.rs b/src/problem_0637_average_of_levels_in_binary_tree/bfs.rs index 551b6b925..854c0c2ce 100644 --- a/src/problem_0637_average_of_levels_in_binary_tree/bfs.rs +++ b/src/problem_0637_average_of_levels_in_binary_tree/bfs.rs @@ -34,7 +34,7 @@ impl Solution { }; } - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "required")] result.push((sum as f64) / (length as f64)); if queue.is_empty() { diff --git a/src/problem_0652_find_duplicate_subtrees/cached_hash_values.rs b/src/problem_0652_find_duplicate_subtrees/cached_hash_values.rs index b594521e2..6b528adee 100644 --- a/src/problem_0652_find_duplicate_subtrees/cached_hash_values.rs +++ b/src/problem_0652_find_duplicate_subtrees/cached_hash_values.rs @@ -30,7 +30,7 @@ impl Hash for Node { } impl Solution { - #[allow(clippy::mutable_key_type)] // TODO: Check this. + #[expect(clippy::mutable_key_type, reason = "by design")] fn dfs( node: Option>>, cache: &mut HashMap, diff --git a/src/problem_0682_baseball_game/stack.rs b/src/problem_0682_baseball_game/stack.rs index 0fcf4219c..dfba86cd6 100644 --- a/src/problem_0682_baseball_game/stack.rs +++ b/src/problem_0682_baseball_game/stack.rs @@ -7,7 +7,7 @@ impl Solution { let mut stack = Vec::with_capacity(ops.len()); for op in ops { - #[allow(clippy::map_err_ignore)] // Expected. + #[expect(clippy::map_err_ignore, reason = "optimal")] match op.parse().map_err(|_| op.as_str()) { Ok(value) => stack.push(value), Err("C") => { diff --git a/src/problem_0736_parse_lisp_expression/recursive_descent.rs b/src/problem_0736_parse_lisp_expression/recursive_descent.rs index 6c264981c..6236045ad 100644 --- a/src/problem_0736_parse_lisp_expression/recursive_descent.rs +++ b/src/problem_0736_parse_lisp_expression/recursive_descent.rs @@ -6,9 +6,7 @@ use std::collections::HashMap; impl Solution { fn symbol(input: &str) -> Option<(&str, &str)> { - let end = input - .find(|c: char| matches!(c, '(' | ')' | ' ')) - .unwrap_or(input.len()); + let end = input.find(['(', ')', ' ']).unwrap_or(input.len()); if end == 0 { None diff --git a/src/problem_0761_special_binary_string/recursive.rs b/src/problem_0761_special_binary_string/recursive.rs index 929166684..299a9585c 100644 --- a/src/problem_0761_special_binary_string/recursive.rs +++ b/src/problem_0761_special_binary_string/recursive.rs @@ -47,7 +47,7 @@ impl Node { Some(b'1') } - #[allow(clippy::option_if_let_else)] // False positive. + #[expect(clippy::option_if_let_else, reason = "false positive")] State::NextChild(child_iter) => Some(if let Some(child) = child_iter.next() { stack.push(mem::replace(child_iter, child.children.iter())); @@ -57,7 +57,7 @@ impl Node { b'0' }), - #[allow(clippy::manual_map, clippy::option_if_let_else)] // False positive. + #[expect(clippy::manual_map, clippy::option_if_let_else, reason = "false positive")] State::End => { if let Some(child_iter) = stack.last_mut() { Some(if let Some(child) = child_iter.next() { diff --git a/src/problem_0855_exam_room/mod.rs b/src/problem_0855_exam_room/mod.rs index 34db14625..ab01664e7 100644 --- a/src/problem_0855_exam_room/mod.rs +++ b/src/problem_0855_exam_room/mod.rs @@ -15,7 +15,79 @@ mod tests { Leave(i32), } - #[allow(clippy::too_many_lines)] + const EXTRA_TEST_CASE_1: (i32, &[Operation]) = ( + 10, + &[ + Operation::Seat(0), + Operation::Seat(9), + Operation::Seat(4), + Operation::Leave(0), + Operation::Leave(4), + Operation::Seat(0), + Operation::Seat(4), + Operation::Seat(2), + Operation::Seat(6), + Operation::Seat(1), + Operation::Seat(3), + Operation::Seat(5), + Operation::Seat(7), + Operation::Seat(8), + Operation::Leave(0), + Operation::Leave(4), + Operation::Seat(0), + Operation::Seat(4), + Operation::Leave(7), + Operation::Seat(7), + Operation::Leave(3), + Operation::Seat(3), + Operation::Leave(3), + Operation::Seat(3), + Operation::Leave(9), + Operation::Seat(9), + Operation::Leave(0), + Operation::Leave(8), + Operation::Seat(0), + Operation::Seat(8), + Operation::Leave(0), + Operation::Leave(8), + Operation::Seat(0), + Operation::Seat(8), + Operation::Leave(2), + ], + ); + + const EXTRA_TEST_CASE_2: (i32, &[Operation]) = ( + 100, + &[ + Operation::Seat(0), + Operation::Seat(99), + Operation::Seat(49), + Operation::Seat(74), + Operation::Seat(24), + Operation::Seat(12), + Operation::Leave(49), + Operation::Seat(49), + Operation::Seat(36), + Operation::Seat(61), + ], + ); + + const EXTRA_TEST_CASE_3: (i32, &[Operation]) = ( + 9, + &[ + Operation::Seat(0), + Operation::Seat(8), + Operation::Seat(4), + Operation::Seat(2), + Operation::Seat(6), + Operation::Seat(1), + Operation::Leave(8), + Operation::Leave(2), + Operation::Leave(1), + Operation::Leave(6), + ], + ); + pub fn run() { let test_cases = [ ( @@ -38,46 +110,6 @@ mod tests { Operation::Seat(5), ], ), - ( - 10, - &[ - Operation::Seat(0), - Operation::Seat(9), - Operation::Seat(4), - Operation::Leave(0), - Operation::Leave(4), - Operation::Seat(0), - Operation::Seat(4), - Operation::Seat(2), - Operation::Seat(6), - Operation::Seat(1), - Operation::Seat(3), - Operation::Seat(5), - Operation::Seat(7), - Operation::Seat(8), - Operation::Leave(0), - Operation::Leave(4), - Operation::Seat(0), - Operation::Seat(4), - Operation::Leave(7), - Operation::Seat(7), - Operation::Leave(3), - Operation::Seat(3), - Operation::Leave(3), - Operation::Seat(3), - Operation::Leave(9), - Operation::Seat(9), - Operation::Leave(0), - Operation::Leave(8), - Operation::Seat(0), - Operation::Seat(8), - Operation::Leave(0), - Operation::Leave(8), - Operation::Seat(0), - Operation::Seat(8), - Operation::Leave(2), - ], - ), ( 10, &[ @@ -97,21 +129,6 @@ mod tests { Operation::Leave(0), ], ), - ( - 100, - &[ - Operation::Seat(0), - Operation::Seat(99), - Operation::Seat(49), - Operation::Seat(74), - Operation::Seat(24), - Operation::Seat(12), - Operation::Leave(49), - Operation::Seat(49), - Operation::Seat(36), - Operation::Seat(61), - ], - ), ( 4, &[ @@ -124,21 +141,6 @@ mod tests { Operation::Seat(1), ], ), - ( - 9, - &[ - Operation::Seat(0), - Operation::Seat(8), - Operation::Seat(4), - Operation::Seat(2), - Operation::Seat(6), - Operation::Seat(1), - Operation::Leave(8), - Operation::Leave(2), - Operation::Leave(1), - Operation::Leave(6), - ], - ), ( 4, &[ @@ -162,6 +164,9 @@ mod tests { Operation::Seat(1), ], ), + EXTRA_TEST_CASE_1, + EXTRA_TEST_CASE_2, + EXTRA_TEST_CASE_3, ]; for (n, operations) in test_cases { diff --git a/src/problem_0906_super_palindromes/brute_force.rs b/src/problem_0906_super_palindromes/brute_force.rs index 2f6615796..4f829fd55 100644 --- a/src/problem_0906_super_palindromes/brute_force.rs +++ b/src/problem_0906_super_palindromes/brute_force.rs @@ -6,7 +6,7 @@ use std::convert; impl Solution { fn sqrt(value: u64) -> u64 { - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "optimal")] let guess = (value as f64).sqrt() as u64; guess diff --git a/src/problem_0912_sort_an_array/cheating.rs b/src/problem_0912_sort_an_array/cheating.rs index 9053ab54a..c2815a0b5 100644 --- a/src/problem_0912_sort_an_array/cheating.rs +++ b/src/problem_0912_sort_an_array/cheating.rs @@ -6,7 +6,7 @@ impl Solution { pub fn sort_array(nums: Vec) -> Vec { let mut nums = nums; - #[allow(clippy::stable_sort_primitive)] // Expected. + #[expect(clippy::stable_sort_primitive, reason = "by design")] // Expected. nums.sort(); nums diff --git a/src/problem_0919_complete_binary_tree_inserter/queue.rs b/src/problem_0919_complete_binary_tree_inserter/queue.rs index 3333a262e..a15f8820f 100644 --- a/src/problem_0919_complete_binary_tree_inserter/queue.rs +++ b/src/problem_0919_complete_binary_tree_inserter/queue.rs @@ -70,7 +70,7 @@ impl CBTInserter { result } - #[allow(clippy::unnecessary_wraps)] // Expected. + #[expect(clippy::unnecessary_wraps, reason = "required")] fn get_root(&self) -> Option>> { Some(Rc::clone(&self.root)) } diff --git a/src/problem_0971_flip_binary_tree_to_match_preorder_traversal/mod.rs b/src/problem_0971_flip_binary_tree_to_match_preorder_traversal/mod.rs index f7ca55fe9..ab910bfb6 100644 --- a/src/problem_0971_flip_binary_tree_to_match_preorder_traversal/mod.rs +++ b/src/problem_0971_flip_binary_tree_to_match_preorder_traversal/mod.rs @@ -13,120 +13,122 @@ mod tests { use super::Solution; use crate::test_utilities; - #[allow(clippy::too_many_lines)] // Expected. + type TestCase<'a> = ((&'a [Option], &'a [i32]), &'a [i32]); + + const EXTRA_TEST_CASE: TestCase = ( + ( + &[ + Some(15), + Some(26), + Some(40), + Some(25), + Some(38), + Some(29), + Some(6), + Some(48), + Some(1), + Some(16), + Some(8), + Some(18), + Some(27), + Some(21), + Some(19), + Some(31), + Some(39), + Some(46), + None, + Some(49), + Some(45), + None, + Some(22), + Some(34), + Some(41), + Some(42), + None, + Some(9), + None, + Some(2), + Some(4), + None, + None, + None, + Some(17), + None, + None, + None, + None, + Some(36), + Some(24), + None, + Some(33), + None, + Some(30), + None, + None, + Some(23), + Some(37), + None, + None, + Some(5), + Some(12), + None, + Some(10), + Some(7), + None, + None, + None, + Some(13), + None, + None, + None, + Some(11), + Some(43), + None, + None, + None, + None, + None, + None, + Some(50), + Some(35), + Some(3), + Some(32), + None, + None, + None, + None, + None, + None, + None, + None, + None, + Some(47), + None, + Some(28), + Some(44), + Some(14), + None, + None, + None, + None, + None, + Some(20), + ], + &[ + 15, 40, 6, 21, 9, 19, 2, 12, 50, 47, 35, 28, 20, 5, 4, 10, 32, 3, 14, 44, 29, 18, 34, 7, 11, 43, 41, + 27, 42, 37, 23, 26, 38, 16, 45, 24, 13, 36, 49, 8, 22, 33, 25, 1, 46, 48, 31, 39, 17, 30, + ], + ), + &[-1], + ); + pub fn run() { let test_cases = [ ((&[Some(1), Some(2)] as &[_], &[2, 1] as &[_]), &[-1] as &[_]), ((&[Some(1), Some(2), Some(3)], &[1, 3, 2]), &[1]), ((&[Some(1), Some(2), Some(3)], &[1, 2, 3]), &[]), ((&[Some(1), Some(2), None, Some(3)], &[1, 3, 2]), &[-1]), - ( - ( - &[ - Some(15), - Some(26), - Some(40), - Some(25), - Some(38), - Some(29), - Some(6), - Some(48), - Some(1), - Some(16), - Some(8), - Some(18), - Some(27), - Some(21), - Some(19), - Some(31), - Some(39), - Some(46), - None, - Some(49), - Some(45), - None, - Some(22), - Some(34), - Some(41), - Some(42), - None, - Some(9), - None, - Some(2), - Some(4), - None, - None, - None, - Some(17), - None, - None, - None, - None, - Some(36), - Some(24), - None, - Some(33), - None, - Some(30), - None, - None, - Some(23), - Some(37), - None, - None, - Some(5), - Some(12), - None, - Some(10), - Some(7), - None, - None, - None, - Some(13), - None, - None, - None, - Some(11), - Some(43), - None, - None, - None, - None, - None, - None, - Some(50), - Some(35), - Some(3), - Some(32), - None, - None, - None, - None, - None, - None, - None, - None, - None, - Some(47), - None, - Some(28), - Some(44), - Some(14), - None, - None, - None, - None, - None, - Some(20), - ], - &[ - 15, 40, 6, 21, 9, 19, 2, 12, 50, 47, 35, 28, 20, 5, 4, 10, 32, 3, 14, 44, 29, 18, 34, 7, 11, - 43, 41, 27, 42, 37, 23, 26, 38, 16, 45, 24, 13, 36, 49, 8, 22, 33, 25, 1, 46, 48, 31, 39, 17, - 30, - ], - ), - &[-1], - ), + EXTRA_TEST_CASE, ]; for ((root, voyage), expected) in test_cases { diff --git a/src/problem_0993_cousins_in_binary_tree/mod.rs b/src/problem_0993_cousins_in_binary_tree/mod.rs index d030c8016..708ceae56 100644 --- a/src/problem_0993_cousins_in_binary_tree/mod.rs +++ b/src/problem_0993_cousins_in_binary_tree/mod.rs @@ -13,7 +13,6 @@ mod tests { use super::Solution; use crate::test_utilities; - #[allow(clippy::too_many_lines)] // Expected. pub fn run() { let test_cases = [ ((&[Some(1), Some(2), Some(3), Some(4)] as &[_], 4, 3), false), diff --git a/src/problem_0998_maximum_binary_tree_ii/iterative.rs b/src/problem_0998_maximum_binary_tree_ii/iterative.rs index 4ff34af7c..55d36fc63 100644 --- a/src/problem_0998_maximum_binary_tree_ii/iterative.rs +++ b/src/problem_0998_maximum_binary_tree_ii/iterative.rs @@ -8,7 +8,7 @@ use std::cell::RefCell; use std::rc::Rc; impl Solution { - #[allow(clippy::unnecessary_wraps)] // Expected. + #[expect(clippy::unnecessary_wraps, reason = "required")] pub fn insert_into_max_tree(root: Option>>, val: i32) -> Option>> { let root = root.unwrap(); diff --git a/src/problem_1048_longest_string_chain/dfs.rs b/src/problem_1048_longest_string_chain/dfs.rs index 7a08ce5c7..dd622c580 100644 --- a/src/problem_1048_longest_string_chain/dfs.rs +++ b/src/problem_1048_longest_string_chain/dfs.rs @@ -7,7 +7,7 @@ use std::mem; impl Solution { fn dfs(word: &mut [u8], cache: &mut HashMap<&[u8], u32>) -> u32 { - #[allow(clippy::option_if_let_else)] // False positive. + #[expect(clippy::option_if_let_else, reason = "false positive")] if let Some(length) = cache.get_mut(word) { if *length == 0 { if word.len() < 2 { diff --git a/src/problem_1080_insufficient_nodes_in_root_to_leaf_paths/recursive.rs b/src/problem_1080_insufficient_nodes_in_root_to_leaf_paths/recursive.rs index 872d14e29..d108a11bf 100644 --- a/src/problem_1080_insufficient_nodes_in_root_to_leaf_paths/recursive.rs +++ b/src/problem_1080_insufficient_nodes_in_root_to_leaf_paths/recursive.rs @@ -9,7 +9,7 @@ use std::rc::Rc; impl Solution { fn helper(node: &mut Option>>, limit: i32) -> i32 { - #[allow(clippy::option_if_let_else)] // False positive. + #[expect(clippy::option_if_let_else, reason = "false positive")] if let Some(node_ref) = node.as_deref() { let mut node_ref = node_ref.borrow_mut(); let child_limit = limit - node_ref.val; diff --git a/src/problem_1089_duplicate_zeros/count_zeros.rs b/src/problem_1089_duplicate_zeros/count_zeros.rs index c68fe6f08..edce60651 100644 --- a/src/problem_1089_duplicate_zeros/count_zeros.rs +++ b/src/problem_1089_duplicate_zeros/count_zeros.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::ptr_arg)] // Expected. + #[expect(clippy::ptr_arg, reason = "required")] pub fn duplicate_zeros(arr: &mut Vec) { let n = arr.len(); let mut required = 0; diff --git a/src/problem_1093_statistics_from_a_large_sample/iterative.rs b/src/problem_1093_statistics_from_a_large_sample/iterative.rs index 9708f93c3..f94ea91c4 100644 --- a/src/problem_1093_statistics_from_a_large_sample/iterative.rs +++ b/src/problem_1093_statistics_from_a_large_sample/iterative.rs @@ -32,7 +32,7 @@ impl Solution { } } - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mean = (sum as f64) / f64::from(total_count); // Median. diff --git a/src/problem_1096_brace_expansion_ii/parse_and_expand.rs b/src/problem_1096_brace_expansion_ii/parse_and_expand.rs index dcbdd0995..d4d5878cd 100644 --- a/src/problem_1096_brace_expansion_ii/parse_and_expand.rs +++ b/src/problem_1096_brace_expansion_ii/parse_and_expand.rs @@ -4,7 +4,6 @@ pub struct Solution; use std::str::Bytes; -#[allow(variant_size_differences)] // Expected. enum Atom { Char(u8), Set(Vec>), diff --git a/src/problem_1125_smallest_sufficient_team/mod.rs b/src/problem_1125_smallest_sufficient_team/mod.rs index 6674336fa..04967474d 100644 --- a/src/problem_1125_smallest_sufficient_team/mod.rs +++ b/src/problem_1125_smallest_sufficient_team/mod.rs @@ -9,7 +9,98 @@ mod tests { use super::Solution; use std::collections::HashSet; - #[allow(clippy::too_many_lines)] // Expected. + const EXTRA_TEST_CASE: ((&[&str], &[&[&str]]), usize) = ( + ( + &[ + "hfkbcrslcdjq", + "jmhobexvmmlyyzk", + "fjubadocdwaygs", + "peaqbonzgl", + "brgjopmm", + "x", + "mf", + "pcfpppaxsxtpixd", + "ccwfthnjt", + "xtadkauiqwravo", + "zezdb", + "a", + "rahimgtlopffbwdg", + "ulqocaijhezwfr", + "zshbwqdhx", + "hyxnrujrqykzhizm", + ], + &[ + &["peaqbonzgl", "xtadkauiqwravo"], + &["peaqbonzgl", "pcfpppaxsxtpixd", "zshbwqdhx"], + &["x", "a"], + &["a"], + &["jmhobexvmmlyyzk", "fjubadocdwaygs", "xtadkauiqwravo", "zshbwqdhx"], + &["fjubadocdwaygs", "x", "zshbwqdhx"], + &["x", "xtadkauiqwravo"], + &["x", "hyxnrujrqykzhizm"], + &["peaqbonzgl", "x", "pcfpppaxsxtpixd", "a"], + &["peaqbonzgl", "pcfpppaxsxtpixd"], + &["a"], + &["hyxnrujrqykzhizm"], + &["jmhobexvmmlyyzk"], + &["hfkbcrslcdjq", "xtadkauiqwravo", "a", "zshbwqdhx"], + &["peaqbonzgl", "mf", "a", "rahimgtlopffbwdg", "zshbwqdhx"], + &["xtadkauiqwravo"], + &["fjubadocdwaygs"], + &["x", "a", "ulqocaijhezwfr", "zshbwqdhx"], + &["peaqbonzgl"], + &["pcfpppaxsxtpixd", "ulqocaijhezwfr", "hyxnrujrqykzhizm"], + &["a", "ulqocaijhezwfr", "hyxnrujrqykzhizm"], + &["a", "rahimgtlopffbwdg"], + &["zshbwqdhx"], + &["fjubadocdwaygs", "peaqbonzgl", "brgjopmm", "x"], + &["hyxnrujrqykzhizm"], + &["jmhobexvmmlyyzk", "a", "ulqocaijhezwfr"], + &["peaqbonzgl", "x", "a", "ulqocaijhezwfr", "zshbwqdhx"], + &["mf", "pcfpppaxsxtpixd"], + &["fjubadocdwaygs", "ulqocaijhezwfr"], + &["fjubadocdwaygs", "x", "a"], + &["zezdb", "hyxnrujrqykzhizm"], + &["ccwfthnjt", "a"], + &["fjubadocdwaygs", "zezdb", "a"], + &[], + &["peaqbonzgl", "ccwfthnjt", "hyxnrujrqykzhizm"], + &["xtadkauiqwravo", "hyxnrujrqykzhizm"], + &["peaqbonzgl", "a"], + &["x", "a", "hyxnrujrqykzhizm"], + &["zshbwqdhx"], + &[], + &["fjubadocdwaygs", "mf", "pcfpppaxsxtpixd", "zshbwqdhx"], + &["pcfpppaxsxtpixd", "a", "zshbwqdhx"], + &["peaqbonzgl"], + &["peaqbonzgl", "x", "ulqocaijhezwfr"], + &["ulqocaijhezwfr"], + &["x"], + &["fjubadocdwaygs", "peaqbonzgl"], + &["fjubadocdwaygs", "xtadkauiqwravo"], + &["pcfpppaxsxtpixd", "zshbwqdhx"], + &["peaqbonzgl", "brgjopmm", "pcfpppaxsxtpixd", "a"], + &["fjubadocdwaygs", "x", "mf", "ulqocaijhezwfr"], + &["jmhobexvmmlyyzk", "brgjopmm", "rahimgtlopffbwdg", "hyxnrujrqykzhizm"], + &["x", "ccwfthnjt", "hyxnrujrqykzhizm"], + &["hyxnrujrqykzhizm"], + &[ + "peaqbonzgl", + "x", + "xtadkauiqwravo", + "ulqocaijhezwfr", + "hyxnrujrqykzhizm", + ], + &["brgjopmm", "ulqocaijhezwfr", "zshbwqdhx"], + &["peaqbonzgl", "pcfpppaxsxtpixd"], + &["fjubadocdwaygs", "x", "a", "zshbwqdhx"], + &["fjubadocdwaygs", "peaqbonzgl", "x"], + &["ccwfthnjt"], + ], + ), + 6, + ); + pub fn run() { let test_cases = [ ( @@ -68,97 +159,7 @@ mod tests { ), 3, ), - ( - ( - &[ - "hfkbcrslcdjq", - "jmhobexvmmlyyzk", - "fjubadocdwaygs", - "peaqbonzgl", - "brgjopmm", - "x", - "mf", - "pcfpppaxsxtpixd", - "ccwfthnjt", - "xtadkauiqwravo", - "zezdb", - "a", - "rahimgtlopffbwdg", - "ulqocaijhezwfr", - "zshbwqdhx", - "hyxnrujrqykzhizm", - ], - &[ - &["peaqbonzgl", "xtadkauiqwravo"], - &["peaqbonzgl", "pcfpppaxsxtpixd", "zshbwqdhx"], - &["x", "a"], - &["a"], - &["jmhobexvmmlyyzk", "fjubadocdwaygs", "xtadkauiqwravo", "zshbwqdhx"], - &["fjubadocdwaygs", "x", "zshbwqdhx"], - &["x", "xtadkauiqwravo"], - &["x", "hyxnrujrqykzhizm"], - &["peaqbonzgl", "x", "pcfpppaxsxtpixd", "a"], - &["peaqbonzgl", "pcfpppaxsxtpixd"], - &["a"], - &["hyxnrujrqykzhizm"], - &["jmhobexvmmlyyzk"], - &["hfkbcrslcdjq", "xtadkauiqwravo", "a", "zshbwqdhx"], - &["peaqbonzgl", "mf", "a", "rahimgtlopffbwdg", "zshbwqdhx"], - &["xtadkauiqwravo"], - &["fjubadocdwaygs"], - &["x", "a", "ulqocaijhezwfr", "zshbwqdhx"], - &["peaqbonzgl"], - &["pcfpppaxsxtpixd", "ulqocaijhezwfr", "hyxnrujrqykzhizm"], - &["a", "ulqocaijhezwfr", "hyxnrujrqykzhizm"], - &["a", "rahimgtlopffbwdg"], - &["zshbwqdhx"], - &["fjubadocdwaygs", "peaqbonzgl", "brgjopmm", "x"], - &["hyxnrujrqykzhizm"], - &["jmhobexvmmlyyzk", "a", "ulqocaijhezwfr"], - &["peaqbonzgl", "x", "a", "ulqocaijhezwfr", "zshbwqdhx"], - &["mf", "pcfpppaxsxtpixd"], - &["fjubadocdwaygs", "ulqocaijhezwfr"], - &["fjubadocdwaygs", "x", "a"], - &["zezdb", "hyxnrujrqykzhizm"], - &["ccwfthnjt", "a"], - &["fjubadocdwaygs", "zezdb", "a"], - &[], - &["peaqbonzgl", "ccwfthnjt", "hyxnrujrqykzhizm"], - &["xtadkauiqwravo", "hyxnrujrqykzhizm"], - &["peaqbonzgl", "a"], - &["x", "a", "hyxnrujrqykzhizm"], - &["zshbwqdhx"], - &[], - &["fjubadocdwaygs", "mf", "pcfpppaxsxtpixd", "zshbwqdhx"], - &["pcfpppaxsxtpixd", "a", "zshbwqdhx"], - &["peaqbonzgl"], - &["peaqbonzgl", "x", "ulqocaijhezwfr"], - &["ulqocaijhezwfr"], - &["x"], - &["fjubadocdwaygs", "peaqbonzgl"], - &["fjubadocdwaygs", "xtadkauiqwravo"], - &["pcfpppaxsxtpixd", "zshbwqdhx"], - &["peaqbonzgl", "brgjopmm", "pcfpppaxsxtpixd", "a"], - &["fjubadocdwaygs", "x", "mf", "ulqocaijhezwfr"], - &["jmhobexvmmlyyzk", "brgjopmm", "rahimgtlopffbwdg", "hyxnrujrqykzhizm"], - &["x", "ccwfthnjt", "hyxnrujrqykzhizm"], - &["hyxnrujrqykzhizm"], - &[ - "peaqbonzgl", - "x", - "xtadkauiqwravo", - "ulqocaijhezwfr", - "hyxnrujrqykzhizm", - ], - &["brgjopmm", "ulqocaijhezwfr", "zshbwqdhx"], - &["peaqbonzgl", "pcfpppaxsxtpixd"], - &["fjubadocdwaygs", "x", "a", "zshbwqdhx"], - &["fjubadocdwaygs", "peaqbonzgl", "x"], - &["ccwfthnjt"], - ], - ), - 6, - ), + EXTRA_TEST_CASE, ]; let mut all_skills = HashSet::<&str>::new(); diff --git a/src/problem_1172_dinner_plate_stacks/mod.rs b/src/problem_1172_dinner_plate_stacks/mod.rs index b302ac35f..be4727930 100644 --- a/src/problem_1172_dinner_plate_stacks/mod.rs +++ b/src/problem_1172_dinner_plate_stacks/mod.rs @@ -17,7 +17,78 @@ mod tests { PopAtStack(i32, i32), } - #[allow(clippy::too_many_lines)] // Expected. + const EXTRA_TEST_CASE_1: (i32, &[Operation]) = ( + 2, + &[ + Operation::Push(472), + Operation::Push(106), + Operation::Push(497), + Operation::Push(498), + Operation::Push(73), + Operation::Push(115), + Operation::Push(437), + Operation::Push(461), + Operation::PopAtStack(3, 461), + Operation::PopAtStack(3, 437), + Operation::PopAtStack(1, 498), + Operation::PopAtStack(3, -1), + Operation::PopAtStack(0, 106), + Operation::PopAtStack(2, 115), + Operation::PopAtStack(2, 73), + Operation::PopAtStack(1, 497), + Operation::PopAtStack(1, -1), + Operation::PopAtStack(3, -1), + Operation::Push(197), + Operation::Push(239), + Operation::Push(129), + Operation::Push(449), + Operation::Push(460), + Operation::Push(240), + Operation::Push(386), + Operation::Push(343), + Operation::Pop(343), + Operation::Pop(386), + Operation::Pop(240), + Operation::Pop(460), + Operation::Pop(449), + Operation::Pop(129), + Operation::Pop(239), + Operation::Pop(197), + Operation::Pop(472), + Operation::Pop(-1), + ], + ); + + const EXTRA_TEST_CASE_2: (i32, &[Operation]) = ( + 2, + &[ + Operation::Push(471), + Operation::Push(177), + Operation::Push(1), + Operation::Push(29), + Operation::Push(333), + Operation::Push(154), + Operation::Push(130), + Operation::Push(333), + Operation::PopAtStack(1, 29), + Operation::PopAtStack(0, 177), + Operation::PopAtStack(2, 154), + Operation::PopAtStack(0, 471), + Operation::Push(165), + Operation::Push(383), + Operation::Push(267), + Operation::Push(367), + Operation::Push(53), + Operation::Push(373), + Operation::Push(388), + Operation::Push(249), + Operation::Pop(249), + Operation::Pop(388), + Operation::Pop(373), + Operation::Pop(53), + ], + ); + pub fn run() { let test_cases = [ ( @@ -78,35 +149,6 @@ mod tests { Operation::Pop(1), ], ), - ( - 2, - &[ - Operation::Push(471), - Operation::Push(177), - Operation::Push(1), - Operation::Push(29), - Operation::Push(333), - Operation::Push(154), - Operation::Push(130), - Operation::Push(333), - Operation::PopAtStack(1, 29), - Operation::PopAtStack(0, 177), - Operation::PopAtStack(2, 154), - Operation::PopAtStack(0, 471), - Operation::Push(165), - Operation::Push(383), - Operation::Push(267), - Operation::Push(367), - Operation::Push(53), - Operation::Push(373), - Operation::Push(388), - Operation::Push(249), - Operation::Pop(249), - Operation::Pop(388), - Operation::Pop(373), - Operation::Pop(53), - ], - ), ( 2, &[ @@ -127,47 +169,8 @@ mod tests { Operation::Pop(1), ], ), - ( - 2, - &[ - Operation::Push(472), - Operation::Push(106), - Operation::Push(497), - Operation::Push(498), - Operation::Push(73), - Operation::Push(115), - Operation::Push(437), - Operation::Push(461), - Operation::PopAtStack(3, 461), - Operation::PopAtStack(3, 437), - Operation::PopAtStack(1, 498), - Operation::PopAtStack(3, -1), - Operation::PopAtStack(0, 106), - Operation::PopAtStack(2, 115), - Operation::PopAtStack(2, 73), - Operation::PopAtStack(1, 497), - Operation::PopAtStack(1, -1), - Operation::PopAtStack(3, -1), - Operation::Push(197), - Operation::Push(239), - Operation::Push(129), - Operation::Push(449), - Operation::Push(460), - Operation::Push(240), - Operation::Push(386), - Operation::Push(343), - Operation::Pop(343), - Operation::Pop(386), - Operation::Pop(240), - Operation::Pop(460), - Operation::Pop(449), - Operation::Pop(129), - Operation::Pop(239), - Operation::Pop(197), - Operation::Pop(472), - Operation::Pop(-1), - ], - ), + EXTRA_TEST_CASE_1, + EXTRA_TEST_CASE_2, ]; for (length, operations) in test_cases { diff --git a/src/problem_1261_find_elements_in_a_contaminated_binary_tree/iterative.rs b/src/problem_1261_find_elements_in_a_contaminated_binary_tree/iterative.rs index 9f34252d9..81961097d 100644 --- a/src/problem_1261_find_elements_in_a_contaminated_binary_tree/iterative.rs +++ b/src/problem_1261_find_elements_in_a_contaminated_binary_tree/iterative.rs @@ -26,7 +26,7 @@ impl FindElements { break; } - #[allow(clippy::assigning_clones)] // False positive. + #[expect(clippy::assigning_clones, reason = "false positive")] if let Some(node_rc) = node { let node_ref = node_rc.borrow(); diff --git a/src/problem_1282_group_the_people_given_the_group_size_they_belong_to/iterative.rs b/src/problem_1282_group_the_people_given_the_group_size_they_belong_to/iterative.rs index 4cb1738ba..e81334fc8 100644 --- a/src/problem_1282_group_the_people_given_the_group_size_they_belong_to/iterative.rs +++ b/src/problem_1282_group_the_people_given_the_group_size_they_belong_to/iterative.rs @@ -12,7 +12,7 @@ impl Solution { for (i, size) in (0..).zip(group_sizes) { let size = size as usize; - #[allow(clippy::option_if_let_else)] // False positive. + #[expect(clippy::option_if_let_else, reason = "false positive")] let bucket = if let Some(bucket) = buckets.get_mut(size - 1) { bucket } else { diff --git a/src/problem_1298_maximum_candies_you_can_get_from_boxes/mod.rs b/src/problem_1298_maximum_candies_you_can_get_from_boxes/mod.rs index a7461dcc6..af07dc57b 100644 --- a/src/problem_1298_maximum_candies_you_can_get_from_boxes/mod.rs +++ b/src/problem_1298_maximum_candies_you_can_get_from_boxes/mod.rs @@ -14,7 +14,128 @@ pub trait Solution { mod tests { use super::Solution; - #[allow(clippy::too_many_lines)] // Expected. + type TestCase<'a> = ((&'a [i32], &'a [i32], &'a [&'a [i32]], &'a [&'a [i32]], &'a [i32]), i32); + + const EXTRA_TEST_CASE: TestCase = ( + ( + &[ + 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, + ], + &[ + 732, 320, 543, 300, 814, 568, 947, 685, 142, 111, 805, 233, 813, 306, 55, 1, 290, 944, 36, 592, 150, + 596, 372, 299, 644, 445, 605, 202, 64, 807, 753, 731, 552, 766, 119, 862, 453, 136, 43, 572, 801, 518, + 936, 408, 515, 215, 492, 738, 154, + ], + &[ + &[42, 2, 24, 8, 39, 16, 46], + &[20, 39, 46, 21, 32, 31, 43, 16, 12, 23, 3], + &[21, 14, 30, 2, 11, 13, 27, 37, 4, 48], + &[16, 17, 15, 6], + &[31, 14, 3, 32, 35, 19, 42, 43, 44, 29, 25, 41], + &[7, 39, 2, 3, 40, 28, 37, 35, 43, 22, 6, 23, 48, 10, 21, 11], + &[27, 1, 37, 3, 45, 32, 30, 26, 16, 2, 35, 19, 31, 47, 5, 14], + &[28, 35, 23, 17, 6], + &[6, 39, 34, 22], + &[44, 29, 36, 31, 40, 22, 9, 11, 17, 25, 1, 14, 41], + &[39, 37, 11, 36, 17, 42, 13, 12, 7, 9, 43, 41], + &[23, 16, 32, 37], + &[36, 39, 21, 41], + &[15, 27, 5, 42], + &[11, 5, 18, 48, 25, 47, 17, 0, 41, 26, 9, 29], + &[18, 36, 40, 35, 12, 33, 11, 5, 44, 14, 46, 7], + &[48, 22, 11, 33, 14], + &[44, 12, 3, 31, 25, 15, 18, 28, 42, 43], + &[36, 9, 0, 42], + &[1, 22, 3, 24, 9, 11, 43, 8, 35, 5, 41, 29, 40], + &[15, 47, 32, 28, 33, 31, 4, 43], + &[1, 11, 6, 37, 28], + &[46, 20, 47, 32, 26, 15, 11, 40], + &[33, 45, 26, 40, 12, 3, 16, 18, 10, 28, 5], + &[14, 6, 4, 46, 34, 9, 33, 24, 30, 12, 37], + &[45, 24, 18, 31, 32, 39, 26, 27], + &[29, 0, 32, 15, 7, 48, 36, 26, 33, 31, 18, 39, 23, 34, 44], + &[25, 16, 42, 31, 41, 35, 26, 10, 3, 1, 4, 29], + &[8, 11, 5, 40, 9, 18, 10, 16, 26, 30, 19, 2, 14, 4], + &[], + &[0, 20, 17, 47, 41, 36, 23, 42, 15, 13, 27], + &[7, 15, 44, 38, 41, 42, 26, 19, 5, 47], + &[], + &[37, 22], + &[21, 24, 15, 48, 33, 6, 39, 11], + &[23, 7, 3, 29, 10, 40, 1, 16, 6, 8, 27], + &[27, 29, 25, 26, 46, 15, 16], + &[33, 40, 10, 38, 13, 19, 17, 23, 32, 39, 7], + &[35, 3, 39, 18], + &[47, 11, 27, 23, 35, 26, 43, 4, 22, 38, 44, 31, 1, 0], + &[], + &[18, 43, 46, 9, 15, 3, 42, 31, 13, 4, 12, 39, 22], + &[42, 45, 47, 18, 26, 41, 38, 9, 0, 35, 8, 16, 29, 36, 31], + &[3, 20, 29, 12, 46, 41, 23, 4, 9, 27], + &[19, 33], + &[32, 18], + &[17, 28, 7, 35, 6, 22, 4, 43], + &[41, 31, 20, 28, 35, 32, 24, 23, 0, 33, 18, 39, 29, 30, 16], + &[43, 47, 46], + ], + &[ + &[14], + &[], + &[26], + &[4, 47], + &[], + &[6], + &[39, 43, 46], + &[30], + &[], + &[], + &[0, 3], + &[], + &[], + &[], + &[], + &[27], + &[], + &[], + &[], + &[], + &[12], + &[], + &[], + &[41], + &[], + &[31], + &[20, 29], + &[13, 35], + &[18], + &[10, 40], + &[], + &[38], + &[], + &[], + &[19], + &[5], + &[], + &[], + &[11], + &[1], + &[15], + &[], + &[], + &[], + &[24], + &[], + &[], + &[], + &[], + ], + &[ + 2, 7, 8, 9, 16, 17, 21, 22, 23, 25, 28, 32, 33, 34, 36, 37, 42, 44, 45, 48, + ], + ), + 23185, + ); + pub fn run() { let test_cases = [ ( @@ -37,125 +158,7 @@ mod tests { ), 6, ), - ( - ( - &[ - 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, - 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, - ], - &[ - 732, 320, 543, 300, 814, 568, 947, 685, 142, 111, 805, 233, 813, 306, 55, 1, 290, 944, 36, 592, - 150, 596, 372, 299, 644, 445, 605, 202, 64, 807, 753, 731, 552, 766, 119, 862, 453, 136, 43, - 572, 801, 518, 936, 408, 515, 215, 492, 738, 154, - ], - &[ - &[42, 2, 24, 8, 39, 16, 46], - &[20, 39, 46, 21, 32, 31, 43, 16, 12, 23, 3], - &[21, 14, 30, 2, 11, 13, 27, 37, 4, 48], - &[16, 17, 15, 6], - &[31, 14, 3, 32, 35, 19, 42, 43, 44, 29, 25, 41], - &[7, 39, 2, 3, 40, 28, 37, 35, 43, 22, 6, 23, 48, 10, 21, 11], - &[27, 1, 37, 3, 45, 32, 30, 26, 16, 2, 35, 19, 31, 47, 5, 14], - &[28, 35, 23, 17, 6], - &[6, 39, 34, 22], - &[44, 29, 36, 31, 40, 22, 9, 11, 17, 25, 1, 14, 41], - &[39, 37, 11, 36, 17, 42, 13, 12, 7, 9, 43, 41], - &[23, 16, 32, 37], - &[36, 39, 21, 41], - &[15, 27, 5, 42], - &[11, 5, 18, 48, 25, 47, 17, 0, 41, 26, 9, 29], - &[18, 36, 40, 35, 12, 33, 11, 5, 44, 14, 46, 7], - &[48, 22, 11, 33, 14], - &[44, 12, 3, 31, 25, 15, 18, 28, 42, 43], - &[36, 9, 0, 42], - &[1, 22, 3, 24, 9, 11, 43, 8, 35, 5, 41, 29, 40], - &[15, 47, 32, 28, 33, 31, 4, 43], - &[1, 11, 6, 37, 28], - &[46, 20, 47, 32, 26, 15, 11, 40], - &[33, 45, 26, 40, 12, 3, 16, 18, 10, 28, 5], - &[14, 6, 4, 46, 34, 9, 33, 24, 30, 12, 37], - &[45, 24, 18, 31, 32, 39, 26, 27], - &[29, 0, 32, 15, 7, 48, 36, 26, 33, 31, 18, 39, 23, 34, 44], - &[25, 16, 42, 31, 41, 35, 26, 10, 3, 1, 4, 29], - &[8, 11, 5, 40, 9, 18, 10, 16, 26, 30, 19, 2, 14, 4], - &[], - &[0, 20, 17, 47, 41, 36, 23, 42, 15, 13, 27], - &[7, 15, 44, 38, 41, 42, 26, 19, 5, 47], - &[], - &[37, 22], - &[21, 24, 15, 48, 33, 6, 39, 11], - &[23, 7, 3, 29, 10, 40, 1, 16, 6, 8, 27], - &[27, 29, 25, 26, 46, 15, 16], - &[33, 40, 10, 38, 13, 19, 17, 23, 32, 39, 7], - &[35, 3, 39, 18], - &[47, 11, 27, 23, 35, 26, 43, 4, 22, 38, 44, 31, 1, 0], - &[], - &[18, 43, 46, 9, 15, 3, 42, 31, 13, 4, 12, 39, 22], - &[42, 45, 47, 18, 26, 41, 38, 9, 0, 35, 8, 16, 29, 36, 31], - &[3, 20, 29, 12, 46, 41, 23, 4, 9, 27], - &[19, 33], - &[32, 18], - &[17, 28, 7, 35, 6, 22, 4, 43], - &[41, 31, 20, 28, 35, 32, 24, 23, 0, 33, 18, 39, 29, 30, 16], - &[43, 47, 46], - ], - &[ - &[14], - &[], - &[26], - &[4, 47], - &[], - &[6], - &[39, 43, 46], - &[30], - &[], - &[], - &[0, 3], - &[], - &[], - &[], - &[], - &[27], - &[], - &[], - &[], - &[], - &[12], - &[], - &[], - &[41], - &[], - &[31], - &[20, 29], - &[13, 35], - &[18], - &[10, 40], - &[], - &[38], - &[], - &[], - &[19], - &[5], - &[], - &[], - &[11], - &[1], - &[15], - &[], - &[], - &[], - &[24], - &[], - &[], - &[], - &[], - ], - &[ - 2, 7, 8, 9, 16, 17, 21, 22, 23, 25, 28, 32, 33, 34, 36, 37, 42, 44, 45, 48, - ], - ), - 23185, - ), + EXTRA_TEST_CASE, ]; for ((status, candies, keys, contained_boxes, initial_boxes), expected) in test_cases { diff --git a/src/problem_1377_frog_position_after_t_seconds/dfs.rs b/src/problem_1377_frog_position_after_t_seconds/dfs.rs index 4c9c2649b..b3af03462 100644 --- a/src/problem_1377_frog_position_after_t_seconds/dfs.rs +++ b/src/problem_1377_frog_position_after_t_seconds/dfs.rs @@ -23,7 +23,7 @@ impl Solution { let children = context.tree[current].as_slice(); if children.len() != 1 { - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "optimal")] let child_probability = probability / (children.len() - 1) as f64; let child_step = step + 1; diff --git a/src/problem_1382_balance_a_binary_search_tree/iterator.rs b/src/problem_1382_balance_a_binary_search_tree/iterator.rs index a90972eb3..9c82d29d0 100644 --- a/src/problem_1382_balance_a_binary_search_tree/iterator.rs +++ b/src/problem_1382_balance_a_binary_search_tree/iterator.rs @@ -30,10 +30,9 @@ impl Solution { stack.push(node); } - stack.pop().map(|node| { - state.clone_from(&RefCell::borrow(&node).right); - node - }) + stack + .pop() + .inspect(|node| state.clone_from(&RefCell::borrow(node).right)) }) } diff --git a/src/problem_1383_maximum_performance_of_a_team/mod.rs b/src/problem_1383_maximum_performance_of_a_team/mod.rs index 4062f208e..dd28f6752 100644 --- a/src/problem_1383_maximum_performance_of_a_team/mod.rs +++ b/src/problem_1383_maximum_performance_of_a_team/mod.rs @@ -8,117 +8,117 @@ pub trait Solution { mod tests { use super::Solution; - #[allow(clippy::too_many_lines)] // Expected. + type TestCase<'a> = ((i32, &'a [i32], &'a [i32], i32), i32); + + const EXTRA_TEST_CASE: TestCase = ( + ( + 447, + &[ + 29_810, 40_211, 42_893, 41_516, 39_690, 43_822, 71_333, 75_889, 12_065, 28_857, 31_951, 9_481, 72_248, + 95_574, 2_820, 1_300, 98_400, 64_653, 20_209, 65_724, 10_107, 87_196, 23_537, 18_552, 40_059, 92_973, + 78_892, 16_555, 18_571, 94_717, 41_428, 88_107, 97_804, 26_927, 39_181, 70_451, 6_365, 87_528, 33_108, + 89_402, 56_384, 32_797, 57_593, 59_417, 51_867, 22_482, 63_673, 84_731, 74_791, 8_169, 46_524, 18_126, + 16_401, 33_963, 52_141, 52_571, 80_275, 30_610, 981, 69_298, 65_654, 57_452, 83_770, 29_587, 41_024, + 90_040, 29_500, 54_034, 73_454, 95_450, 36_075, 28_767, 9_379, 84_580, 20_902, 26_719, 39_154, 39_265, + 48_709, 91_919, 96_524, 77_933, 16_154, 67_365, 49_441, 20_419, 55_936, 74_648, 99_320, 64_885, 51_591, + 83_490, 50_329, 21_601, 95_669, 68_705, 33_448, 13_245, 96_588, 18_236, 86_471, 91_804, 58_335, 50_116, + 52_068, 42_660, 16_559, 63_959, 15_623, 78_733, 53_507, 86_575, 36_396, 49_657, 526, 69_254, 75_902, + 4_039, 79_381, 34_131, 22_657, 19_453, 26_274, 40_782, 99_277, 89_592, 22_018, 46_787, 55_046, 27_387, + 50_235, 37_231, 3_166, 74_621, 71_472, 88_332, 85_117, 9_855, 48_986, 40_797, 65_934, 46_769, 42_427, + 16_240, 94_106, 45_904, 70_687, 44_482, 89_577, 64_527, 84_892, 50_121, 72_993, 36_389, 78_403, 96_806, + 66_973, 60_501, 67_753, 97_601, 40_022, 22_324, 81_270, 69_594, 47_111, 462, 51_009, 55_820, 44_042, + 76_603, 91_686, 64_580, 83_933, 38_128, 2_724, 94_541, 20_459, 52_078, 23_351, 79_360, 45_804, 92_802, + 89_789, 39_803, 60_565, 63_511, 61_225, 5_950, 66_884, 97_616, 55_391, 46_554, 86_094, 2_588, 66_475, + 21_185, 12_197, 83_359, 36_150, 39_899, 69_219, 31_095, 35_268, 9_816, 68_577, 48_262, 67_046, 96_565, + 22_093, 85_599, 93_512, 35_359, 79_911, 30_424, 73_538, 22_592, 34_017, 43_208, 29_140, 79_948, 32_012, + 4_003, 52_770, 56_593, 35_271, 9_508, 95_988, 75_910, 76_210, 19_423, 34_339, 69_022, 18_170, 93_815, + 47_329, 98_485, 31_522, 94_131, 94_173, 40_042, 13_945, 52_037, 64_535, 24_480, 7_254, 3_052, 89_562, + 64_810, 69_277, 80_371, 44_885, 35_990, 80_379, 22_635, 29_107, 30_569, 58_959, 98_385, 30_372, 37_178, + 71_699, 51_065, 59_205, 33_801, 65_056, 14_542, 10_336, 2_021, 62_967, 50_220, 37_646, 52_420, 99_427, + 19_959, 1_990, 19_029, 71_117, 74_023, 33_315, 10_423, 85_480, 1_893, 70_384, 68_801, 5_612, 15_393, + 11_933, 3_621, 83_561, 97_599, 90_017, 86_903, 51_080, 82_715, 34_059, 83_311, 32_169, 77_061, 22_974, + 56_161, 91_496, 83_674, 7_970, 71_687, 70_530, 93_278, 55_591, 9_187, 35_009, 80_041, 98_594, 32_976, + 12_658, 7_696, 56_113, 6_923, 11_957, 61_495, 48_530, 40_985, 16_598, 4_350, 87_066, 51_799, 58_470, + 96_551, 35_389, 32_770, 11_245, 4_482, 7_624, 34_211, 96_367, 34_119, 15_354, 39_813, 55_684, 65_896, + 26_924, 44_390, 51_262, 63_066, 17_004, 58_801, 73_223, 76_201, 68_168, 3_968, 97_410, 26_212, 51_019, + 42_497, 53_675, 16_564, 8_502, 39_387, 69_951, 54_735, 41_786, 35_740, 98_139, 65_675, 68_961, 19_498, + 95_264, 42_935, 9_024, 36_650, 59_526, 97_208, 10_246, 7_354, 6_387, 64_511, 33_020, 92_133, 97_865, + 47_393, 48_515, 40_290, 78_416, 69_748, 21_994, 19_446, 90_079, 73_765, 14_780, 53_885, 81_226, 13_006, + 89_302, 93_672, 26_784, 8_753, 74_871, 84_022, 9_544, 84_311, 67_041, 2_864, 48_249, 93_098, 28_828, + 78_392, 30_831, 59_270, 48_125, 24_750, 95_135, 33_628, 26_394, 97_883, 49_902, 63_843, 52_920, 66_856, + 76_625, 5_259, 60_091, 24_873, 91_226, 84_159, 70_881, 39_670, 97_893, 71_176, 74_970, 37_029, 53_928, + 67_878, 79_007, 76_161, 59_313, 17_164, 58_220, 18_393, 21_361, 83_449, 55_598, 86_711, 4_752, 55_165, + 36_904, 98_437, 2_403, 11_801, 50_256, + ], + &[ + 52_409_144, 5_509_941, 25_073_597, 77_712_955, 32_997_178, 13_548_961, 82_059_612, 79_988_739, + 32_896_498, 2_734_556, 53_925_148, 35_978_917, 9_518_234, 10_083_751, 85_279_542, 39_033_408, + 48_209_851, 62_925_888, 13_547_194, 44_035_972, 68_353_067, 23_252_163, 20_073_998, 42_920_683, + 14_344_887, 69_035_996, 39_391_494, 27_748_248, 73_214_826, 4_262_748, 83_688_455, 74_215_897, + 92_555_899, 23_911_542, 58_067_690, 21_192_570, 95_942_114, 33_191_627, 8_645_527, 59_954_387, + 73_721_763, 72_662_479, 72_217_179, 1_458_481, 45_455_404, 34_624_026, 3_276_054, 55_926_364, + 2_538_189, 92_838_862, 77_855_755, 79_664_441, 18_588_592, 37_166_813, 75_708_455, 23_108_833, + 11_978_561, 65_229_374, 23_834_131, 42_579_452, 87_085_776, 92_142_233, 98_169_793, 31_994_108, + 66_447_473, 64_267_057, 95_676_586, 45_224_865, 82_045_517, 87_698_900, 86_760_377, 6_468_938, + 68_678_099, 49_484_751, 68_670_060, 41_849_361, 92_953_423, 74_130_846, 22_169_912, 94_123_667, + 62_381_496, 11_404_911, 81_350_059, 76_669_555, 23_659_351, 33_634_347, 29_208_286, 96_582_765, + 6_997_203, 91_487_697, 96_254_682, 46_705_288, 69_129_620, 73_044_360, 5_463_828, 12_133_523, + 84_348_931, 35_906_765, 11_236_700, 82_799_272, 92_157_812, 11_006_966, 32_345_170, 58_105_753, + 22_112_937, 58_804_673, 83_537_456, 28_456_190, 57_882_805, 71_679_588, 15_849_776, 39_658_053, + 33_315_038, 75_077_925, 25_479_720, 58_891_125, 2_823_227, 84_225_193, 32_512_794, 27_730_164, + 38_222_742, 72_791_567, 36_671_733, 78_616_435, 33_672_843, 59_914_327, 73_199_263, 65_875_307, + 16_347_721, 76_577_204, 27_490_709, 14_514_199, 15_847_293, 1_773_821, 39_783_827, 97_216_020, + 18_333_339, 67_158_723, 76_850_157, 58_675_855, 90_900_690, 70_919_839, 113_377, 59_366_425, + 60_337_868, 40_909_455, 53_606_930, 98_131_095, 76_694_029, 15_179_404, 50_675_006, 27_368_881, + 520_182, 85_299_790, 96_943_869, 97_761_582, 26_693_124, 80_642_358, 54_890_399, 95_580_346, + 94_340_555, 60_315_856, 89_770_242, 26_489_362, 70_624_121, 91_073_195, 77_758_531, 54_392_013, + 83_433_073, 98_493_102, 9_092_678, 33_236_521, 87_073_139, 84_513_597, 54_626_478, 84_458_121, + 85_058_138, 36_273_509, 9_853_306, 1_359_367, 35_511_764, 55_182_268, 73_047_564, 20_410_486, + 34_809_483, 22_766_268, 68_494_858, 36_348_909, 13_237_907, 79_273_853, 9_362_263, 8_992_441, + 59_389_134, 22_030_332, 95_327_344, 92_670_308, 53_945_290, 92_463_699, 81_200_910, 28_036_660, + 27_878_141, 44_821_397, 9_201_186, 93_844_369, 88_420_620, 62_805_392, 74_846_641, 6_676_310, + 39_846_057, 98_661_632, 74_657_575, 47_761_591, 99_300_303, 52_688_395, 53_648_926, 64_910_915, + 81_926_714, 96_106_913, 34_731_191, 94_850_369, 88_696_471, 83_544_102, 42_483_824, 33_343_240, + 25_488_064, 84_005_065, 22_230_419, 59_535_838, 97_743_772, 81_370_827, 61_658_488, 21_815_186, + 18_535_199, 59_147_254, 41_575_534, 53_788_561, 15_547_373, 27_674_242, 91_455_784, 9_157_169, + 30_550_600, 43_133_574, 13_418_312, 6_037_203, 80_196_915, 29_065_895, 4_659_159, 94_479_026, + 97_168_531, 59_362_807, 88_976_311, 15_846_699, 92_964_157, 12_781_669, 53_647_598, 66_440_847, + 50_720_111, 22_628_784, 31_640_052, 62_085_874, 77_837_256, 28_441_679, 95_956_960, 44_307_589, + 79_674_139, 28_702_153, 6_203_269, 701_612, 42_892_555, 77_880_342, 26_291_144, 21_483_953, 86_710_609, + 4_087_842, 51_978_739, 89_229_451, 7_666_475, 50_934_271, 17_445_468, 62_127_947, 40_721_868, + 4_760_655, 8_167_385, 17_304_056, 36_720_664, 58_050_499, 25_516_258, 67_063_506, 17_490_145, + 37_483_093, 25_759_943, 60_064_361, 44_265_676, 35_966_750, 86_114_542, 32_627_221, 8_077_773, + 79_254_965, 46_924_497, 81_249_071, 75_196_502, 70_084_709, 47_409_400, 55_384_949, 26_758_766, + 71_995_043, 88_903_900, 95_770_584, 99_761_764, 96_786_456, 9_701_824, 23_834_179, 20_268_187, + 27_292_708, 6_027_141, 85_513_177, 68_832_164, 67_260_236, 13_325_421, 5_384_539, 71_332_033, + 59_505_400, 17_207_132, 94_978_827, 3_304_402, 70_398_482, 12_130_142, 43_676_345, 40_512_228, + 51_571_311, 98_328_737, 42_037_891, 17_448_963, 51_027_324, 90_971_680, 12_624_314, 32_935_688, + 74_783_098, 44_306_234, 68_359_791, 78_401_987, 14_050_977, 87_587_125, 70_296_049, 96_553_750, + 94_125_049, 71_889_567, 39_101_099, 21_076_465, 49_707_787, 69_937_862, 13_070_135, 46_356_024, + 77_162_533, 5_848_487, 87_391_451, 42_097_414, 40_039_965, 47_327_338, 43_659_510, 69_806_991, + 1_155_797, 16_356_308, 42_561_888, 43_697_659, 76_921_522, 60_641_417, 64_383_955, 48_877_454, + 51_073_567, 77_707_695, 18_063_186, 70_291_398, 77_256_263, 32_932_323, 77_011_969, 45_452_682, + 86_369_228, 54_032_650, 62_353_742, 45_694_651, 68_121_148, 3_902_022, 33_571_278, 29_679_847, + 17_905_659, 24_776_639, 97_705_167, 6_724_984, 73_243_675, 35_665_572, 14_352_922, 35_124_454, + 84_844_541, 70_649_184, 10_535_657, 29_176_348, 23_268_960, 57_994_116, 79_236_664, 65_320_138, + 38_084_604, 26_895_286, 66_251_930, 57_102_138, 90_677_543, 73_078_374, 64_714_177, 9_756_702, + 54_668_275, 1_111_304, 71_402_264, 69_026_003, 10_255_970, 82_657_264, 77_615_576, 57_122_680, + 47_221_323, 859_161, 40_178_651, 92_789_343, 739_148, 16_112_120, 68_785_506, 42_352_675, 86_576_855, + 74_004_543, 70_548_491, 72_751_454, 54_801_202, 84_552_504, 41_306_769, 40_521_727, 67_956_765, + 78_687_514, 73_819_008, 33_922_695, 1_289_271, 98_802_406, 75_954_956, 49_440_866, 53_974_168, + 88_448_415, 89_882_431, 12_143_598, 646_710, 36_087_820, + ], + 238, + ), + 755_645_132, + ); + pub fn run() { let test_cases = [ ((6, &[2, 10, 3, 1, 5, 8] as &[_], &[5, 4, 3, 9, 7, 2] as &[_], 2), 60), ((6, &[2, 10, 3, 1, 5, 8], &[5, 4, 3, 9, 7, 2], 3), 68), ((6, &[2, 10, 3, 1, 5, 8], &[5, 4, 3, 9, 7, 2], 4), 72), - ( - ( - 447, - &[ - 29_810, 40_211, 42_893, 41_516, 39_690, 43_822, 71_333, 75_889, 12_065, 28_857, 31_951, 9_481, - 72_248, 95_574, 2_820, 1_300, 98_400, 64_653, 20_209, 65_724, 10_107, 87_196, 23_537, 18_552, - 40_059, 92_973, 78_892, 16_555, 18_571, 94_717, 41_428, 88_107, 97_804, 26_927, 39_181, 70_451, - 6_365, 87_528, 33_108, 89_402, 56_384, 32_797, 57_593, 59_417, 51_867, 22_482, 63_673, 84_731, - 74_791, 8_169, 46_524, 18_126, 16_401, 33_963, 52_141, 52_571, 80_275, 30_610, 981, 69_298, - 65_654, 57_452, 83_770, 29_587, 41_024, 90_040, 29_500, 54_034, 73_454, 95_450, 36_075, 28_767, - 9_379, 84_580, 20_902, 26_719, 39_154, 39_265, 48_709, 91_919, 96_524, 77_933, 16_154, 67_365, - 49_441, 20_419, 55_936, 74_648, 99_320, 64_885, 51_591, 83_490, 50_329, 21_601, 95_669, 68_705, - 33_448, 13_245, 96_588, 18_236, 86_471, 91_804, 58_335, 50_116, 52_068, 42_660, 16_559, 63_959, - 15_623, 78_733, 53_507, 86_575, 36_396, 49_657, 526, 69_254, 75_902, 4_039, 79_381, 34_131, - 22_657, 19_453, 26_274, 40_782, 99_277, 89_592, 22_018, 46_787, 55_046, 27_387, 50_235, 37_231, - 3_166, 74_621, 71_472, 88_332, 85_117, 9_855, 48_986, 40_797, 65_934, 46_769, 42_427, 16_240, - 94_106, 45_904, 70_687, 44_482, 89_577, 64_527, 84_892, 50_121, 72_993, 36_389, 78_403, 96_806, - 66_973, 60_501, 67_753, 97_601, 40_022, 22_324, 81_270, 69_594, 47_111, 462, 51_009, 55_820, - 44_042, 76_603, 91_686, 64_580, 83_933, 38_128, 2_724, 94_541, 20_459, 52_078, 23_351, 79_360, - 45_804, 92_802, 89_789, 39_803, 60_565, 63_511, 61_225, 5_950, 66_884, 97_616, 55_391, 46_554, - 86_094, 2_588, 66_475, 21_185, 12_197, 83_359, 36_150, 39_899, 69_219, 31_095, 35_268, 9_816, - 68_577, 48_262, 67_046, 96_565, 22_093, 85_599, 93_512, 35_359, 79_911, 30_424, 73_538, 22_592, - 34_017, 43_208, 29_140, 79_948, 32_012, 4_003, 52_770, 56_593, 35_271, 9_508, 95_988, 75_910, - 76_210, 19_423, 34_339, 69_022, 18_170, 93_815, 47_329, 98_485, 31_522, 94_131, 94_173, 40_042, - 13_945, 52_037, 64_535, 24_480, 7_254, 3_052, 89_562, 64_810, 69_277, 80_371, 44_885, 35_990, - 80_379, 22_635, 29_107, 30_569, 58_959, 98_385, 30_372, 37_178, 71_699, 51_065, 59_205, 33_801, - 65_056, 14_542, 10_336, 2_021, 62_967, 50_220, 37_646, 52_420, 99_427, 19_959, 1_990, 19_029, - 71_117, 74_023, 33_315, 10_423, 85_480, 1_893, 70_384, 68_801, 5_612, 15_393, 11_933, 3_621, - 83_561, 97_599, 90_017, 86_903, 51_080, 82_715, 34_059, 83_311, 32_169, 77_061, 22_974, 56_161, - 91_496, 83_674, 7_970, 71_687, 70_530, 93_278, 55_591, 9_187, 35_009, 80_041, 98_594, 32_976, - 12_658, 7_696, 56_113, 6_923, 11_957, 61_495, 48_530, 40_985, 16_598, 4_350, 87_066, 51_799, - 58_470, 96_551, 35_389, 32_770, 11_245, 4_482, 7_624, 34_211, 96_367, 34_119, 15_354, 39_813, - 55_684, 65_896, 26_924, 44_390, 51_262, 63_066, 17_004, 58_801, 73_223, 76_201, 68_168, 3_968, - 97_410, 26_212, 51_019, 42_497, 53_675, 16_564, 8_502, 39_387, 69_951, 54_735, 41_786, 35_740, - 98_139, 65_675, 68_961, 19_498, 95_264, 42_935, 9_024, 36_650, 59_526, 97_208, 10_246, 7_354, - 6_387, 64_511, 33_020, 92_133, 97_865, 47_393, 48_515, 40_290, 78_416, 69_748, 21_994, 19_446, - 90_079, 73_765, 14_780, 53_885, 81_226, 13_006, 89_302, 93_672, 26_784, 8_753, 74_871, 84_022, - 9_544, 84_311, 67_041, 2_864, 48_249, 93_098, 28_828, 78_392, 30_831, 59_270, 48_125, 24_750, - 95_135, 33_628, 26_394, 97_883, 49_902, 63_843, 52_920, 66_856, 76_625, 5_259, 60_091, 24_873, - 91_226, 84_159, 70_881, 39_670, 97_893, 71_176, 74_970, 37_029, 53_928, 67_878, 79_007, 76_161, - 59_313, 17_164, 58_220, 18_393, 21_361, 83_449, 55_598, 86_711, 4_752, 55_165, 36_904, 98_437, - 2_403, 11_801, 50_256, - ], - &[ - 52_409_144, 5_509_941, 25_073_597, 77_712_955, 32_997_178, 13_548_961, 82_059_612, 79_988_739, - 32_896_498, 2_734_556, 53_925_148, 35_978_917, 9_518_234, 10_083_751, 85_279_542, 39_033_408, - 48_209_851, 62_925_888, 13_547_194, 44_035_972, 68_353_067, 23_252_163, 20_073_998, 42_920_683, - 14_344_887, 69_035_996, 39_391_494, 27_748_248, 73_214_826, 4_262_748, 83_688_455, 74_215_897, - 92_555_899, 23_911_542, 58_067_690, 21_192_570, 95_942_114, 33_191_627, 8_645_527, 59_954_387, - 73_721_763, 72_662_479, 72_217_179, 1_458_481, 45_455_404, 34_624_026, 3_276_054, 55_926_364, - 2_538_189, 92_838_862, 77_855_755, 79_664_441, 18_588_592, 37_166_813, 75_708_455, 23_108_833, - 11_978_561, 65_229_374, 23_834_131, 42_579_452, 87_085_776, 92_142_233, 98_169_793, 31_994_108, - 66_447_473, 64_267_057, 95_676_586, 45_224_865, 82_045_517, 87_698_900, 86_760_377, 6_468_938, - 68_678_099, 49_484_751, 68_670_060, 41_849_361, 92_953_423, 74_130_846, 22_169_912, 94_123_667, - 62_381_496, 11_404_911, 81_350_059, 76_669_555, 23_659_351, 33_634_347, 29_208_286, 96_582_765, - 6_997_203, 91_487_697, 96_254_682, 46_705_288, 69_129_620, 73_044_360, 5_463_828, 12_133_523, - 84_348_931, 35_906_765, 11_236_700, 82_799_272, 92_157_812, 11_006_966, 32_345_170, 58_105_753, - 22_112_937, 58_804_673, 83_537_456, 28_456_190, 57_882_805, 71_679_588, 15_849_776, 39_658_053, - 33_315_038, 75_077_925, 25_479_720, 58_891_125, 2_823_227, 84_225_193, 32_512_794, 27_730_164, - 38_222_742, 72_791_567, 36_671_733, 78_616_435, 33_672_843, 59_914_327, 73_199_263, 65_875_307, - 16_347_721, 76_577_204, 27_490_709, 14_514_199, 15_847_293, 1_773_821, 39_783_827, 97_216_020, - 18_333_339, 67_158_723, 76_850_157, 58_675_855, 90_900_690, 70_919_839, 113_377, 59_366_425, - 60_337_868, 40_909_455, 53_606_930, 98_131_095, 76_694_029, 15_179_404, 50_675_006, 27_368_881, - 520_182, 85_299_790, 96_943_869, 97_761_582, 26_693_124, 80_642_358, 54_890_399, 95_580_346, - 94_340_555, 60_315_856, 89_770_242, 26_489_362, 70_624_121, 91_073_195, 77_758_531, 54_392_013, - 83_433_073, 98_493_102, 9_092_678, 33_236_521, 87_073_139, 84_513_597, 54_626_478, 84_458_121, - 85_058_138, 36_273_509, 9_853_306, 1_359_367, 35_511_764, 55_182_268, 73_047_564, 20_410_486, - 34_809_483, 22_766_268, 68_494_858, 36_348_909, 13_237_907, 79_273_853, 9_362_263, 8_992_441, - 59_389_134, 22_030_332, 95_327_344, 92_670_308, 53_945_290, 92_463_699, 81_200_910, 28_036_660, - 27_878_141, 44_821_397, 9_201_186, 93_844_369, 88_420_620, 62_805_392, 74_846_641, 6_676_310, - 39_846_057, 98_661_632, 74_657_575, 47_761_591, 99_300_303, 52_688_395, 53_648_926, 64_910_915, - 81_926_714, 96_106_913, 34_731_191, 94_850_369, 88_696_471, 83_544_102, 42_483_824, 33_343_240, - 25_488_064, 84_005_065, 22_230_419, 59_535_838, 97_743_772, 81_370_827, 61_658_488, 21_815_186, - 18_535_199, 59_147_254, 41_575_534, 53_788_561, 15_547_373, 27_674_242, 91_455_784, 9_157_169, - 30_550_600, 43_133_574, 13_418_312, 6_037_203, 80_196_915, 29_065_895, 4_659_159, 94_479_026, - 97_168_531, 59_362_807, 88_976_311, 15_846_699, 92_964_157, 12_781_669, 53_647_598, 66_440_847, - 50_720_111, 22_628_784, 31_640_052, 62_085_874, 77_837_256, 28_441_679, 95_956_960, 44_307_589, - 79_674_139, 28_702_153, 6_203_269, 701_612, 42_892_555, 77_880_342, 26_291_144, 21_483_953, - 86_710_609, 4_087_842, 51_978_739, 89_229_451, 7_666_475, 50_934_271, 17_445_468, 62_127_947, - 40_721_868, 4_760_655, 8_167_385, 17_304_056, 36_720_664, 58_050_499, 25_516_258, 67_063_506, - 17_490_145, 37_483_093, 25_759_943, 60_064_361, 44_265_676, 35_966_750, 86_114_542, 32_627_221, - 8_077_773, 79_254_965, 46_924_497, 81_249_071, 75_196_502, 70_084_709, 47_409_400, 55_384_949, - 26_758_766, 71_995_043, 88_903_900, 95_770_584, 99_761_764, 96_786_456, 9_701_824, 23_834_179, - 20_268_187, 27_292_708, 6_027_141, 85_513_177, 68_832_164, 67_260_236, 13_325_421, 5_384_539, - 71_332_033, 59_505_400, 17_207_132, 94_978_827, 3_304_402, 70_398_482, 12_130_142, 43_676_345, - 40_512_228, 51_571_311, 98_328_737, 42_037_891, 17_448_963, 51_027_324, 90_971_680, 12_624_314, - 32_935_688, 74_783_098, 44_306_234, 68_359_791, 78_401_987, 14_050_977, 87_587_125, 70_296_049, - 96_553_750, 94_125_049, 71_889_567, 39_101_099, 21_076_465, 49_707_787, 69_937_862, 13_070_135, - 46_356_024, 77_162_533, 5_848_487, 87_391_451, 42_097_414, 40_039_965, 47_327_338, 43_659_510, - 69_806_991, 1_155_797, 16_356_308, 42_561_888, 43_697_659, 76_921_522, 60_641_417, 64_383_955, - 48_877_454, 51_073_567, 77_707_695, 18_063_186, 70_291_398, 77_256_263, 32_932_323, 77_011_969, - 45_452_682, 86_369_228, 54_032_650, 62_353_742, 45_694_651, 68_121_148, 3_902_022, 33_571_278, - 29_679_847, 17_905_659, 24_776_639, 97_705_167, 6_724_984, 73_243_675, 35_665_572, 14_352_922, - 35_124_454, 84_844_541, 70_649_184, 10_535_657, 29_176_348, 23_268_960, 57_994_116, 79_236_664, - 65_320_138, 38_084_604, 26_895_286, 66_251_930, 57_102_138, 90_677_543, 73_078_374, 64_714_177, - 9_756_702, 54_668_275, 1_111_304, 71_402_264, 69_026_003, 10_255_970, 82_657_264, 77_615_576, - 57_122_680, 47_221_323, 859_161, 40_178_651, 92_789_343, 739_148, 16_112_120, 68_785_506, - 42_352_675, 86_576_855, 74_004_543, 70_548_491, 72_751_454, 54_801_202, 84_552_504, 41_306_769, - 40_521_727, 67_956_765, 78_687_514, 73_819_008, 33_922_695, 1_289_271, 98_802_406, 75_954_956, - 49_440_866, 53_974_168, 88_448_415, 89_882_431, 12_143_598, 646_710, 36_087_820, - ], - 238, - ), - 755_645_132, - ), + EXTRA_TEST_CASE, ]; for ((n, speed, efficiency, k), expected) in test_cases { diff --git a/src/problem_1396_design_underground_system/standard.rs b/src/problem_1396_design_underground_system/standard.rs index cb55d676a..065756eae 100644 --- a/src/problem_1396_design_underground_system/standard.rs +++ b/src/problem_1396_design_underground_system/standard.rs @@ -55,7 +55,7 @@ impl UndergroundSystem { }); } - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "optimal")] fn get_average_time(&self, start_station: String, end_station: String) -> f64 { let start_station = Self::get_station_name(start_station); let end_station = Self::get_station_name(end_station); diff --git a/src/problem_1410_html_entity_parser/state_machine.rs b/src/problem_1410_html_entity_parser/state_machine.rs index e026798fe..00190e538 100644 --- a/src/problem_1410_html_entity_parser/state_machine.rs +++ b/src/problem_1410_html_entity_parser/state_machine.rs @@ -27,7 +27,7 @@ enum State { } impl Solution { - #[allow(clippy::too_many_lines)] // Expected. + #[expect(clippy::too_many_lines, reason = "optimal")] pub fn entity_parser(text: String) -> String { let mut result = Vec::new(); let mut state = State::NotAnd; diff --git a/src/problem_1467_probability_of_a_two_boxes_having_the_same_number_of_distinct_balls/dynamic_programming.rs b/src/problem_1467_probability_of_a_two_boxes_having_the_same_number_of_distinct_balls/dynamic_programming.rs index 962cd9f30..115675491 100644 --- a/src/problem_1467_probability_of_a_two_boxes_having_the_same_number_of_distinct_balls/dynamic_programming.rs +++ b/src/problem_1467_probability_of_a_two_boxes_having_the_same_number_of_distinct_balls/dynamic_programming.rs @@ -27,7 +27,6 @@ impl Solution { result } - #[allow(clippy::cast_precision_loss)] // Expected. pub fn get_probability(balls: Vec) -> f64 { const MAX_COLORS: usize = 8; const MAX_BALLS_PER_COLOR: usize = 6; @@ -83,7 +82,10 @@ impl Solution { let good_count = cache[columns * max_left_balls + total_colors]; let total_count = combinations[combinations_columns * total_balls + max_left_balls]; - good_count as f64 / total_count as f64 + #[expect(clippy::cast_precision_loss, reason = "optimal")] + let result = good_count as f64 / total_count as f64; + + result } } diff --git a/src/problem_1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/mod.rs b/src/problem_1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/mod.rs index b6b6137ed..cafdbd927 100644 --- a/src/problem_1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/mod.rs +++ b/src/problem_1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/mod.rs @@ -9,7 +9,110 @@ mod tests { use super::Solution; use crate::test_utilities; - #[allow(clippy::too_many_lines)] // Expected. + type TestCase<'a> = ((i32, &'a [[i32; 3]]), (&'a [i32], &'a [i32])); + + const EXTRA_TEST_CASE: TestCase = ( + ( + 14, + &[ + [0, 1, 13], + [0, 2, 6], + [2, 3, 13], + [3, 4, 4], + [0, 5, 11], + [4, 6, 14], + [4, 7, 8], + [2, 8, 6], + [4, 9, 6], + [7, 10, 4], + [5, 11, 3], + [6, 12, 7], + [12, 13, 9], + [7, 13, 2], + [5, 13, 10], + [0, 6, 4], + [2, 7, 3], + [0, 7, 8], + [1, 12, 9], + [10, 12, 11], + [1, 2, 7], + [1, 3, 10], + [3, 10, 6], + [6, 10, 4], + [4, 8, 5], + [1, 13, 4], + [11, 13, 8], + [2, 12, 10], + [5, 8, 1], + [3, 7, 6], + [7, 12, 12], + [1, 7, 9], + [5, 9, 1], + [2, 13, 10], + [10, 11, 4], + [3, 5, 10], + [6, 11, 14], + [5, 12, 3], + [0, 8, 13], + [8, 9, 1], + [3, 6, 8], + [0, 3, 4], + [2, 9, 6], + [0, 11, 4], + [2, 5, 14], + [4, 11, 2], + [7, 11, 11], + [1, 11, 6], + [2, 10, 12], + [0, 13, 4], + [3, 9, 9], + [4, 12, 3], + [6, 7, 10], + [6, 8, 13], + [9, 11, 3], + [1, 6, 2], + [2, 4, 12], + [0, 10, 3], + [3, 12, 1], + [3, 8, 12], + [1, 8, 6], + [8, 13, 2], + [10, 13, 12], + [9, 13, 11], + [2, 11, 14], + [5, 10, 9], + [5, 6, 10], + [2, 6, 9], + [4, 10, 7], + [3, 13, 10], + [4, 13, 3], + [3, 11, 9], + [7, 9, 14], + [6, 9, 5], + [1, 5, 12], + [4, 5, 3], + [11, 12, 3], + [0, 4, 8], + [5, 7, 8], + [9, 12, 13], + [8, 12, 12], + [1, 10, 6], + [1, 9, 9], + [7, 8, 9], + [9, 10, 13], + [8, 11, 3], + [6, 13, 7], + [0, 12, 10], + [1, 4, 8], + [8, 10, 2], + ], + ), + ( + &[13, 16, 45, 55, 57, 58, 61, 89], + &[10, 15, 23, 25, 28, 32, 37, 39, 51, 54, 70, 75, 76, 85], + ), + ); + pub fn run() { let test_cases = [ ( @@ -28,107 +131,7 @@ mod tests { (&[0, 1] as &[_], &[2, 3, 4, 5] as &[_]), ), ((4, &[[0, 1, 1], [1, 2, 1], [2, 3, 1], [0, 3, 1]]), (&[], &[0, 1, 2, 3])), - ( - ( - 14, - &[ - [0, 1, 13], - [0, 2, 6], - [2, 3, 13], - [3, 4, 4], - [0, 5, 11], - [4, 6, 14], - [4, 7, 8], - [2, 8, 6], - [4, 9, 6], - [7, 10, 4], - [5, 11, 3], - [6, 12, 7], - [12, 13, 9], - [7, 13, 2], - [5, 13, 10], - [0, 6, 4], - [2, 7, 3], - [0, 7, 8], - [1, 12, 9], - [10, 12, 11], - [1, 2, 7], - [1, 3, 10], - [3, 10, 6], - [6, 10, 4], - [4, 8, 5], - [1, 13, 4], - [11, 13, 8], - [2, 12, 10], - [5, 8, 1], - [3, 7, 6], - [7, 12, 12], - [1, 7, 9], - [5, 9, 1], - [2, 13, 10], - [10, 11, 4], - [3, 5, 10], - [6, 11, 14], - [5, 12, 3], - [0, 8, 13], - [8, 9, 1], - [3, 6, 8], - [0, 3, 4], - [2, 9, 6], - [0, 11, 4], - [2, 5, 14], - [4, 11, 2], - [7, 11, 11], - [1, 11, 6], - [2, 10, 12], - [0, 13, 4], - [3, 9, 9], - [4, 12, 3], - [6, 7, 10], - [6, 8, 13], - [9, 11, 3], - [1, 6, 2], - [2, 4, 12], - [0, 10, 3], - [3, 12, 1], - [3, 8, 12], - [1, 8, 6], - [8, 13, 2], - [10, 13, 12], - [9, 13, 11], - [2, 11, 14], - [5, 10, 9], - [5, 6, 10], - [2, 6, 9], - [4, 10, 7], - [3, 13, 10], - [4, 13, 3], - [3, 11, 9], - [7, 9, 14], - [6, 9, 5], - [1, 5, 12], - [4, 5, 3], - [11, 12, 3], - [0, 4, 8], - [5, 7, 8], - [9, 12, 13], - [8, 12, 12], - [1, 10, 6], - [1, 9, 9], - [7, 8, 9], - [9, 10, 13], - [8, 11, 3], - [6, 13, 7], - [0, 12, 10], - [1, 4, 8], - [8, 10, 2], - ], - ), - ( - &[13, 16, 45, 55, 57, 58, 61, 89], - &[10, 15, 23, 25, 28, 32, 37, 39, 51, 54, 70, 75, 76, 85], - ), - ), + EXTRA_TEST_CASE, ]; for ((n, edges), (expected_critical_edges, expected_pseudo_critical_edges)) in test_cases { diff --git a/src/problem_1491_average_salary_excluding_the_minimum_and_maximum_salary/iterative.rs b/src/problem_1491_average_salary_excluding_the_minimum_and_maximum_salary/iterative.rs index 76037ba1e..ecf22fa52 100644 --- a/src/problem_1491_average_salary_excluding_the_minimum_and_maximum_salary/iterative.rs +++ b/src/problem_1491_average_salary_excluding_the_minimum_and_maximum_salary/iterative.rs @@ -3,7 +3,6 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::cast_precision_loss)] // Expected. pub fn average(salary: Vec) -> f64 { let mut iter = salary.iter().copied(); let mut min = iter.next().unwrap(); @@ -20,7 +19,10 @@ impl Solution { } } - f64::from(sum - min - max) / ((salary.len() - 2) as f64) + #[expect(clippy::cast_precision_loss, reason = "optimal")] + let result = f64::from(sum - min - max) / ((salary.len() - 2) as f64); + + result } } diff --git a/src/problem_1514_path_with_maximum_probability/mod.rs b/src/problem_1514_path_with_maximum_probability/mod.rs index 29f9f3281..4ecd186fc 100644 --- a/src/problem_1514_path_with_maximum_probability/mod.rs +++ b/src/problem_1514_path_with_maximum_probability/mod.rs @@ -9,7 +9,219 @@ pub trait Solution { mod tests { use super::Solution; - #[allow(clippy::too_many_lines)] // Expected. + type TestCase<'a> = ((i32, &'a [[i32; 2]], &'a [f64], i32, i32), f64); + + const EXTRA_TEST_CASE: TestCase = ( + ( + 20, + &[ + [0, 9], + [6, 11], + [4, 17], + [8, 12], + [14, 17], + [4, 0], + [8, 19], + [2, 8], + [7, 3], + [10, 17], + [12, 19], + [13, 1], + [0, 16], + [1, 12], + [6, 10], + [9, 14], + [2, 3], + [1, 11], + [17, 19], + [4, 18], + [11, 4], + [0, 7], + [2, 10], + [7, 12], + [5, 10], + [12, 14], + [14, 19], + [9, 10], + [10, 12], + [19, 10], + [10, 13], + [19, 3], + [15, 11], + [16, 2], + [15, 7], + [13, 9], + [16, 3], + [15, 1], + [13, 18], + [9, 5], + [0, 8], + [6, 4], + [1, 2], + [0, 11], + [7, 2], + [17, 8], + [10, 18], + [5, 12], + [6, 7], + [7, 16], + [14, 11], + [12, 13], + [6, 8], + [2, 6], + [9, 11], + [16, 10], + [13, 6], + [3, 8], + [14, 4], + [15, 6], + [15, 18], + [1, 4], + [4, 8], + [3, 9], + [5, 3], + [4, 12], + [11, 7], + [10, 0], + [14, 1], + [2, 0], + [12, 6], + [1, 0], + [5, 16], + [2, 5], + [10, 4], + [10, 11], + [2, 18], + [15, 5], + [19, 9], + [8, 9], + [17, 1], + [2, 15], + [15, 10], + [6, 16], + [5, 14], + [3, 6], + [8, 10], + [12, 18], + [6, 1], + [18, 0], + [15, 8], + [11, 16], + [5, 19], + [0, 19], + [17, 3], + [9, 17], + [16, 15], + [3, 11], + [12, 9], + [4, 2], + [14, 7], + [19, 16], + [2, 14], + [18, 7], + [3, 13], + [5, 1], + [1, 7], + [9, 1], + [1, 16], + [7, 13], + [16, 8], + [5, 6], + [13, 2], + [15, 3], + [14, 10], + [3, 18], + [0, 15], + [14, 16], + [5, 18], + [16, 4], + [0, 14], + [7, 19], + [6, 19], + [18, 19], + [8, 18], + [17, 16], + [11, 5], + [5, 4], + [2, 11], + [19, 11], + [0, 13], + [6, 0], + [9, 2], + [18, 16], + [11, 18], + [2, 17], + [7, 8], + [7, 5], + [11, 17], + [3, 4], + [9, 4], + [13, 14], + [13, 15], + [19, 15], + [1, 10], + [18, 9], + [9, 7], + [4, 15], + [14, 8], + [1, 8], + [3, 10], + [19, 4], + [19, 2], + [8, 5], + [0, 17], + [11, 8], + [15, 12], + [12, 0], + [0, 3], + [17, 5], + [17, 12], + [1, 19], + [5, 0], + [7, 17], + [13, 11], + [10, 7], + [6, 17], + [11, 12], + [13, 4], + [18, 17], + [16, 9], + [13, 8], + [15, 9], + [13, 5], + [15, 14], + [18, 14], + [13, 16], + [1, 3], + [1, 18], + [14, 6], + [16, 12], + [6, 18], + [6, 9], + ], + &[ + 0.8034, 0.4845, 0.9491, 0.275, 0.4748, 0.6327, 0.204, 0.141, 0.2436, 0.1634, 0.6329, 0.9277, 0.8033, + 0.8569, 0.7035, 0.6623, 0.9642, 0.2587, 0.493, 0.9525, 0.8741, 0.1064, 0.1258, 0.5924, 0.4279, 0.7027, + 0.1997, 0.6898, 0.3876, 0.4882, 0.755, 0.8104, 0.2179, 0.4137, 0.7009, 0.1513, 0.0125, 0.9724, 0.1166, + 0.2216, 0.746, 0.3061, 0.8231, 0.8261, 0.0872, 0.7748, 0.6571, 0.2954, 0.2594, 0.9896, 0.2086, 0.8478, + 0.0801, 0.8931, 0.5456, 0.6698, 0.3146, 0.0913, 0.4775, 0.5485, 0.5276, 0.2652, 0.0003, 0.9899, 0.7481, + 0.1121, 0.3518, 0.9968, 0.0462, 0.8877, 0.4986, 0.6148, 0.7025, 0.4006, 0.5022, 0.5113, 0.7362, 0.7995, + 0.3859, 0.3093, 0.9112, 0.7292, 0.2118, 0.1951, 0.4578, 0.12, 0.7304, 0.0004, 0.9045, 0.3064, 0.7647, + 0.694, 0.9022, 0.0632, 0.9982, 0.5049, 0.98, 0.0235, 0.068, 0.0751, 0.8295, 0.0834, 0.5588, 0.0343, + 0.2307, 0.107, 0.9371, 0.7282, 0.6736, 0.2076, 0.0991, 0.8601, 0.6118, 0.4578, 0.2787, 0.4349, 0.8452, + 0.3591, 0.8005, 0.3297, 0.6573, 0.591, 0.6822, 0.2518, 0.6538, 0.6176, 0.9352, 0.8758, 0.4037, 0.7785, + 0.7201, 0.4327, 0.1664, 0.9889, 0.4662, 0.9246, 0.0998, 0.9905, 0.978, 0.405, 0.206, 0.1661, 0.8647, + 0.1496, 0.6509, 0.7509, 0.0974, 0.2403, 0.0641, 0.8365, 0.0142, 0.3892, 0.794, 0.9198, 0.027, 0.3786, + 0.8792, 0.6103, 0.2488, 0.5838, 0.2196, 0.9787, 0.3474, 0.1726, 0.8073, 0.7203, 0.2355, 0.057, 0.244, + 0.0731, 0.2281, 0.0484, 0.5085, 0.1538, 0.9677, 0.6539, 0.8041, 0.9386, 0.9208, 0.0653, 0.4476, 0.3843, + 0.7323, + ], + 10, + 18, + ), + 0.816_480_788_273_92, + ); + pub fn run() { let test_cases = [ ( @@ -51,217 +263,7 @@ mod tests { ), 0.95, ), - ( - ( - 20, - &[ - [0, 9], - [6, 11], - [4, 17], - [8, 12], - [14, 17], - [4, 0], - [8, 19], - [2, 8], - [7, 3], - [10, 17], - [12, 19], - [13, 1], - [0, 16], - [1, 12], - [6, 10], - [9, 14], - [2, 3], - [1, 11], - [17, 19], - [4, 18], - [11, 4], - [0, 7], - [2, 10], - [7, 12], - [5, 10], - [12, 14], - [14, 19], - [9, 10], - [10, 12], - [19, 10], - [10, 13], - [19, 3], - [15, 11], - [16, 2], - [15, 7], - [13, 9], - [16, 3], - [15, 1], - [13, 18], - [9, 5], - [0, 8], - [6, 4], - [1, 2], - [0, 11], - [7, 2], - [17, 8], - [10, 18], - [5, 12], - [6, 7], - [7, 16], - [14, 11], - [12, 13], - [6, 8], - [2, 6], - [9, 11], - [16, 10], - [13, 6], - [3, 8], - [14, 4], - [15, 6], - [15, 18], - [1, 4], - [4, 8], - [3, 9], - [5, 3], - [4, 12], - [11, 7], - [10, 0], - [14, 1], - [2, 0], - [12, 6], - [1, 0], - [5, 16], - [2, 5], - [10, 4], - [10, 11], - [2, 18], - [15, 5], - [19, 9], - [8, 9], - [17, 1], - [2, 15], - [15, 10], - [6, 16], - [5, 14], - [3, 6], - [8, 10], - [12, 18], - [6, 1], - [18, 0], - [15, 8], - [11, 16], - [5, 19], - [0, 19], - [17, 3], - [9, 17], - [16, 15], - [3, 11], - [12, 9], - [4, 2], - [14, 7], - [19, 16], - [2, 14], - [18, 7], - [3, 13], - [5, 1], - [1, 7], - [9, 1], - [1, 16], - [7, 13], - [16, 8], - [5, 6], - [13, 2], - [15, 3], - [14, 10], - [3, 18], - [0, 15], - [14, 16], - [5, 18], - [16, 4], - [0, 14], - [7, 19], - [6, 19], - [18, 19], - [8, 18], - [17, 16], - [11, 5], - [5, 4], - [2, 11], - [19, 11], - [0, 13], - [6, 0], - [9, 2], - [18, 16], - [11, 18], - [2, 17], - [7, 8], - [7, 5], - [11, 17], - [3, 4], - [9, 4], - [13, 14], - [13, 15], - [19, 15], - [1, 10], - [18, 9], - [9, 7], - [4, 15], - [14, 8], - [1, 8], - [3, 10], - [19, 4], - [19, 2], - [8, 5], - [0, 17], - [11, 8], - [15, 12], - [12, 0], - [0, 3], - [17, 5], - [17, 12], - [1, 19], - [5, 0], - [7, 17], - [13, 11], - [10, 7], - [6, 17], - [11, 12], - [13, 4], - [18, 17], - [16, 9], - [13, 8], - [15, 9], - [13, 5], - [15, 14], - [18, 14], - [13, 16], - [1, 3], - [1, 18], - [14, 6], - [16, 12], - [6, 18], - [6, 9], - ], - &[ - 0.8034, 0.4845, 0.9491, 0.275, 0.4748, 0.6327, 0.204, 0.141, 0.2436, 0.1634, 0.6329, 0.9277, - 0.8033, 0.8569, 0.7035, 0.6623, 0.9642, 0.2587, 0.493, 0.9525, 0.8741, 0.1064, 0.1258, 0.5924, - 0.4279, 0.7027, 0.1997, 0.6898, 0.3876, 0.4882, 0.755, 0.8104, 0.2179, 0.4137, 0.7009, 0.1513, - 0.0125, 0.9724, 0.1166, 0.2216, 0.746, 0.3061, 0.8231, 0.8261, 0.0872, 0.7748, 0.6571, 0.2954, - 0.2594, 0.9896, 0.2086, 0.8478, 0.0801, 0.8931, 0.5456, 0.6698, 0.3146, 0.0913, 0.4775, 0.5485, - 0.5276, 0.2652, 0.0003, 0.9899, 0.7481, 0.1121, 0.3518, 0.9968, 0.0462, 0.8877, 0.4986, 0.6148, - 0.7025, 0.4006, 0.5022, 0.5113, 0.7362, 0.7995, 0.3859, 0.3093, 0.9112, 0.7292, 0.2118, 0.1951, - 0.4578, 0.12, 0.7304, 0.0004, 0.9045, 0.3064, 0.7647, 0.694, 0.9022, 0.0632, 0.9982, 0.5049, - 0.98, 0.0235, 0.068, 0.0751, 0.8295, 0.0834, 0.5588, 0.0343, 0.2307, 0.107, 0.9371, 0.7282, - 0.6736, 0.2076, 0.0991, 0.8601, 0.6118, 0.4578, 0.2787, 0.4349, 0.8452, 0.3591, 0.8005, 0.3297, - 0.6573, 0.591, 0.6822, 0.2518, 0.6538, 0.6176, 0.9352, 0.8758, 0.4037, 0.7785, 0.7201, 0.4327, - 0.1664, 0.9889, 0.4662, 0.9246, 0.0998, 0.9905, 0.978, 0.405, 0.206, 0.1661, 0.8647, 0.1496, - 0.6509, 0.7509, 0.0974, 0.2403, 0.0641, 0.8365, 0.0142, 0.3892, 0.794, 0.9198, 0.027, 0.3786, - 0.8792, 0.6103, 0.2488, 0.5838, 0.2196, 0.9787, 0.3474, 0.1726, 0.8073, 0.7203, 0.2355, 0.057, - 0.244, 0.0731, 0.2281, 0.0484, 0.5085, 0.1538, 0.9677, 0.6539, 0.8041, 0.9386, 0.9208, 0.0653, - 0.4476, 0.3843, 0.7323, - ], - 10, - 18, - ), - 0.816_480_788_273_92, - ), + EXTRA_TEST_CASE, ]; for ((n, edges, succ_prob, start, end), expected) in test_cases { diff --git a/src/problem_1619_mean_of_array_after_removing_some_elements/quick_select.rs b/src/problem_1619_mean_of_array_after_removing_some_elements/quick_select.rs index af01a110d..2fded2e34 100644 --- a/src/problem_1619_mean_of_array_after_removing_some_elements/quick_select.rs +++ b/src/problem_1619_mean_of_array_after_removing_some_elements/quick_select.rs @@ -5,7 +5,6 @@ pub struct Solution; use std::cmp::Reverse; impl Solution { - #[allow(clippy::cast_precision_loss)] // Expected. pub fn trim_mean(arr: Vec) -> f64 { let mut arr = arr; let split = arr.len() / 20 - 1; @@ -16,7 +15,10 @@ impl Solution { .select_nth_unstable_by_key(split, |&value| Reverse(value)) .2; - f64::from(remaining.iter().sum::()) / remaining.len() as f64 + #[expect(clippy::cast_precision_loss, reason = "optimal")] + let result = f64::from(remaining.iter().sum::()) / remaining.len() as f64; + + result } } diff --git a/src/problem_1701_average_waiting_time/greedy.rs b/src/problem_1701_average_waiting_time/greedy.rs index 9284b2d7b..c0450881c 100644 --- a/src/problem_1701_average_waiting_time/greedy.rs +++ b/src/problem_1701_average_waiting_time/greedy.rs @@ -15,7 +15,7 @@ impl Solution { total_waiting_time += i64::from(free_time - arrival); } - #[allow(clippy::cast_precision_loss)] // Expected. + #[expect(clippy::cast_precision_loss, reason = "optimal")] let result = (total_waiting_time as f64) / (n as f64); result diff --git a/src/problem_1739_building_boxes/mathematical.rs b/src/problem_1739_building_boxes/mathematical.rs index ffd9a90c3..026e66d7a 100644 --- a/src/problem_1739_building_boxes/mathematical.rs +++ b/src/problem_1739_building_boxes/mathematical.rs @@ -5,10 +5,12 @@ pub struct Solution; // See . impl Solution { - #[allow(clippy::cast_precision_loss)] pub fn minimum_boxes(n: i32) -> i32 { let mut n = u64::from(n as u32); + + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mut h = ((n * 6) as f64).cbrt() as u64; + let mut full_box_count = h * (h + 1) * (h + 2) / 6; if full_box_count > n { @@ -20,6 +22,7 @@ impl Solution { n -= full_box_count; + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mut extra_count = ((n * 2) as f64).sqrt() as u64; if extra_count * (extra_count + 1) / 2 < n { diff --git a/src/problem_1802_maximum_value_at_a_given_index_in_a_bounded_array/mathematical.rs b/src/problem_1802_maximum_value_at_a_given_index_in_a_bounded_array/mathematical.rs index 524b82cff..9a06b36a2 100644 --- a/src/problem_1802_maximum_value_at_a_given_index_in_a_bounded_array/mathematical.rs +++ b/src/problem_1802_maximum_value_at_a_given_index_in_a_bounded_array/mathematical.rs @@ -7,7 +7,6 @@ impl Solution { (start + end) * (end + 1 - start) / 2 } - #[allow(clippy::cast_precision_loss)] // Expected. pub fn max_value(n: i32, index: i32, max_sum: i32) -> i32 { let n = n as u32; let index = index as u32; @@ -23,6 +22,7 @@ impl Solution { let threshold = Self::get_area(1, n_u64 - index_u64) + Self::get_area(n_u64 - index_u64 * 2, n_u64 - index_u64 - 1); + #[expect(clippy::cast_precision_loss, reason = "optimal")] if max_sum_u64 <= threshold { (f64::sqrt((8 * (max_sum_u64 + index_u64 * (index_u64 + 1)) + 1) as _) as u32 - index * 2 - 1) / 2 } else { diff --git a/src/problem_1825_finding_mk_average/btree_map.rs b/src/problem_1825_finding_mk_average/btree_map.rs index 5c620eabf..6a38fa14b 100644 --- a/src/problem_1825_finding_mk_average/btree_map.rs +++ b/src/problem_1825_finding_mk_average/btree_map.rs @@ -41,7 +41,7 @@ impl MultiSet { let entry = self.0.first_entry().unwrap(); let key = *entry.key(); - #[allow(clippy::if_then_some_else_none)] // False positive. + #[expect(clippy::if_then_some_else_none, reason = "false positive")] if num > key { Self::remove_entry(entry); self.insert(num); @@ -56,7 +56,7 @@ impl MultiSet { let entry = self.0.last_entry().unwrap(); let key = *entry.key(); - #[allow(clippy::if_then_some_else_none)] // False positive. + #[expect(clippy::if_then_some_else_none, reason = "false positive")] if num < key { Self::remove_entry(entry); self.insert(num); diff --git a/src/problem_1914_cyclically_rotating_a_grid/iterative.rs b/src/problem_1914_cyclically_rotating_a_grid/iterative.rs index 15a380cea..6c6d122fa 100644 --- a/src/problem_1914_cyclically_rotating_a_grid/iterative.rs +++ b/src/problem_1914_cyclically_rotating_a_grid/iterative.rs @@ -69,7 +69,7 @@ impl Solution { layer_max_column -= 2; Self::rotate_left(NonZeroUsize::new(length).unwrap(), k, grid.as_mut_slice(), |grid, i| { - #[allow(clippy::option_if_let_else)] // Expected. + #[expect(clippy::option_if_let_else, reason = "optimal")] let (y, x) = if let Some(offset) = i.checked_sub(middle) { if let Some(offset) = offset.checked_sub(layer_max_column) { (max_row - offset, layer) diff --git a/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method.rs b/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method.rs index 9e521fde3..58a51b52b 100644 --- a/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method.rs +++ b/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method.rs @@ -6,7 +6,7 @@ impl Solution { pub fn minimum_perimeter(num: i64) -> i64 { let num = num as u64; - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mut x = ((num / 4) as f64).cbrt() as u64; loop { diff --git a/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method_2.rs b/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method_2.rs index 8df209e93..90c82f90b 100644 --- a/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method_2.rs +++ b/src/problem_1954_minimum_garden_perimeter_to_collect_enough_apples/newtons_method_2.rs @@ -9,7 +9,7 @@ impl Solution { let x = if num < 13 { u64::from(num != 0) } else { - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss, reason = "optimal")] let mut x = ((num / 4) as f64).cbrt() as u64; // A single iteration is enough. diff --git a/src/problem_1993_operations_on_tree/mod.rs b/src/problem_1993_operations_on_tree/mod.rs index d174b77a5..c23a85d36 100644 --- a/src/problem_1993_operations_on_tree/mod.rs +++ b/src/problem_1993_operations_on_tree/mod.rs @@ -11,7 +11,6 @@ pub trait LockingTree { mod tests { use super::LockingTree; - #[allow(variant_size_differences)] // Expected. enum Operation { Lock((i32, i32), bool), Unlock((i32, i32), bool), diff --git a/src/problem_2069_walking_robot_simulation_ii/modular_arithmetic.rs b/src/problem_2069_walking_robot_simulation_ii/modular_arithmetic.rs index cdbc6b072..1e2ee15c0 100644 --- a/src/problem_2069_walking_robot_simulation_ii/modular_arithmetic.rs +++ b/src/problem_2069_walking_robot_simulation_ii/modular_arithmetic.rs @@ -31,7 +31,7 @@ impl Robot { let steps = self.steps & 0x_7fff; let half_cycle = self.cycle_length.get() / 2; - #[allow(clippy::option_if_let_else)] // Suggestion is too ugly. + #[expect(clippy::option_if_let_else, reason = "optimal")] let (x, y) = if let Some(second_half) = steps.checked_sub(half_cycle) { if let Some(x) = self.width_minus_1.checked_sub(second_half) { (x, half_cycle - self.width_minus_1) @@ -55,7 +55,7 @@ impl Robot { let steps = self.steps - 1; let half_cycle = self.cycle_length.get() / 2; - #[allow(clippy::option_if_let_else)] // Suggestion is too ugly. + #[expect(clippy::option_if_let_else, reason = "optimal")] if let Some(second_half) = steps.checked_sub(half_cycle) { if second_half < self.width_minus_1 { "West" diff --git a/src/problem_2103_rings_and_rods/iterative.rs b/src/problem_2103_rings_and_rods/iterative.rs index 6cf483c95..386ffbc96 100644 --- a/src/problem_2103_rings_and_rods/iterative.rs +++ b/src/problem_2103_rings_and_rods/iterative.rs @@ -3,7 +3,7 @@ pub struct Solution; // ------------------------------------------------------ snip ------------------------------------------------------ // impl Solution { - #[allow(clippy::naive_bytecount)] // Not supported by LeetCode. + #[expect(clippy::naive_bytecount, reason = "optimal")] pub fn count_points(rings: String) -> i32 { let mut iter_2 = rings.bytes(); diff --git a/src/problem_2166_design_bitset/dense_storage.rs b/src/problem_2166_design_bitset/dense_storage.rs index bad77c270..23f93121a 100644 --- a/src/problem_2166_design_bitset/dense_storage.rs +++ b/src/problem_2166_design_bitset/dense_storage.rs @@ -62,7 +62,7 @@ impl Bitset { self.data.iter().map(|x| x.count_ones()).sum::() as _ } - #[allow(clippy::inherent_to_string)] // Expected. + #[expect(clippy::inherent_to_string, reason = "required")] fn to_string(&self) -> String { let mut result = String::with_capacity(self.length); diff --git a/src/problem_2166_design_bitset/mod.rs b/src/problem_2166_design_bitset/mod.rs index 33df88176..800f26b73 100644 --- a/src/problem_2166_design_bitset/mod.rs +++ b/src/problem_2166_design_bitset/mod.rs @@ -15,7 +15,7 @@ pub trait Bitset { mod tests { use super::Bitset; - #[allow(variant_size_differences)] // Expected. + #[expect(variant_size_differences, reason = "optimal")] enum Operation { Fix(i32), Unfix(i32), diff --git a/src/problem_2178_maximum_split_of_positive_even_integers/mathematical.rs b/src/problem_2178_maximum_split_of_positive_even_integers/mathematical.rs index e38a1a4b6..abca64171 100644 --- a/src/problem_2178_maximum_split_of_positive_even_integers/mathematical.rs +++ b/src/problem_2178_maximum_split_of_positive_even_integers/mathematical.rs @@ -7,7 +7,7 @@ impl Solution { let final_sum = final_sum as u64; if final_sum % 2 == 0 { - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss, reason = "optimal")] let count = (((final_sum * 4 + 1) as f64).sqrt() as u64 - 1) / 2; let mut result = Vec::with_capacity(count as _); diff --git a/src/problem_2241_design_an_atm_machine/greedy.rs b/src/problem_2241_design_an_atm_machine/greedy.rs index 55b5d2cb9..729893aee 100644 --- a/src/problem_2241_design_an_atm_machine/greedy.rs +++ b/src/problem_2241_design_an_atm_machine/greedy.rs @@ -1,6 +1,6 @@ // ------------------------------------------------------ snip ------------------------------------------------------ // -#[allow(clippy::struct_field_names, clippy::upper_case_acronyms)] +#[expect(clippy::struct_field_names, clippy::upper_case_acronyms, reason = "optimal")] pub struct ATM { count_20: u32, count_50: u32, diff --git a/src/problem_2241_design_an_atm_machine/greedy_2.rs b/src/problem_2241_design_an_atm_machine/greedy_2.rs index 6d6b814c8..98d45bb84 100644 --- a/src/problem_2241_design_an_atm_machine/greedy_2.rs +++ b/src/problem_2241_design_an_atm_machine/greedy_2.rs @@ -1,6 +1,6 @@ // ------------------------------------------------------ snip ------------------------------------------------------ // -#[allow(clippy::struct_field_names, clippy::upper_case_acronyms)] +#[expect(clippy::upper_case_acronyms, reason = "required")] pub struct ATM { counts: [u32; 5], } diff --git a/src/problem_2241_design_an_atm_machine/mod.rs b/src/problem_2241_design_an_atm_machine/mod.rs index f6897c8d6..1c4e61535 100644 --- a/src/problem_2241_design_an_atm_machine/mod.rs +++ b/src/problem_2241_design_an_atm_machine/mod.rs @@ -1,7 +1,7 @@ pub mod greedy; pub mod greedy_2; -#[allow(clippy::upper_case_acronyms)] // Expected. +#[expect(clippy::upper_case_acronyms, reason = "required")] pub trait ATM { fn new() -> Self; fn deposit(&mut self, banknotes_count: Vec); diff --git a/tools/check-cpp-code-format/src/main.rs b/tools/check-cpp-code-format/src/main.rs index 0263a0682..c46679560 100644 --- a/tools/check-cpp-code-format/src/main.rs +++ b/tools/check-cpp-code-format/src/main.rs @@ -36,7 +36,7 @@ fn check_regex(re: &str, text: &str) { ); } -#[allow(clippy::print_stdout)] // Expected. +#[expect(clippy::print_stdout, reason = "by design")] fn main() { let project_path = PathBuf::from(env::args_os().nth(1).unwrap()); let leet_code_include_path = project_path.join("include").join("leet-code"); diff --git a/xtask/src/utilities.rs b/xtask/src/utilities.rs index 4b53c097b..d3282d351 100644 --- a/xtask/src/utilities.rs +++ b/xtask/src/utilities.rs @@ -11,7 +11,6 @@ pub fn get_project_dir() -> PathBuf { path } -#[allow(clippy::print_stdout)] // Expected. fn print_command_line(command: &Command) { let stdout = io::stdout(); let mut stdout = stdout.lock();