1
0
Fork 0

add cfg(test_input)

main
Andrew Coleman 2022-12-07 14:16:10 -05:00
parent 3905fdb350
commit bb9d2d5c6a
9 changed files with 53 additions and 1 deletions

View File

@ -5,5 +5,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
test_input = []
[dependencies]
anyhow = "1.0.66"

View File

@ -2,7 +2,12 @@ use anyhow::Result;
use std::fs;
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day1.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day1.txt")?;
let lines = file_contents.lines();
let mut calories = Vec::with_capacity(lines.clone().count());
let mut count: u32 = 0;

View File

@ -14,7 +14,12 @@ enum EndStates {
}
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day2.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day2.txt")?;
let lines = file_contents.lines();
let mut part_one_scores: Vec<u32> = Vec::with_capacity(1000);
let mut part_two_scores: Vec<u32> = Vec::with_capacity(1000);

View File

@ -13,7 +13,12 @@ fn get_priority(t: &char) -> u32 {
}
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day3.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day3.txt")?;
let lines = file_contents.lines();
let mut rucksacks: Vec<u32> = Vec::with_capacity(1000);
let mut rucksacks2: Vec<u32> = Vec::with_capacity(1000);

View File

@ -2,7 +2,12 @@ use anyhow::Result;
use std::fs;
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day4.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day4.txt")?;
let lines = file_contents.lines();
let mut part_one_pairs = 0;
let mut part_two_pairs = 0;

View File

@ -2,7 +2,12 @@ use anyhow::Result;
use std::fs;
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day5.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day5.txt")?;
let mut stacks: Vec<Vec<&str>> = Vec::with_capacity(10);
let mut moves: Vec<(usize, usize, usize)> = Vec::with_capacity(1000);
let mut numstacks: usize = 0;

View File

@ -24,7 +24,13 @@ fn unique_run_position<'a>(line: &'a str, count: usize) -> usize {
}
pub fn run() -> Result<()> {
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day6.txt")?;
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day6.txt")?;
let lines = file_contents.lines();
let mut line_counter = 0;

View File

@ -86,8 +86,11 @@ fn part_two_recurse<'a>(map: &mut BTreeMap<u32, &'a str>, dir: &'a Dir) {
}
pub fn run() -> Result<()> {
#[cfg(feature = "test_input")]
let file_contents = fs::read_to_string("tests/day7.txt")?;
#[cfg(not(feature = "test_input"))]
let file_contents = fs::read_to_string("day7.txt")?;
//let file_contents = fs::read_to_string("tests/day7.txt")?;
let mut root = Dir {
name: String::from("/"),

14
2022/tests/day1.txt Normal file
View File

@ -0,0 +1,14 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000