Reimplement test macro as a generic function.

This commit is contained in:
2020-12-25 09:31:44 +01:00
parent 4c3640e994
commit 40a9cb63ff
21 changed files with 47 additions and 54 deletions

View File

@@ -67,19 +67,12 @@ pub fn get_implementation(day: usize) -> Box<dyn Solution> {
}
#[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);
}