-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating some method names, adding manhattan distance.
Day 20 solutions.
- Loading branch information
1 parent
d3dadd6
commit d1552e5
Showing
13 changed files
with
390 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Advent.UseCases.Day20; | ||
using Spectre.Console.Cli; | ||
|
||
namespace Advent.Tests.Commands; | ||
|
||
public class Day20CommandTests | ||
{ | ||
private readonly List<string> _arguments = []; | ||
private readonly IRemainingArguments _remaining = Substitute.For<IRemainingArguments>(); | ||
private readonly TestConsole console = new(); | ||
|
||
public Day20CommandTests() | ||
{ | ||
console.Profile.Capabilities.Interactive = true; | ||
} | ||
|
||
[Fact] | ||
public async Task Day20Command_Solves_Part1_Correctly() | ||
{ | ||
var mockReader = Substitute.For<IFileReader>(); | ||
mockReader | ||
.ReadInputAsync(Arg.Any<string>()) | ||
.Returns(Task.FromResult(TestData.Day20TestData)); | ||
|
||
var command = new Day20Command(mockReader, console); | ||
var result = await command.ExecuteAsync( | ||
new CommandContext(_arguments, _remaining, "day20", null), | ||
new Day20Settings { Part = "Part 1", Threshold = 0 } | ||
); | ||
result.Should().Be(0); | ||
console.Output.Should().Contain("Day 20 Part 1"); | ||
console.Output.Should().Contain("The answer is 44"); | ||
} | ||
|
||
[Fact] | ||
public async Task Day20Command_Solves_Part2_Correctly() | ||
{ | ||
var mockReader = Substitute.For<IFileReader>(); | ||
mockReader | ||
.ReadInputAsync(Arg.Any<string>()) | ||
.Returns(Task.FromResult(TestData.Day20TestData)); | ||
|
||
var command = new Day20Command(mockReader, console); | ||
var result = await command.ExecuteAsync( | ||
new CommandContext(_arguments, _remaining, "day20", null), | ||
new Day20Settings { Part = "Part 2", Threshold = 50 } | ||
); | ||
result.Should().Be(0); | ||
console.Output.Should().Contain("Day 20 Part 2"); | ||
console.Output.Should().Contain("The answer is 285"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Advent.UseCases.Day20; | ||
using Advent.UseCases.Day6; | ||
|
||
namespace Advent.Tests.UseCases.Day20; | ||
|
||
public class Day20Part2SolverTests | ||
{ | ||
[Fact] | ||
public void Solve_ShouldReturnShortestPathLength_Part1Test() | ||
{ | ||
// Arrange | ||
var input = Day6Parser.Parse(TestData.Day20TestData); | ||
|
||
// Act | ||
var result = new Day20Solver(0, 2).Solve(input); | ||
|
||
// Assert | ||
result.Should().Be(44); | ||
} | ||
|
||
[Fact] | ||
public void Solve_ShouldReturnShortestPathLength_Part2Test() | ||
{ | ||
// Arrange | ||
var input = Day6Parser.Parse(TestData.Day20TestData); | ||
|
||
// Act | ||
var result = new Day20Solver(50, 20).Solve(input); | ||
|
||
// Assert | ||
result.Should().Be(285); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Advent.Common; | ||
using Advent.Common.Commands; | ||
using Advent.UseCases.Day20; | ||
using Advent.UseCases.Day6; | ||
using Spectre.Console; | ||
using Spectre.Console.Cli; | ||
|
||
namespace Advent.Commands; | ||
|
||
public class Day20Command(IFileReader reader, IAnsiConsole console) | ||
: AdventCommand<Day20Settings>(reader, console) | ||
{ | ||
public override async Task<int> ExecuteAsync(CommandContext context, Day20Settings settings) | ||
{ | ||
var input = await _reader.ReadInputAsync("../input/day20input.txt"); | ||
var data = Day6Parser.Parse(input); | ||
|
||
var choice = settings.Part ?? PromptForPartChoice(); | ||
IDay6Solver solver = choice switch | ||
{ | ||
"Part 1" => new Day20Solver(settings.Threshold, 2), | ||
"Part 2" => new Day20Solver(settings.Threshold, 20), | ||
_ => throw new InvalidOperationException("Invalid choice") | ||
}; | ||
|
||
var result = solver.Solve(data); | ||
_console.MarkupLine($"[bold green]Day 20 {choice} [/]"); | ||
_console.MarkupLine($"The answer is [bold yellow]{result}[/]"); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.