From: alex <> Date: Mon, 2 Dec 2024 08:47:55 +0000 (+0100) Subject: Maquette et Makefile X-Git-Url: https://aoc.elinar.fr/?a=commitdiff_plain;h=0c4b66ce12b482a6521912c7b99cb3bc8adf31c7;p=aoc_2024 Maquette et Makefile --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89753f0 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +# - create a new file src/day% +# - update the main to integrate the new day +new-day%: + if [ -f "src/$(subst new-,,$@).rs" ]; then return 1; fi + cp -v src/day00.rs src/$(subst new-,,$@).rs + sed -i \ + -e "$$(( $$(grep -n main src/main.rs | cut -d ':' -f 1) - 2 ))a\pub mod $(subst new-,,$@);" \ + -e "/_ =>/i\ \"$(subst new-,,$@)\" => $(subst new-,,$@)::run(\&input)?," \ + src/main.rs + +# run the tests for a specific day +test-day%: + cargo test $(subst test-,,$@)::tests + +# run a specific day with its input file +day%: + cargo run $@ input/$@.txt diff --git a/src/day00.rs b/src/day00.rs new file mode 100644 index 0000000..f1a9a82 --- /dev/null +++ b/src/day00.rs @@ -0,0 +1,47 @@ +use std::error::Error; +use std::path::Path; + +pub fn run(input: &str) -> Result<(), Box> { + let res = run_part1(&input)?; + println!("{res}"); + + let res = run_part2(&input)?; + println!("{res}"); + + Ok(()) +} + +fn get_day() -> String { + let filename = file!(); + Path::new(filename).file_stem().unwrap().to_str().unwrap().to_string() +} + +fn run_part1(input: &str) -> Result> { + println!("Running {} - part 1", get_day()); + + Ok(0) +} + +fn run_part2(input: &str) -> Result> { + println!("Running {} - part 2", get_day()); + + Ok(0) +} + +#[cfg(test)] +mod tests { + use super::*; + + static TEXT_INPUT: &str = "\ +"; + + #[test] + fn test_part1() { + assert_eq!(0, run_part1(TEXT_INPUT).unwrap()); + } + + #[test] + fn test_part2() { + assert_eq!(0, run_part2(TEXT_INPUT).unwrap()); + } +}