advent-of-code/2021/src/teststuff.rs

38 lines
1.0 KiB
Rust
Raw Normal View History

2021-11-22 14:30:40 +01:00
#[macro_export]
macro_rules! bench {
($part: ident ($($param: expr),*) == $expected:expr) => {
2021-12-01 14:16:29 +01:00
paste::paste! {
2021-11-22 14:30:40 +01:00
#[bench]
fn [<$part _bench>](b: &mut test::Bencher) {
let raw = &read_file(DAY);
2021-11-22 14:30:40 +01:00
let input = parse_input(&raw);
2021-12-01 14:16:29 +01:00
b.iter(|| assert_eq!($part(test::black_box(&input)$(, $param)*), $expected));
2021-11-22 14:30:40 +01:00
}
}
};
}
#[macro_export]
macro_rules! bench_input {
($fn:ident == $expected_len:expr) => {
#[bench]
fn bench_input_parsing(b: &mut test::Bencher) {
let raw = &read_file(DAY);
2021-12-01 14:16:29 +01:00
b.iter(|| assert_eq!(parse_input(test::black_box(&raw)).$fn(), $expected_len));
2021-11-22 14:30:40 +01:00
}
};
}
#[macro_export]
macro_rules! test {
($part: ident ($($param: expr),*) == $expected:expr) => {
2021-12-01 14:16:29 +01:00
paste::paste! {
2021-11-22 14:30:40 +01:00
#[test]
fn [<$part _test>]() {
let input = parse_input(TEST_INPUT);
assert_eq!($part(&input$(, $param)*), $expected);
}
}
};
}