diff --git a/aoc2021/input/day02_provided.txt b/aoc2021/input/day02_provided.txt new file mode 100644 index 0000000..b7172ac --- /dev/null +++ b/aoc2021/input/day02_provided.txt @@ -0,0 +1,6 @@ +forward 5 +down 5 +forward 8 +up 3 +down 8 +forward 2 diff --git a/aoc2021/src/day02.rs b/aoc2021/src/day02.rs index f9e03d2..fbc1c2e 100644 --- a/aoc2021/src/day02.rs +++ b/aoc2021/src/day02.rs @@ -84,3 +84,30 @@ impl std::str::FromStr for Command { }) } } + +#[cfg(test)] +mod tests { + use super::*; + + const PROVIDED: &str = include_str!("../input/day02_provided.txt"); + + #[test] + fn part1_provided() { + assert_eq!(part1(PROVIDED).unwrap(), 150); + } + + #[test] + fn part1_real() { + assert_eq!(part1(INPUT).unwrap(), 1962940); + } + + #[test] + fn part2_provided() { + assert_eq!(part2(PROVIDED).unwrap(), 900); + } + + #[test] + fn part2_real() { + assert_eq!(part2(INPUT).unwrap(), 1813664422); + } +}