Added the ability to have more then one test input, and fixed actual input
This commit is contained in:
parent
a6a2385a85
commit
a52cdafb8a
2500
2022/input/2/input
Normal file
2500
2022/input/2/input
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -6,11 +6,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn part1() {
|
fn part1() {
|
||||||
Day::test(aoc::Part::ONE);
|
Day::test(aoc::Part::ONE, "test-1", 24000);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn part2() {
|
fn part2() {
|
||||||
Day::test(aoc::Part::TWO);
|
Day::test(aoc::Part::TWO, "test-1", 45000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn part1() {
|
fn part1() {
|
||||||
Day::test(aoc::Part::ONE);
|
Day::test(aoc::Part::ONE, "test-1", 0);
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn part2() {
|
|
||||||
Day::test(aoc::Part::TWO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub trait Solver {
|
||||||
fn part1(input: &str) -> u32;
|
fn part1(input: &str) -> u32;
|
||||||
fn part2(input: &str) -> u32;
|
fn part2(input: &str) -> u32;
|
||||||
|
|
||||||
fn test(part: Part) {
|
fn test(part: Part, name: &str, result: u32) {
|
||||||
// Select the right function
|
// Select the right function
|
||||||
let fun = match part {
|
let fun = match part {
|
||||||
Part::ONE => Self::part1,
|
Part::ONE => Self::part1,
|
||||||
|
@ -18,31 +18,14 @@ pub trait Solver {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read the test input
|
// Read the test input
|
||||||
let test = fs::read_to_string(format!("input/{}/test", Self::day())).expect("Test file does not exist!");
|
let input = fs::read_to_string(format!("input/{}/{name}", Self::day())).expect("Test file does not exist!");
|
||||||
|
|
||||||
// Get the correct test result
|
|
||||||
let result: u32 = match test.split("\n")
|
|
||||||
.skip(part as usize)
|
|
||||||
.next()
|
|
||||||
.expect("Expected second line to contain result for part1")
|
|
||||||
.parse() {
|
|
||||||
Ok(result) => result,
|
|
||||||
_ => 0, // Use zero if no value is specified yet
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get the input for the test
|
|
||||||
// @TODO This creates a new string, would be nice if we could actually get a slice here
|
|
||||||
let input = test.split("\n")
|
|
||||||
.skip(2)
|
|
||||||
.collect::<Vec<&str>>()
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
// Assert that the result matches the expected value
|
// Assert that the result matches the expected value
|
||||||
assert_eq!(fun(&input), result);
|
assert_eq!(fun(&input), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solve() {
|
fn solve() {
|
||||||
let input = fs::read_to_string(format!("input/{}/test", Self::day())).expect("Input file does not exist!");
|
let input = fs::read_to_string(format!("input/{}/input", Self::day())).expect("Input file does not exist!");
|
||||||
println!("Part 1: {}", Self::part1(&input));
|
println!("Part 1: {}", Self::part1(&input));
|
||||||
println!("Part 2: {}", Self::part2(&input));
|
println!("Part 2: {}", Self::part2(&input));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user