Use macros for tests

This commit is contained in:
2020-12-02 22:37:19 +01:00
parent f8adae8dc0
commit b25a4bc1ba
3 changed files with 25 additions and 14 deletions

View File

@@ -19,3 +19,20 @@ pub fn get_implementation(day: usize) -> Box<dyn Solution> {
_ => panic!("Unsupported day {}", day),
}
}
#[macro_export]
macro_rules! test_implementation {
($impl:ident, 1, $source:ident, $output:expr) => {
let mut implementation = $impl::default();
let result = implementation.part1(&mut $source.as_ref());
assert_eq!($output.to_string(), result);
};
($impl:ident, 2, $source:ident, $output:expr) => {
let mut implementation = $impl::default();
let result = implementation.part2(&mut $source.as_ref());
assert_eq!($output.to_string(), result);
};
}