extract day and typealias from macro

This commit is contained in:
kageru 2022-11-29 12:45:03 +01:00
parent 927d1ccce3
commit a6dfde6fc5
3 changed files with 36 additions and 39 deletions

View File

@ -7,21 +7,10 @@ echo '#![feature(test)]
extern crate test;
use aoc2022::{boilerplate, common::*};
fn parse_input(raw: &str) -> Parsed {
unimplemented!()
}
fn part1(parsed: &Parsed) -> usize {
unimplemented!()
}
fn part2(parsed: &Parsed) -> usize {
unimplemented!()
}
const DAY: usize = 0;
type Parsed = Vec<usize>;
boilerplate! {
DAY = '$today',
type = Vec<usize>,
TEST_INPUT == "",
tests: {
part1: { TEST_INPUT => 0 },
@ -30,4 +19,16 @@ boilerplate! {
bench1 == 0,
bench2 == 0,
parse: Vec::len => 0,
}
fn parse_input(raw: &str) -> Parsed {
parse_nums()
}
fn part1(parsed: &Parsed) -> usize {
unimplemented!()
}
fn part2(parsed: &Parsed) -> usize {
unimplemented!()
}' > src/bin/day$today.rs

View File

@ -2,6 +2,28 @@
extern crate test;
use aoc2022::{boilerplate, common::*};
const DAY: usize = 0;
type Parsed = Vec<usize>;
boilerplate! {
TEST_INPUT == "1721
979
366
299
675
1456",
tests: {
part1: {
TEST_INPUT => 514579,
"1234\n786" => 969924,
},
part2: { TEST_INPUT => 241861950 },
},
bench1 == 731731,
bench2 == 116115990,
parse: Vec::len => 200,
}
/// Naive solution for a previous day 1,
/// just to test my test setup for this year.
@ -32,24 +54,3 @@ fn part2(parsed: &Parsed) -> usize {
}
unreachable!()
}
boilerplate! {
DAY = 0,
type = Vec<usize>,
TEST_INPUT == "1721
979
366
299
675
1456",
tests: {
part1: {
TEST_INPUT => 514579,
"1234\n786" => 969924,
},
part2: { TEST_INPUT => 241861950 },
},
bench1 == 731731,
bench2 == 116115990,
parse: Vec::len => 200,
}

View File

@ -1,8 +1,6 @@
#[macro_export]
macro_rules! boilerplate {
(
DAY = $day: literal,
type = $type: ty,
TEST_INPUT == $ti: literal,
tests: {
$($part: ident: { $($tpi: expr => $to: literal$(,)?)+ }$(,)?)*
@ -11,9 +9,6 @@ macro_rules! boilerplate {
bench2 == $b2: literal,
parse: $input_fn: expr => $it: literal$(,)?
) => {
const DAY: usize = $day;
type Parsed = $type;
fn main() {
let input = parse_input(&read_file(DAY));
println!("Part 1: {}", part1(&input));