mirror of
https://github.com/SebastianStork/advent-of-code.git
synced 2026-01-21 13:21:34 +01:00
Add unit tests to 2025 day 1
This commit is contained in:
parent
5d4fa37355
commit
3c4e0e4317
1 changed files with 29 additions and 4 deletions
|
|
@ -4,15 +4,14 @@ const STARTING_POSITION: i32 = 50;
|
||||||
const DIAL_RANGE: i32 = 100;
|
const DIAL_RANGE: i32 = 100;
|
||||||
|
|
||||||
fn main() {
|
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!("Password1: {}", count_zero_positions(&rotations));
|
||||||
println!("Password2: {}", count_zero_clicks(&rotations));
|
println!("Password2: {}", count_zero_clicks(&rotations));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_rotations() -> Vec<i32> {
|
fn parse_rotations(contents: &str) -> Vec<i32> {
|
||||||
fs::read_to_string("../../inputs/01.txt")
|
contents
|
||||||
.unwrap()
|
|
||||||
.lines()
|
.lines()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
let distance = line[1..].parse::<i32>().unwrap();
|
let distance = line[1..].parse::<i32>().unwrap();
|
||||||
|
|
@ -60,3 +59,29 @@ fn count_zero_clicks(rotations: &[i32]) -> i32 {
|
||||||
|
|
||||||
counter
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue