28 lines
828 B
Rust
28 lines
828 B
Rust
use anyhow::Result;
|
|
|
|
pub trait Day {
|
|
fn init(content: String) -> Result<Self> where Self: Sized;
|
|
fn part1(&self) -> Result<String>;
|
|
fn part2(&self) -> Result<String>;
|
|
}
|
|
|
|
#[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(())
|
|
}
|
|
};
|
|
} |