Add unit tests to 2025 day 1

This commit is contained in:
SebastianStork 2025-12-01 19:08:37 +01:00
parent 5d4fa37355
commit 3c4e0e4317
Signed by: SebastianStork
SSH key fingerprint: SHA256:iEM011ogNMG1q8+U500adGu/9rpPuZ2KnFtbdLeqTiI

View file

@ -4,15 +4,14 @@ const STARTING_POSITION: i32 = 50;
const DIAL_RANGE: i32 = 100;
fn main() {
let rotations = read_rotations();
let rotations = parse_rotations(&fs::read_to_string("../../inputs/01.txt").unwrap());
println!("Password1: {}", count_zero_positions(&rotations));
println!("Password2: {}", count_zero_clicks(&rotations));
}
fn read_rotations() -> Vec<i32> {
fs::read_to_string("../../inputs/01.txt")
.unwrap()
fn parse_rotations(contents: &str) -> Vec<i32> {
contents
.lines()
.map(|line| {
let distance = line[1..].parse::<i32>().unwrap();
@ -60,3 +59,29 @@ fn count_zero_clicks(rotations: &[i32]) -> i32 {
counter
}
#[cfg(test)]
mod tests {
use super::*;
const TEST_INPUT: &str = "L68
L30
R48
L5
R60
L55
L1
L99
R14
L82";
#[test]
fn test_part1() {
assert_eq!(count_zero_positions(&parse_rotations(TEST_INPUT)), 3);
}
#[test]
fn test_part2() {
assert_eq!(count_zero_clicks(&parse_rotations(TEST_INPUT)), 6);
}
}