Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions 2024/Advent.Tests/Commands/Day25CommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Advent.Common.Settings;
using Spectre.Console.Cli;

namespace Advent.Tests.Commands;

public class Day25CommandTests
{
private readonly List<string> _arguments = [];
private readonly IRemainingArguments _remaining = Substitute.For<IRemainingArguments>();
private readonly TestConsole console = new();

public Day25CommandTests()
{
console.Profile.Capabilities.Interactive = true;
}

[Fact]
public async Task Day25Command_Solves_Part1_Correctly()
{
var mockReader = Substitute.For<IFileReader>();
mockReader
.ReadInputAsync(Arg.Any<string>())
.Returns(Task.FromResult(TestData.Day25TestData));

var command = new Day25Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day25", null),
new AdventSettings { Part = "Part 1" }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 25 Part 1");
console.Output.Should().Contain("The answer is 3");
}
}
9 changes: 5 additions & 4 deletions 2024/Advent.Tests/Commands/Day4CommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Advent.Common.Settings;
using Advent.UseCases.Day4;
using Spectre.Console.Cli;

Expand Down Expand Up @@ -30,7 +31,7 @@ public async Task Day4Command_Solves_Part1_Correctly()
var command = new Day4Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day4", null),
new Day4Settings { Part = "Part 1", Word = "XMAS" }
new AdventSettings { Part = "Part 1" }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 4 Part 1");
Expand All @@ -46,7 +47,7 @@ public async Task Day4Command_Solves_Part2_Correctly()
var command = new Day4Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day4", null),
new Day4Settings { Part = "Part 2", Word = "MAS" }
new AdventSettings { Part = "Part 2" }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 4 Part 2");
Expand All @@ -64,7 +65,7 @@ public async Task Day4Command_Prompts_For_Part_1()
var command = new Day4Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day4", null),
new Day4Settings() { Word = "XMAS" }
new AdventSettings() { }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 4 Part 1");
Expand All @@ -83,7 +84,7 @@ public async Task Day4Command_Prompts_For_Part_2()
var command = new Day4Command(mockReader, console);
var result = await command.ExecuteAsync(
new CommandContext(_arguments, _remaining, "day4", null),
new Day4Settings() { Word = "MAS" }
new AdventSettings() { }
);
result.Should().Be(0);
console.Output.Should().Contain("Day 4 Part 2");
Expand Down
41 changes: 41 additions & 0 deletions 2024/Advent.Tests/Common/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,45 @@ internal static class TestData
+ "hwm AND bqk -> z03\n"
+ "tgd XOR rvg -> z12\n"
+ "tnw OR pbm -> gnj\n";

public const string Day25TestData =
"#####\n"
+ ".####\n"
+ ".####\n"
+ ".####\n"
+ ".#.#.\n"
+ ".#...\n"
+ ".....\n"
+ "\n\n"
+ "#####\n"
+ "##.##\n"
+ ".#.##\n"
+ "...##\n"
+ "...#.\n"
+ "...#.\n"
+ ".....\n"
+ "\n"
+ ".....\n"
+ "#....\n"
+ "#....\n"
+ "#...#\n"
+ "#.#.#\n"
+ "#.###\n"
+ "#####\n"
+ "\n"
+ ".....\n"
+ ".....\n"
+ "#.#..\n"
+ "###..\n"
+ "###.#\n"
+ "###.#\n"
+ "#####\n"
+ "\n"
+ ".....\n"
+ ".....\n"
+ ".....\n"
+ "#....\n"
+ "#.#..\n"
+ "#.#.#\n"
+ "#####\n";
}
24 changes: 24 additions & 0 deletions 2024/Advent.Tests/IntegrationTests/CommandAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,31 @@ public async Task Day24Part2_IntegrationTest_Success()
result.Output.Should().Contain("Day 24 Part 2");
result.Output.Should().Contain("The answer is cvh,dbb,hbk,kvn,tfn,z14,z18,z23");
}
#endregion

