]> aoc.elinar.fr Git - aoc_2024/commitdiff
Maquette et Makefile
authoralex <>
Mon, 2 Dec 2024 08:47:55 +0000 (09:47 +0100)
committeralex <>
Mon, 2 Dec 2024 08:47:55 +0000 (09:47 +0100)
Makefile [new file with mode: 0644]
src/day00.rs [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..f1a9a82
--- /dev/null
@@ -0,0 +1,47 @@
+use std::error::Error;
+use std::path::Path;
+
+pub fn run(input: &str) -> Result<(), Box<dyn Error>> {
+    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<u32, Box<dyn Error>> {
+    println!("Running {} - part 1", get_day());
+
+    Ok(0)
+}
+
+fn run_part2(input: &str) -> Result<u32, Box<dyn Error>> {
+    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());
+    }
+}