1
1
mirror of https://github.com/theoludwig/advent_of_code.git synced 2025-05-18 19:27:51 +02:00

ci: add automated tests/linting/format

This commit is contained in:
2023-12-01 17:26:01 +01:00
parent 0c6ebb6ad4
commit 760686db4c
12 changed files with 106 additions and 16 deletions

7
day_1/Cargo.lock generated
View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day_1"
version = "1.0.0"

View File

@ -10,7 +10,7 @@ fn part_1(input: &str) -> i32 {
let first_digit = characters_digits.first().unwrap_or(&'0').to_owned();
let last_digit = characters_digits.last().unwrap_or(&'0').to_owned();
let number = format!("{}{}", first_digit, last_digit);
let number: i32 = number.parse().expect("Should parse as a number.");
let number: i32 = number.parse().expect("Should parse as a i32.");
number
})
.sum()
@ -64,15 +64,23 @@ fn part_2(input: &str) -> i32 {
}
fn main() {
let input_example1 = include_str!("../input_example_1.txt");
let input_example2 = include_str!("../input_example_2.txt");
let input = include_str!("../input.txt");
println!("Answer Part 1 (example1): {}", part_1(input_example1));
println!("Answer Part 1 (example2): {}", part_1(input_example2));
println!("- Day 1: Trebuchet?! -");
println!("Answer Part 1: {}", part_1(input));
println!("Answer Part 2 (example1): {}", part_2(input_example1));
println!("Answer Part 2 (example2): {}", part_2(input_example2));
println!("Answer Part 2: {}", part_2(input));
}
#[cfg(test)]
mod day_1_tests {
use super::*;
#[test]
fn test_part_1_example() {
assert_eq!(142, part_1(include_str!("../input_example_1.txt")));
}
#[test]
fn test_part_2_example() {
assert_eq!(281, part_2(include_str!("../input_example_2.txt")));
}
}