feat: move data files out of src/

This commit is contained in:
Matej Janezic 2023-11-23 00:01:54 +01:00
parent 00000360a0
commit 000003708f
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
7 changed files with 26 additions and 25 deletions

4
.gitignore vendored
View File

@ -11,6 +11,6 @@ target/
.env
# downloaded inputs
/src/inputs/*
!/src/inputs/.keep
/data/inputs/*
!/data/inputs/.keep

6
Cargo.lock generated
View File

@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aoc"
version = "36.0.0"
version = "37.0.0"
dependencies = [
"itertools",
]
@ -105,7 +105,7 @@ checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0"
[[package]]
name = "download"
version = "36.0.0"
version = "37.0.0"
dependencies = [
"dotenvy",
"pico-args",
@ -643,7 +643,7 @@ checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "scaffold"
version = "36.0.0"
version = "37.0.0"
dependencies = [
"dotenvy",
"pico-args",

View File

@ -19,7 +19,7 @@ members = ["utils/download", "utils/scaffold"]
[workspace.package]
description = "template for advent of code"
readme = "README.md"
version = "36.0.0"
version = "37.0.0"
edition = "2021"
license = "MIT"
authors = ["Matej Janežič <janezic.mj@gmail.com>"]

View File

@ -11,8 +11,8 @@ pub const ANSI_BOLD: &str = "\x1b[1m";
pub const ANSI_RESET: &str = "\x1b[0m";
#[macro_export]
macro_rules! solve {
($part:expr, $solver:ident, $input:expr) => {{
macro_rules! solution {
($day:expr) => {
use aoc::{ANSI_BOLD, ANSI_ITALIC, ANSI_RESET};
use std::fmt::Display;
use std::time::Instant;
@ -34,16 +34,20 @@ macro_rules! solve {
}
}
println!("🎄 {}Part {}{} 🎄", ANSI_BOLD, $part, ANSI_RESET);
print_result($solver, $input);
}};
fn main() {
let input = aoc::read_file("inputs", 1);
println!("🎄 {}Part {}{} 🎄", ANSI_BOLD, 1, ANSI_RESET);
print_result(part_one, &input);
println!("🎄 {}Part {}{} 🎄", ANSI_BOLD, 1, ANSI_RESET);
print_result(part_two, &input);
}
};
}
#[must_use]
pub fn read_file(folder: &str, day: u8) -> String {
let cwd = env::current_dir().unwrap();
let filepath = cwd.join("src").join(folder).join(format!("{day:02}.txt"));
let filepath = cwd.join("data").join(folder).join(format!("{day:02}.txt"));
let f = fs::read_to_string(filepath);
f.expect("could not open input file").trim().to_string()
}

View File

@ -11,26 +11,23 @@ use std::{
const MODULE_TEMPLATE: &str = r#"pub fn part_one(input: &str) -> Option<u32> {
None
}
pub fn part_two(input: &str) -> Option<u32> {
None
}
fn main() {
let input = &aoc::read_file("inputs", DAY);
aoc::solve!(1, part_one, input);
aoc::solve!(2, part_two, input);
}
aoc::solution!(DAY);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part_one() {
let input = aoc::read_file("examples", DAY);
assert_eq!(part_one(&input), None);
assert_eq!(part_one(&aoc::read_file("examples", DAY)), None);
}
#[test]
fn test_part_two() {
let input = aoc::read_file("examples", DAY);
assert_eq!(part_two(&input), None);
assert_eq!(part_two(&aoc::read_file("examples", DAY)), None);
}
}
"#;
@ -59,8 +56,8 @@ fn main() {
let day_padded = format!("{day:02}");
let input_path = format!("src/inputs/{day_padded}.txt");
let example_path = format!("src/examples/{day_padded}.txt");
let input_path = format!("data/inputs/{day_padded}.txt");
let example_path = format!("data/examples/{day_padded}.txt");
let module_path = format!("src/bin/{day_padded}.rs");
let mut file = match safe_create_file(&module_path) {