From c09ec6dc7c7817f9a8617ac27ae14a15998c2d5a Mon Sep 17 00:00:00 2001 From: tinnamchoi Date: Thu, 10 Jul 2025 14:40:02 +0800 Subject: [PATCH 1/2] feat: sort tests numerically --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + crates/cli/Cargo.toml | 1 + crates/cli/src/util.rs | 4 +++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9c3a867..05da8fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,7 @@ dependencies = [ "clap", "config", "normpath", + "numeric-sort", "regex", "serde", "serde_json", @@ -409,6 +410,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "numeric-sort" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dcb6053ab98da45585315f79932c5c9821fab8efa4301c0d7b637c91630eb7" + [[package]] name = "once_cell" version = "1.21.3" diff --git a/Cargo.toml b/Cargo.toml index 98118a6..d350b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ anyhow = "1.0.95" clap = "4.5.26" config = { version = "0.15.11", features = ["toml"] } normpath = "1.3" +numeric-sort = "0.1.5" regex = "1.11.1" serde = { version = "1.0.217", features = ["derive"] } serde_json = "1.0.138" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index bab11a1..3bd674c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -13,6 +13,7 @@ anyhow.workspace = true clap.workspace = true config.workspace = true normpath.workspace = true +numeric-sort.workspace = true regex.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/cli/src/util.rs b/crates/cli/src/util.rs index 169b252..7d7a935 100644 --- a/crates/cli/src/util.rs +++ b/crates/cli/src/util.rs @@ -2,6 +2,7 @@ use std::fs; use std::path::{Path, PathBuf}; use anyhow::{bail, Context, Result}; +use numeric_sort::sort_unstable; use crate::config::SETTINGS_FILE_NAME; use crate::problem::sync_mappings::problem_exists; @@ -60,10 +61,11 @@ pub fn get_files_in_directory>(path: P) -> Result> { } pub fn get_input_files_in_directory>(path: P) -> Result> { - let files = get_files_in_directory(path)? + let mut files: Vec<_> = get_files_in_directory(path)? .into_iter() .filter(|name| name.ends_with(".in")) .collect(); + sort_unstable(&mut files); Ok(files) } From 82f476b5556495a4c057683751a6531a996c88ca Mon Sep 17 00:00:00 2001 From: tinnamchoi Date: Thu, 10 Jul 2025 14:55:46 +0800 Subject: [PATCH 2/2] fix: updated clippy errors --- crates/cli/src/main.rs | 8 +++----- crates/cli/src/problem/check.rs | 2 +- crates/cli/src/problem/compare.rs | 2 +- crates/cli/src/problem/create.rs | 2 +- crates/cli/src/problem/fuzz.rs | 2 +- crates/cli/src/problem/run.rs | 2 +- crates/cli/src/problem/solve.rs | 8 ++++---- crates/cli/src/problem/test.rs | 6 +++--- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 4b3d0b7..c4c3dc2 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -15,11 +15,9 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const ABOUT: &str = env!("CARGO_PKG_DESCRIPTION"); fn main() -> Result<()> { - let about_text = format!("{} {}\n{}", NAME, VERSION, ABOUT); - let after_help_text = format!( - "See '{} help ' for more information on a command", - BIN_NAME - ); + let about_text = format!("{NAME} {VERSION}\n{ABOUT}"); + let after_help_text = + format!("See '{BIN_NAME} help ' for more information on a command"); let cli = Command::new(NAME) .bin_name(BIN_NAME) diff --git a/crates/cli/src/problem/check.rs b/crates/cli/src/problem/check.rs index ddc0eda..2a1fc56 100644 --- a/crates/cli/src/problem/check.rs +++ b/crates/cli/src/problem/check.rs @@ -58,7 +58,7 @@ pub fn check(problems_dir: PathBuf, problem_name: &str) -> Result<()> { if !exists { bail!("The folder structure is not valid! Missing file {file}"); } - eprintln!("Folder structure for '{}' is valid", problem_name); + eprintln!("Folder structure for '{problem_name}' is valid"); // Check that test files are valid, i.e.: // - A .in file must have a corresponding .out file diff --git a/crates/cli/src/problem/compare.rs b/crates/cli/src/problem/compare.rs index cfea6fb..afe037a 100644 --- a/crates/cli/src/problem/compare.rs +++ b/crates/cli/src/problem/compare.rs @@ -51,7 +51,7 @@ pub fn compare(settings: &Settings, compare_args: &CompareArgs) -> Result<()> { eprintln!("Running the solution files for each test case..."); for test_file in test_files { - let input_file_path = problem_path.join(format!("tests/{}", test_file)); + let input_file_path = problem_path.join(format!("tests/{test_file}")); let mut results: Vec = Vec::new(); for (i, run_cmd) in run_commands.iter().enumerate() { diff --git a/crates/cli/src/problem/create.rs b/crates/cli/src/problem/create.rs index 2a6d057..39d068c 100644 --- a/crates/cli/src/problem/create.rs +++ b/crates/cli/src/problem/create.rs @@ -28,7 +28,7 @@ pub fn create(problems_dir: &Path, problem_name: &str, difficulty: u16) -> Resul let difficulty_str = if difficulty == 0 { "unrated".to_string() } else { - format!("{:0>4}", bucketed_difficulty) + format!("{bucketed_difficulty:0>4}") }; let re = Regex::new(PROBLEM_NAME_REGEX_PATTERN)?; if !re.is_match(problem_name) { diff --git a/crates/cli/src/problem/fuzz.rs b/crates/cli/src/problem/fuzz.rs index 6c04013..f9a6190 100644 --- a/crates/cli/src/problem/fuzz.rs +++ b/crates/cli/src/problem/fuzz.rs @@ -56,7 +56,7 @@ pub fn fuzz(settings: &Settings, fuzz_args: &FuzzArgs) -> Result<()> { generate::generate(settings, problems_dir, problem_name, generator, &test_name) .context("Failed to generate test case")?; - let input_file_path = problem_path.join(format!("tests/{}.in", test_name)); + let input_file_path = problem_path.join(format!("tests/{test_name}.in")); let mut results: Vec = Vec::new(); for (i, run_cmd) in run_commands.iter().enumerate() { diff --git a/crates/cli/src/problem/run.rs b/crates/cli/src/problem/run.rs index 47b02ee..09d6948 100644 --- a/crates/cli/src/problem/run.rs +++ b/crates/cli/src/problem/run.rs @@ -97,7 +97,7 @@ impl RunCommand { bin_file: PathBuf, script_file: PathBuf, ) -> Result { - let mut file_path = problem.join(format!("{}", file)); + let mut file_path = problem.join(format!("{file}")); file_path = file_path .normalize() .context(format!( diff --git a/crates/cli/src/problem/solve.rs b/crates/cli/src/problem/solve.rs index 84efad6..0f2d002 100644 --- a/crates/cli/src/problem/solve.rs +++ b/crates/cli/src/problem/solve.rs @@ -22,7 +22,7 @@ pub fn solve( let problem = project_root.join(get_problem(problems_dir, problem_name)?); let solution_lang = solution_lang.unwrap_or(&settings.problem.default_lang); - let mut solution_file = problem.join(format!("solutions/solution.{}", solution_lang)); + let mut solution_file = problem.join(format!("solutions/solution.{solution_lang}")); if solution_file_name.is_some() { solution_file = problem.join(format!( "solutions/{}", @@ -38,7 +38,7 @@ pub fn solve( eprintln!("Using solution file at: {}", solution_file.display()); let bin_file = problem.join("solutions/solution.out"); - let script_file = problem.join(format!("solutions/solution.{}", solution_lang)); + let script_file = problem.join(format!("solutions/solution.{solution_lang}")); let lang_settings = settings .problem @@ -84,7 +84,7 @@ pub fn solve( eprintln!("Running the solution file for each test case..."); // Run the file for every test input and generate the corresponding output for test_file in test_files { - let input_file_path = problem.join(format!("tests/{}", test_file)); + let input_file_path = problem.join(format!("tests/{test_file}")); let output_file_path = problem.join(format!( "tests/{}.out", test_file @@ -114,7 +114,7 @@ pub fn solve( final_cmd = final_cmd.stdin(input_file).stdout(output_file); final_cmd.capture()?; - eprintln!(" - generated output for test file: {}", test_file); + eprintln!(" - generated output for test file: {test_file}"); } eprintln!("Finished generating outputs for all test cases"); diff --git a/crates/cli/src/problem/test.rs b/crates/cli/src/problem/test.rs index 469c016..3933828 100644 --- a/crates/cli/src/problem/test.rs +++ b/crates/cli/src/problem/test.rs @@ -25,7 +25,7 @@ pub fn test( let problem = project_root.join(get_problem(problems_dir, problem_name)?); let solution_lang = solution_lang.unwrap_or(&settings.problem.default_lang); - let mut solution_file = problem.join(format!("solutions/solution.{}", solution_lang)); + let mut solution_file = problem.join(format!("solutions/solution.{solution_lang}")); if solution_file_name.is_some() { solution_file = problem.join(format!( "solutions/{}", @@ -41,7 +41,7 @@ pub fn test( eprintln!("Using solution file at: {}", solution_file.display()); let bin_file = problem.join("solutions/solution.out"); - let script_file = problem.join(format!("solutions/solution.{}", solution_lang)); + let script_file = problem.join(format!("solutions/solution.{solution_lang}")); let lang_settings = settings .problem @@ -91,7 +91,7 @@ pub fn test( let mut total_time: Duration = Duration::new(0, 0); for test_file in test_files { - let input_file_path = problem.join(format!("tests/{}", test_file)); + let input_file_path = problem.join(format!("tests/{test_file}")); let output_file_path = problem.join(format!( "tests/{}.out", test_file