mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
Reimplement test macro as a generic function.
This commit is contained in:
@@ -55,11 +55,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day01, 1, SAMPLE, 514579);
|
||||
test_implementation(Day01, 1, SAMPLE, 514579);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day01, 2, SAMPLE, 241861950);
|
||||
test_implementation(Day01, 2, SAMPLE, 241861950);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day02, 1, SAMPLE, 2);
|
||||
test_implementation(Day02, 1, SAMPLE, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day02, 2, SAMPLE, 1);
|
||||
test_implementation(Day02, 2, SAMPLE, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day03, 1, SAMPLE, 7);
|
||||
test_implementation(Day03, 1, SAMPLE, 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day03, 2, SAMPLE, 336);
|
||||
test_implementation(Day03, 2, SAMPLE, 336);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day06, 1, SAMPLE, 11);
|
||||
test_implementation(Day06, 1, SAMPLE, 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day06, 2, SAMPLE, 6);
|
||||
test_implementation(Day06, 2, SAMPLE, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day07, 1, SAMPLE, 4);
|
||||
test_implementation(Day07, 1, SAMPLE, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day07, 2, SAMPLE, 32);
|
||||
test_implementation!(Day07, 2, SAMPLE2, 126);
|
||||
test_implementation(Day07, 2, SAMPLE, 32);
|
||||
test_implementation(Day07, 2, SAMPLE2, 126);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day08, 1, SAMPLE, 5);
|
||||
test_implementation(Day08, 1, SAMPLE, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day08, 2, SAMPLE, 8);
|
||||
test_implementation(Day08, 2, SAMPLE, 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +59,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day10, 1, SAMPLE, 35);
|
||||
test_implementation!(Day10, 1, SAMPLE2, 220);
|
||||
test_implementation(Day10, 1, SAMPLE, 35);
|
||||
test_implementation(Day10, 1, SAMPLE2, 220);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day10, 2, SAMPLE, 8);
|
||||
test_implementation!(Day10, 2, SAMPLE2, 19208);
|
||||
test_implementation(Day10, 2, SAMPLE, 8);
|
||||
test_implementation(Day10, 2, SAMPLE2, 19208);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day11, 1, SAMPLE, 37);
|
||||
test_implementation(Day11, 1, SAMPLE, 37);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day11, 2, SAMPLE, 26);
|
||||
test_implementation(Day11, 2, SAMPLE, 26);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day12, 1, SAMPLE, 25);
|
||||
test_implementation(Day12, 1, SAMPLE, 25);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day12, 2, SAMPLE, 286);
|
||||
test_implementation(Day12, 2, SAMPLE, 286);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day13, 1, SAMPLE, 295);
|
||||
test_implementation(Day13, 1, SAMPLE, 295);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day13, 2, SAMPLE, 1068781);
|
||||
test_implementation(Day13, 2, SAMPLE, 1068781);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +143,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day14, 1, SAMPLE, 165);
|
||||
test_implementation(Day14, 1, SAMPLE, 165);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day14, 2, SAMPLE2, 208);
|
||||
test_implementation(Day14, 2, SAMPLE2, 208);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -165,6 +165,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day16, 1, SAMPLE, 71);
|
||||
test_implementation(Day16, 1, SAMPLE, 71);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,11 +130,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day17, 1, SAMPLE, 112);
|
||||
test_implementation(Day17, 1, SAMPLE, 112);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day17, 2, SAMPLE, 848);
|
||||
test_implementation(Day17, 2, SAMPLE, 848);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,12 +125,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day19, 1, SAMPLE, 2);
|
||||
test_implementation(Day19, 1, SAMPLE, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day19, 1, SAMPLE2, 3);
|
||||
test_implementation!(Day19, 2, SAMPLE2, 12);
|
||||
test_implementation(Day19, 1, SAMPLE2, 3);
|
||||
test_implementation(Day19, 2, SAMPLE2, 12);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,12 +413,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day20, 1, SAMPLE, 20899048083289u64);
|
||||
test_implementation(Day20, 1, SAMPLE, 20899048083289u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day20, 2, SAMPLE, 273);
|
||||
test_implementation(Day20, 2, SAMPLE, 273);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -123,11 +123,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day21, 1, SAMPLE, 5);
|
||||
test_implementation(Day21, 1, SAMPLE, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day21, 2, SAMPLE, "mxmxvkd,sqjhc,fvjkl");
|
||||
test_implementation(Day21, 2, SAMPLE, "mxmxvkd,sqjhc,fvjkl");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day22, 1, SAMPLE, 306);
|
||||
test_implementation(Day22, 1, SAMPLE, 306);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day22, 2, SAMPLE, 291);
|
||||
test_implementation(Day22, 2, SAMPLE, 291);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day23, 2, SAMPLE, 149245887792u64);
|
||||
test_implementation(Day23, 2, SAMPLE, 149245887792u64);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day24, 1, SAMPLE, 10);
|
||||
test_implementation(Day24, 1, SAMPLE, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_part2() {
|
||||
test_implementation!(Day24, 2, SAMPLE, 2208);
|
||||
test_implementation(Day24, 2, SAMPLE, 2208);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_part1() {
|
||||
test_implementation!(Day25, 1, SAMPLE, 14897079);
|
||||
test_implementation(Day25, 1, SAMPLE, 14897079);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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