mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 13:20:32 +01:00
Reimplement test macro as a generic function.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user