This commit is contained in:
nora 2023-12-03 13:05:25 +01:00
parent b093225df0
commit 7be7e7c549
3 changed files with 52 additions and 36 deletions

View file

@ -25,9 +25,9 @@ fn main() {
println!("result: {result}"); println!("result: {result}");
} }
struct Day4; struct Day2;
impl Day for Day4 { impl Day for Day2 {
fn part1() -> helper::Variants { fn part1() -> helper::Variants {
Variants::basic(part1) Variants::basic(part1)
} }
@ -101,23 +101,14 @@ fn part2(input: &str) -> u64 {
.sum() .sum()
} }
#[cfg(test)] helper::tests! {
mod tests { day2 Day2;
#[test] part1 {
fn part1() { small => 8;
helper::test_part1::<super::Day4>(&[ default => 1931;
(include_str!("../input_small.txt"), 8),
(include_str!("../input.txt"), 1931),
]
);
} }
part2 {
#[test] small => 2286;
fn part2() { default => 83105;
helper::test_part2::<super::Day4>(&[
(include_str!("../input_small.txt"), 2286),
(include_str!("../input.txt"), 83105),
]
);
} }
} }

View file

@ -130,23 +130,14 @@ fn part2(input: &str) -> u64 {
.sum() .sum()
} }
#[cfg(test)] helper::tests! {
mod tests { day3 Day3;
#[test] part1 {
fn part1() { small => 4361;
helper::test_part1::<super::Day3>(&[ default => 537832;
(include_str!("../input_small.txt"), 4361),
(include_str!("../input.txt"), 537832),
]
);
} }
part2 {
#[test] small => 467835;
fn part2() { default => 81939900;
helper::test_part2::<super::Day3>(&[
(include_str!("../input_small.txt"), 467835),
(include_str!("../input.txt"), 81939900),
]
);
} }
} }

View file

@ -55,6 +55,40 @@ pub fn test_part2<D: Day>(inputs: &[(&str, u64)]) {
} }
} }
#[macro_export]
macro_rules! tests {
(
$day_small:ident $day:ident;
part1 {
small => $p1small:expr;
default => $p1default:expr;
}
part2 {
small => $p2small:expr;
default => $p2default:expr;
}
) => {
#[cfg(test)]
mod $day_small {
#[test]
fn part1() {
helper::test_part1::<super::$day>(&[
(include_str!("../input_small.txt"), $p1small),
(include_str!("../input.txt"), $p1default),
]);
}
#[test]
fn part2() {
helper::test_part2::<super::$day>(&[
(include_str!("../input_small.txt"), $p2small),
(include_str!("../input.txt"), $p2default),
]);
}
}
};
}
pub fn integer(input: &str) -> IResult<&str, u64> { pub fn integer(input: &str) -> IResult<&str, u64> {
map(digit1, |d: &str| d.parse::<u64>().unwrap())(input) map(digit1, |d: &str| d.parse::<u64>().unwrap())(input)
} }