#region Day25
[Fact]
public async Task Day25Part1_IntegrationTest_Success()
{
// Arrange
var args = new string[] { "day25", "--part", "Part 1" };
var app = new CommandAppTester(_registrar);

app.Configure(config =>
{
config.PropagateExceptions();
config.ConfigureConsole(_console);
config.AddCommand<Day25Command>("day25");
});

// Act
var result = await app.RunAsync(args);

// Assert
result.ExitCode.Should().Be(0);
result.Output.Should().Contain("Day 25 Part 1");
result.Output.Should().Contain("The answer is 2586");
}
#endregion
}

Expand Down
3 changes: 1 addition & 2 deletions 2024/Advent.Tests/UseCases/Day1/Day1ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ public class Day1ParserTests
public void Parse_ShouldReturnTwoListsOfInts()
{
// Arrange
var parser = new Day1Parser();
var input = "17211 12345\n" + "12397 34356\n" + "36633 45832\n" + "29933 67531\n";

// Act
var result = parser.Parse(input);
var result = Day1Parser.Parse(input);

// Assert
result.Item1.Should().BeEquivalentTo([17211, 12397, 36633, 29933]);
Expand Down
6 changes: 1 addition & 5 deletions 2024/Advent.Tests/UseCases/Day2/Day2ParsterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public class Day2ParserTests
[Fact]
public void Parse_ShouldReturnCorrectNumberOfLists()
{
// Arrange
var parser = new Day2Parser();

// Act
var result = parser.Parse(TestData).ToList();
var result = Day2Parser.Parse(TestData).ToList();

// Assert
result.Count.Should().Be(6);
Expand Down
33 changes: 33 additions & 0 deletions 2024/Advent.Tests/UseCases/Day25/Day25ParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Advent.UseCases.Day25;

namespace Advent.Tests.UseCases.Day25;

public class Day25ParserTests
{
[Fact]
public void Parse_WhenInputIsValid_ReturnsDay25Input()
{
// Arrange
var expectedLocks = new List<GridData>
{
new(["#####", ".####", ".####", ".####", ".#.#.", ".#...", "....."]),
new(["#####", "##.##", ".#.##", "...##", "...#.", "...#.", "....."])
};

var expectedKeys = new List<GridData>
{
new([".....", "#....", "#....", "#...#", "#.#.#", "#.###", "#####"]),
new([".....", ".....", "#.#..", "###..", "###.#", "###.#", "#####"]),
new([".....", ".....", ".....", "#....", "#.#..", "#.#.#", "#####"])
};

// Act
(var locks, var keys) = Day25Parser.Parse(TestData.Day25TestData);

// Assert
locks.Should().HaveCount(2);
locks.Should().BeEquivalentTo(expectedLocks);
keys.Should().HaveCount(3);
keys.Should().BeEquivalentTo(expectedKeys);
}
}
20 changes: 20 additions & 0 deletions 2024/Advent.Tests/UseCases/Day25/Day25Part1Solver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Advent.UseCases.Day25;

namespace Advent.Tests.UseCases.Day25;

public class Day25Part1SolverTests
{
[Fact]
public void Solve_WhenInputIsValid_ReturnsCorrectResult()
{
// Arrange
var input = Day25Parser.Parse(TestData.Day25TestData);
var solver = new Day25Part1Solver();

// Act
var result = solver.Solve(input);

// Assert
result.Should().Be("3");
}
}
5 changes: 1 addition & 4 deletions 2024/Advent.Tests/UseCases/Day4/Day4ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public void Parse_ShouldCreateCorrectFlatCrossword()
var input = "123\n456\n789";
var result = Day4Parser.Parse(input);

result
.FlatCrossword.ToArray()
.Should()
.BeEquivalentTo(['1', '2', '3', '4', '5', '6', '7', '8', '9']);
result.FlatCrossword.Should().BeEquivalentTo(['1', '2', '3', '4', '5', '6', '7', '8', '9']);
}

[Fact]
Expand Down
27 changes: 1 addition & 26 deletions 2024/Advent.Tests/UseCases/Day4/Day4Part1SolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,6 @@ namespace Advent.Tests.UseCases.Day4;

public class Day4Part1SolverTests
{
[Fact]
public void Solve_ShouldReturnCorrectCount()
{
// data that is a 10x10 crossword puzzle
var data = new Day4Data(
[
"1234167890",
"1234267890",
"1234367890",
"1233367890",
"3321267890",
"1234167893",
"3234567831",
"1334567220",
"1224561390",
"1231563890"
]
);
var solver = new Day4Part1Solver("1233");

var result = solver.Solve(data);

result.Should().Be(8);
}

[Fact]
public void Solve_ShouldReturnCorrectCount_For_XMAS()
{
Expand All @@ -47,7 +22,7 @@ public void Solve_ShouldReturnCorrectCount_For_XMAS()
"MXMXAXMASX"
]
);
var solver = new Day4Part1Solver("XMAS");
var solver = new Day4Part1Solver();

var result = solver.Solve(data);

Expand Down
35 changes: 1 addition & 34 deletions 2024/Advent.Tests/UseCases/Day4/Day4Part2SolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,6 @@ namespace Advent.Tests.UseCases.Day4;

public class Day4Part2SolverTests
{
[Fact]
public void Solve_ShouldReturnCorrectCount()
{
// data that is a 10x10 crossword puzzle
var data = new Day4Data(
[
"1234167890",
"1234267890",
"1234367890",
"1233367890",
"3321267890",
"1234167893",
"3234567831",
"1334567220",
"1224561390",
"1231563890"
]
);
var solver = new Day4Part2Solver("123");

var result = solver.Solve(data);

result.Should().Be(4);
}

[Fact]
public void Solve_ShouldReturnCorrectCount_For_XMAS()
{
Expand All @@ -47,18 +22,10 @@ public void Solve_ShouldReturnCorrectCount_For_XMAS()
"MXMXAXMASX"
]
);
var solver = new Day4Part2Solver("MAS");
var solver = new Day4Part2Solver();

var result = solver.Solve(data);

result.Should().Be(9);
}

