Skip to content

Support different example inputs for part 1 and part 2 in tests #37

Closed
@snorremd

Description

@snorremd

First of all, thank you for an amazing starter template. This repo makes it so easy to try out Rust for advent of code!

In AOC 2023 the first day puzzle has two example inputs, one for each part. The default read_file function only accepts a day which is strongly typed so you can only ever read 01.txt, etc.

In my project I just added a new function that takes a part number too:

pub fn read_file_part(folder: &str, day: Day, part: u8) -> String {
    let cwd = env::current_dir().unwrap();
    let filepath = cwd.join("data").join(folder).join(format!("{day}-{part}.txt"));
    let f = fs::read_to_string(filepath);
    f.expect("could not open input file")
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions