diff --git a/2020/src/day01.rs b/2020/src/day01.rs index 37377af..07627fe 100644 --- a/2020/src/day01.rs +++ b/2020/src/day01.rs @@ -55,11 +55,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day01, 1, SAMPLE, 514579); + test_implementation(Day01, 1, SAMPLE, 514579); } #[test] fn sample_part2() { - test_implementation!(Day01, 2, SAMPLE, 241861950); + test_implementation(Day01, 2, SAMPLE, 241861950); } } diff --git a/2020/src/day02.rs b/2020/src/day02.rs index b8eb0ec..8cbd668 100644 --- a/2020/src/day02.rs +++ b/2020/src/day02.rs @@ -65,11 +65,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day02, 1, SAMPLE, 2); + test_implementation(Day02, 1, SAMPLE, 2); } #[test] fn sample_part2() { - test_implementation!(Day02, 2, SAMPLE, 1); + test_implementation(Day02, 2, SAMPLE, 1); } } diff --git a/2020/src/day03.rs b/2020/src/day03.rs index b05e1d1..ff49852 100644 --- a/2020/src/day03.rs +++ b/2020/src/day03.rs @@ -50,11 +50,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day03, 1, SAMPLE, 7); + test_implementation(Day03, 1, SAMPLE, 7); } #[test] fn sample_part2() { - test_implementation!(Day03, 2, SAMPLE, 336); + test_implementation(Day03, 2, SAMPLE, 336); } } diff --git a/2020/src/day06.rs b/2020/src/day06.rs index 8184c87..5d7220c 100644 --- a/2020/src/day06.rs +++ b/2020/src/day06.rs @@ -57,11 +57,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day06, 1, SAMPLE, 11); + test_implementation(Day06, 1, SAMPLE, 11); } #[test] fn sample_part2() { - test_implementation!(Day06, 2, SAMPLE, 6); + test_implementation(Day06, 2, SAMPLE, 6); } } diff --git a/2020/src/day07.rs b/2020/src/day07.rs index dff6a98..ff54cc3 100644 --- a/2020/src/day07.rs +++ b/2020/src/day07.rs @@ -126,12 +126,12 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day07, 1, SAMPLE, 4); + test_implementation(Day07, 1, SAMPLE, 4); } #[test] fn sample_part2() { - test_implementation!(Day07, 2, SAMPLE, 32); - test_implementation!(Day07, 2, SAMPLE2, 126); + test_implementation(Day07, 2, SAMPLE, 32); + test_implementation(Day07, 2, SAMPLE2, 126); } } diff --git a/2020/src/day08.rs b/2020/src/day08.rs index 60768f0..582dae9 100644 --- a/2020/src/day08.rs +++ b/2020/src/day08.rs @@ -113,11 +113,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day08, 1, SAMPLE, 5); + test_implementation(Day08, 1, SAMPLE, 5); } #[test] fn sample_part2() { - test_implementation!(Day08, 2, SAMPLE, 8); + test_implementation(Day08, 2, SAMPLE, 8); } } diff --git a/2020/src/day10.rs b/2020/src/day10.rs index 90015c4..7532eb6 100644 --- a/2020/src/day10.rs +++ b/2020/src/day10.rs @@ -59,13 +59,13 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day10, 1, SAMPLE, 35); - test_implementation!(Day10, 1, SAMPLE2, 220); + test_implementation(Day10, 1, SAMPLE, 35); + test_implementation(Day10, 1, SAMPLE2, 220); } #[test] fn sample_part2() { - test_implementation!(Day10, 2, SAMPLE, 8); - test_implementation!(Day10, 2, SAMPLE2, 19208); + test_implementation(Day10, 2, SAMPLE, 8); + test_implementation(Day10, 2, SAMPLE2, 19208); } } diff --git a/2020/src/day11.rs b/2020/src/day11.rs index 9ca8bc9..4637606 100644 --- a/2020/src/day11.rs +++ b/2020/src/day11.rs @@ -157,11 +157,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day11, 1, SAMPLE, 37); + test_implementation(Day11, 1, SAMPLE, 37); } #[test] fn sample_part2() { - test_implementation!(Day11, 2, SAMPLE, 26); + test_implementation(Day11, 2, SAMPLE, 26); } } diff --git a/2020/src/day12.rs b/2020/src/day12.rs index e6a3856..9237a88 100644 --- a/2020/src/day12.rs +++ b/2020/src/day12.rs @@ -97,11 +97,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day12, 1, SAMPLE, 25); + test_implementation(Day12, 1, SAMPLE, 25); } #[test] fn sample_part2() { - test_implementation!(Day12, 2, SAMPLE, 286); + test_implementation(Day12, 2, SAMPLE, 286); } } diff --git a/2020/src/day13.rs b/2020/src/day13.rs index 0b4e0ac..30a4d3e 100644 --- a/2020/src/day13.rs +++ b/2020/src/day13.rs @@ -59,11 +59,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day13, 1, SAMPLE, 295); + test_implementation(Day13, 1, SAMPLE, 295); } #[test] fn sample_part2() { - test_implementation!(Day13, 2, SAMPLE, 1068781); + test_implementation(Day13, 2, SAMPLE, 1068781); } } diff --git a/2020/src/day14.rs b/2020/src/day14.rs index 1f28b63..85ab45f 100644 --- a/2020/src/day14.rs +++ b/2020/src/day14.rs @@ -143,12 +143,12 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day14, 1, SAMPLE, 165); + test_implementation(Day14, 1, SAMPLE, 165); } #[test] fn sample_part2() { - test_implementation!(Day14, 2, SAMPLE2, 208); + test_implementation(Day14, 2, SAMPLE2, 208); } #[test] diff --git a/2020/src/day16.rs b/2020/src/day16.rs index edd508f..d43d52f 100644 --- a/2020/src/day16.rs +++ b/2020/src/day16.rs @@ -165,6 +165,6 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day16, 1, SAMPLE, 71); + test_implementation(Day16, 1, SAMPLE, 71); } } diff --git a/2020/src/day17.rs b/2020/src/day17.rs index d9be923..36a9eab 100644 --- a/2020/src/day17.rs +++ b/2020/src/day17.rs @@ -130,11 +130,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day17, 1, SAMPLE, 112); + test_implementation(Day17, 1, SAMPLE, 112); } #[test] fn sample_part2() { - test_implementation!(Day17, 2, SAMPLE, 848); + test_implementation(Day17, 2, SAMPLE, 848); } } diff --git a/2020/src/day19.rs b/2020/src/day19.rs index 65ef35c..0c83466 100644 --- a/2020/src/day19.rs +++ b/2020/src/day19.rs @@ -125,12 +125,12 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day19, 1, SAMPLE, 2); + test_implementation(Day19, 1, SAMPLE, 2); } #[test] fn sample_part2() { - test_implementation!(Day19, 1, SAMPLE2, 3); - test_implementation!(Day19, 2, SAMPLE2, 12); + test_implementation(Day19, 1, SAMPLE2, 3); + test_implementation(Day19, 2, SAMPLE2, 12); } } diff --git a/2020/src/day20.rs b/2020/src/day20.rs index 1e540db..b26bb66 100644 --- a/2020/src/day20.rs +++ b/2020/src/day20.rs @@ -413,12 +413,12 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day20, 1, SAMPLE, 20899048083289u64); + test_implementation(Day20, 1, SAMPLE, 20899048083289u64); } #[test] fn sample_part2() { - test_implementation!(Day20, 2, SAMPLE, 273); + test_implementation(Day20, 2, SAMPLE, 273); } #[test] diff --git a/2020/src/day21.rs b/2020/src/day21.rs index 02edc1b..303f025 100644 --- a/2020/src/day21.rs +++ b/2020/src/day21.rs @@ -123,11 +123,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day21, 1, SAMPLE, 5); + test_implementation(Day21, 1, SAMPLE, 5); } #[test] fn sample_part2() { - test_implementation!(Day21, 2, SAMPLE, "mxmxvkd,sqjhc,fvjkl"); + test_implementation(Day21, 2, SAMPLE, "mxmxvkd,sqjhc,fvjkl"); } } diff --git a/2020/src/day22.rs b/2020/src/day22.rs index 2baf21d..01292ea 100644 --- a/2020/src/day22.rs +++ b/2020/src/day22.rs @@ -120,11 +120,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day22, 1, SAMPLE, 306); + test_implementation(Day22, 1, SAMPLE, 306); } #[test] fn sample_part2() { - test_implementation!(Day22, 2, SAMPLE, 291); + test_implementation(Day22, 2, SAMPLE, 291); } } diff --git a/2020/src/day23.rs b/2020/src/day23.rs index 38a7676..5d26eea 100644 --- a/2020/src/day23.rs +++ b/2020/src/day23.rs @@ -149,6 +149,6 @@ mod tests { #[test] fn sample_part2() { - test_implementation!(Day23, 2, SAMPLE, 149245887792u64); + test_implementation(Day23, 2, SAMPLE, 149245887792u64); } } diff --git a/2020/src/day24.rs b/2020/src/day24.rs index 0f84a5f..5e61168 100644 --- a/2020/src/day24.rs +++ b/2020/src/day24.rs @@ -129,11 +129,11 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day24, 1, SAMPLE, 10); + test_implementation(Day24, 1, SAMPLE, 10); } #[test] fn sample_part2() { - test_implementation!(Day24, 2, SAMPLE, 2208); + test_implementation(Day24, 2, SAMPLE, 2208); } } diff --git a/2020/src/day25.rs b/2020/src/day25.rs index de1de5b..266c4f9 100644 --- a/2020/src/day25.rs +++ b/2020/src/day25.rs @@ -92,6 +92,6 @@ mod tests { #[test] fn sample_part1() { - test_implementation!(Day25, 1, SAMPLE, 14897079); + test_implementation(Day25, 1, SAMPLE, 14897079); } } diff --git a/2020/src/lib.rs b/2020/src/lib.rs index 12dbd1f..5f789fd 100644 --- a/2020/src/lib.rs +++ b/2020/src/lib.rs @@ -67,19 +67,12 @@ pub fn get_implementation(day: usize) -> Box { } #[cfg(test)] -#[macro_export] -macro_rules! test_implementation { - ($impl:ident, 1, $source:ident, $output:expr) => { - let mut implementation = $impl::default(); - - let result = implementation.part1(&mut $source.clone()); - assert_eq!($output.to_string(), result); +fn test_implementation(mut day: impl Solution, part: u8, mut input: &[u8], answer: impl ToString) { + let result = match part { + 1 => day.part1(&mut input), + 2 => day.part2(&mut input), + _ => panic!("Invalid part: {}", part), }; - ($impl:ident, 2, $source:ident, $output:expr) => { - let mut implementation = $impl::default(); - - let result = implementation.part2(&mut $source.clone()); - assert_eq!($output.to_string(), result); - }; + assert_eq!(answer.to_string(), result); }