[Fact]
public void Solve_ShouldThrowArgumentException_WhenWordLengthIsEven()
{
Action act = static () => _ = new Day4Part2Solver("1234");

act.Should().Throw<ArgumentException>().WithMessage("Word must have an odd length");
}
}
15 changes: 4 additions & 11 deletions 2024/Advent.Tests/UseCases/Day9/Day9ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ namespace Advent.Tests.UseCases.Day9;

public class Day9ParserTests
{
private readonly Day9Parser _parser;

public Day9ParserTests()
{
_parser = new Day9Parser();
}

[Fact]
public void Parse_WhenInputIsEmpty_ThrowsInvalidOperationException()
{
// Arrange
var input = "";

// Act
Action act = () => _parser.Parse(input);
Action act = () => Day9Parser.Parse(input);

// Assert
act.Should().Throw<InvalidOperationException>();
Expand All @@ -31,7 +24,7 @@ public void Parse_WhenInputIsInvalid_ThrowsInvalidOperationException()
var input = "0";

// Act
Action act = () => _parser.Parse(input);
Action act = () => Day9Parser.Parse(input);

// Assert
act.Should().Throw<InvalidOperationException>();
Expand Down Expand Up @@ -62,7 +55,7 @@ public void Parse_WhenInputIsValid_DiskMap()
];

// Act
var result = _parser.Parse(input);
var result = Day9Parser.Parse(input);

// Assert
result.ToArray().Should().BeEquivalentTo(expected);
Expand All @@ -73,7 +66,7 @@ public void Parse_WhenInputIsValie_DiskMap2()
{
var data = TestData.GetDay9ParsedData();
// Act
Span<uint> result = _parser.Parse(TestData.Day9ParserInput);
Span<uint> result = Day9Parser.Parse(TestData.Day9ParserInput);

var resultArray = result.ToArray();
// Assert
Expand Down
Loading
Loading