Created
November 17, 2020 17:30
-
-
Save ritobanrc/6100544aca8dd0e61374328640d408b5 to your computer and use it in GitHub Desktop.
A short script to easily handle the functions for advent of code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// The `main` function for each day is in `dayXX.rs`, called `dayXX_main()`. To | |
/// run all the solutions, simply run `cargo test`. Inputs should be placed in a folder | |
/// input/dayXX.txt. This also requires the `paste = "0.1.0"` and `anyhow = "1.0.0"` crates | |
/// for creating the function names and handing errors, respectively. | |
use std::io; | |
pub fn load_input(day: usize) -> io::Result<String> { | |
use std::fs::read_to_string; | |
use std::path::PathBuf; | |
let path: PathBuf = ["input", &format!("day{:02}.txt", day)].iter().collect(); | |
read_to_string(path) | |
} | |
#[macro_export] | |
macro_rules! aoc { | |
($day: expr) => { | |
paste::item! { | |
#[test] | |
fn [<day $day _test>]() -> anyhow::Result<()> { | |
[<day $day _main>]() | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment