2021-12-07 19:40:41 +01:00
|
|
|
use anyhow::Result;
|
|
|
|
|
2021-12-01 17:07:17 +01:00
|
|
|
pub trait Day {
|
2021-12-07 19:40:41 +01:00
|
|
|
fn init(content: String) -> Result<Self> where Self: Sized;
|
|
|
|
fn part1(&self) -> Result<String>;
|
|
|
|
fn part2(&self) -> Result<String>;
|
2021-12-16 20:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! day_tests {
|
|
|
|
($day_struct:ty, $day_number:expr, $part1_expected:expr, $part2_expected:expr) => {
|
|
|
|
#[test]
|
|
|
|
fn part1_real() -> anyhow::Result<()> {
|
|
|
|
use crate::day::Day;
|
|
|
|
let d = <$day_struct>::init(crate::load_input($day_number)?)?;
|
|
|
|
assert_eq!($part1_expected, d.part1()?);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn part2_real() -> anyhow::Result<()> {
|
|
|
|
use crate::day::Day;
|
|
|
|
let d = <$day_struct>::init(crate::load_input($day_number)?)?;
|
|
|
|
assert_eq!($part2_expected, d.part2()?);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
};
|
2021-12-01 17:07:17 +01:00
|
|
|
}
|