Skip to content

Commit 3f0754b

Browse files
committed
Lazily access the puzzle input to avoid querying it when testing with the example
1 parent bf36eaa commit 3f0754b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/AdventOfCode.Commons/Solver.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ public abstract class Solver<TInput, TResult>
1818
/// <summary>
1919
/// The puzzle input
2020
/// </summary>
21-
public readonly TInput PuzzleInput;
21+
public readonly Lazy<TInput> PuzzleInput;
2222

2323
/// <summary>
2424
/// Create a new solver and initialize its puzzle input based on the provided <see cref="IPuzzleInputReaderStrategy"/>
2525
/// </summary>
2626
/// <param name="puzzleInputReader">The strategy to use to retriever the puzzle input</param>
2727
private Solver(IPuzzleInputReaderStrategy puzzleInputReader)
2828
{
29-
var content = puzzleInputReader.ReadInput();
30-
PuzzleInput = ParseInput(content);
29+
PuzzleInput = new Lazy<TInput>(() =>
30+
{
31+
var content = puzzleInputReader.ReadInput();
32+
return ParseInput(content);
33+
});
3134
}
3235

3336
/// <summary>

src/AdventOfCode.Commons/TestEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void PartOneSolutionTest()
101101
var input = _solver.PuzzleInput;
102102

103103
// Act
104-
var result = _solver.PartOne(input);
104+
var result = _solver.PartOne(input.Value);
105105

106106
// Assert
107107
result.Should().Be(PartOne.Solution);
@@ -137,7 +137,7 @@ public void PartTwoSolutionTest()
137137
var input = _solver.PuzzleInput;
138138

139139
// Act
140-
var result = _solver.PartTwo(input);
140+
var result = _solver.PartTwo(input.Value);
141141

142142
// Assert
143143
result.Should().Be(PartTwo.Solution);

0 commit comments

Comments
 (0)