From fb5c0239616102739e35f1c1a96bd0c136c57b37 Mon Sep 17 00:00:00 2001 From: HoLLy Date: Sun, 5 Dec 2021 12:21:16 +0100 Subject: [PATCH] Add test cases for real inputs --- aoc-lib/src/lib.rs | 31 ++++++++++++++++++++++--------- day-1/src/main.rs | 2 +- day-2/src/main.rs | 2 +- day-3/src/main.rs | 2 +- day-4/src/main.rs | 2 +- day-5/src/main.rs | 2 +- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/aoc-lib/src/lib.rs b/aoc-lib/src/lib.rs index fbf798d..ae5da90 100644 --- a/aoc-lib/src/lib.rs +++ b/aoc-lib/src/lib.rs @@ -3,7 +3,7 @@ use std::fmt::Display; #[macro_export] macro_rules! aoc_setup { - ($type:ident $(, test $index:literal: $test_result:expr)*) => { + ($type:ident $(, $test_type:ident $index:literal: $test_result:expr)*) => { // TODO: pub use another macro that creates benchmarks? fn main() { @@ -11,16 +11,29 @@ macro_rules! aoc_setup { } $( - aoc_lib::paste! { - #[test] - fn []() { - let input = include_str!("../sample.txt"); - let parsed = $type::parse_input(input); - assert_eq!($test_result, $type::[< solve_ $index >](&parsed)); - } - } + aoc_setup!(test_impl $test_type $type $index: $test_result); )* }; + (test_impl sample $type:ident $index:literal: $test_result:expr) => { + aoc_lib::paste! { + #[test] + fn []() { + let input = include_str!("../sample.txt"); + let parsed = $type::parse_input(input); + assert_eq!($test_result, $type::[< solve_ $index >](&parsed)); + } + } + }; + (test_impl part $type:ident $index:literal: $test_result:expr) => { + aoc_lib::paste! { + #[test] + fn []() { + let input = include_str!("../input.txt"); + let parsed = $type::parse_input(input); + assert_eq!($test_result, $type::[< solve_ $index >](&parsed)); + } + } + }; } pub trait AdventOfCode { diff --git a/day-1/src/main.rs b/day-1/src/main.rs index b4698f8..791ef19 100644 --- a/day-1/src/main.rs +++ b/day-1/src/main.rs @@ -1,6 +1,6 @@ use aoc_lib::*; -aoc_setup!(Day1, test 1: 7, test 2: 5); +aoc_setup!(Day1, sample 1: 7, sample 2: 5, part 1: 1759, part 2: 1805); pub struct Day1; diff --git a/day-2/src/main.rs b/day-2/src/main.rs index 8e3822d..422dc07 100644 --- a/day-2/src/main.rs +++ b/day-2/src/main.rs @@ -1,6 +1,6 @@ use aoc_lib::*; -aoc_setup!(Day2, test 1: 150, test 2: 900); +aoc_setup!(Day2, sample 1: 150, sample 2: 900, part 1: 1654760, part 2: 1956047400); #[derive(Clone, Copy)] pub enum Direction { diff --git a/day-3/src/main.rs b/day-3/src/main.rs index 7da7a1b..c44548f 100644 --- a/day-3/src/main.rs +++ b/day-3/src/main.rs @@ -1,6 +1,6 @@ use aoc_lib::*; -aoc_setup!(Day3, test 1: 198, test 2: 230); +aoc_setup!(Day3, sample 1: 198, sample 2: 230, part 1: 4191876, part 2: 3414905); pub struct Day3; diff --git a/day-4/src/main.rs b/day-4/src/main.rs index a04c4b8..81ea366 100644 --- a/day-4/src/main.rs +++ b/day-4/src/main.rs @@ -2,7 +2,7 @@ use aoc_lib::*; use itertools::Itertools; use std::ops::IndexMut; -aoc_setup!(Day4, test 1: 4512, test 2: 1924); +aoc_setup!(Day4, sample 1: 4512, sample 2: 1924, part 1: 16674, part 2: 7075); #[derive(Debug)] pub struct Input(Vec, Vec); diff --git a/day-5/src/main.rs b/day-5/src/main.rs index 5956b16..730697d 100644 --- a/day-5/src/main.rs +++ b/day-5/src/main.rs @@ -1,6 +1,6 @@ use aoc_lib::*; -aoc_setup!(Day5, test 1: 5, test 2: 12000); +aoc_setup!(Day5, sample 1: 5, sample 2: 12, part 1: 4826, part 2: 16793); pub struct Day5;