feat: solved day 15 part 2
This commit is contained in:
@@ -27,4 +27,15 @@ public class PuzzleParserTests
|
||||
|
||||
await Assert.That(result).IsEqualTo(1318523);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartTwoSolution_WhenGivenPuzzleInput_ItShouldReturnExpectedSolution()
|
||||
{
|
||||
var input = await GetPuzzleInput();
|
||||
var (map, directions) = PuzzleParser.Parse(input);
|
||||
|
||||
var result = map.Scale().MoveRobot(directions).CalculateTotalBoxGpsCoordinates();
|
||||
|
||||
await Assert.That(result).IsEqualTo(1337648);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,70 @@ public class WarehouseMapTests
|
||||
"<^^>>>vv<v>>v<<",
|
||||
];
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(ScaleTestCases))]
|
||||
public async Task Scale_WhenCalled_ItShouldReturnExpectedMap(ScaleTestCase testCase)
|
||||
{
|
||||
var expected = WideWarehouseMap.From(testCase.ExpectedMap);
|
||||
|
||||
var result = WarehouseMap.From(testCase.MapInput).Scale();
|
||||
|
||||
await Assert.That(result.Positions).IsEquivalentTo(expected.Positions);
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<ScaleTestCase>> ScaleTestCases()
|
||||
{
|
||||
yield return () => new(
|
||||
[
|
||||
"##########",
|
||||
"#..O..O.O#",
|
||||
"#......O.#",
|
||||
"#.OO..O.O#",
|
||||
"#..O@..O.#",
|
||||
"#O#..O...#",
|
||||
"#O..O..O.#",
|
||||
"#.OO.O.OO#",
|
||||
"#....O...#",
|
||||
"##########",
|
||||
],
|
||||
[
|
||||
"####################",
|
||||
"##....[]....[]..[]##",
|
||||
"##............[]..##",
|
||||
"##..[][]....[]..[]##",
|
||||
"##....[]@.....[]..##",
|
||||
"##[]##....[]......##",
|
||||
"##[]....[]....[]..##",
|
||||
"##..[][]..[]..[][]##",
|
||||
"##........[]......##",
|
||||
"####################",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"#######",
|
||||
"#...#.#",
|
||||
"#.....#",
|
||||
"#..OO@#",
|
||||
"#..O..#",
|
||||
"#.....#",
|
||||
"#######",
|
||||
],
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##....[][]@.##",
|
||||
"##....[]....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public record ScaleTestCase(string[] MapInput, string[] ExpectedMap);
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(MoveTestCases))]
|
||||
public async Task Move_WhenCalled_ItShouldMoveValuesToExpectedPositions(MoveTestCase testCase)
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
namespace WarehouseWoes.Tests;
|
||||
|
||||
public class WideWarehouseMapTests
|
||||
{
|
||||
[Test]
|
||||
[MethodDataSource(nameof(CalculateTotalBoxGpsCoordinatesTestCases))]
|
||||
public async Task CalculateTotalBoxGpsCoordinates_WhenCalledWithExampleInput_ItShouldReturnExpectedValue(CalculateTotalBoxGpsCoordinatesTestCase testCase)
|
||||
{
|
||||
var map = WideWarehouseMap.From(testCase.MapInput);
|
||||
|
||||
var result = map.CalculateTotalBoxGpsCoordinates();
|
||||
|
||||
await Assert.That(result).IsEqualTo(testCase.ExpectedValue);
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<CalculateTotalBoxGpsCoordinatesTestCase>> CalculateTotalBoxGpsCoordinatesTestCases()
|
||||
{
|
||||
yield return () => new(
|
||||
[
|
||||
"####################",
|
||||
"##[].......[].[][]##",
|
||||
"##[]...........[].##",
|
||||
"##[]........[][][]##",
|
||||
"##[]......[]....[]##",
|
||||
"##..##......[]....##",
|
||||
"##..[]............##",
|
||||
"##..@......[].[][]##",
|
||||
"##......[][]..[]..##",
|
||||
"####################",
|
||||
],
|
||||
9021
|
||||
);
|
||||
}
|
||||
|
||||
public record CalculateTotalBoxGpsCoordinatesTestCase(string[] MapInput, int ExpectedValue);
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(MoveTestCases))]
|
||||
public async Task Move_WhenCalled_ItShouldMoveValuesToExpectedPositions(MoveTestCase testCase)
|
||||
{
|
||||
var expected = WideWarehouseMap.From(testCase.ExpectedMap);
|
||||
var directions = testCase.Directions.Select(Direction.From).ToList();
|
||||
|
||||
var result = WideWarehouseMap.From(testCase.MapInput).MoveRobot(directions);
|
||||
|
||||
await Assert.That(result.Positions).IsEquivalentTo(expected.Positions);
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<MoveTestCase>> MoveTestCases()
|
||||
{
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##....[][]@.##",
|
||||
"##....[]....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"<",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]@..##",
|
||||
"##....[]....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]@..##",
|
||||
"##....[]....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"v",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[].@..##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[].@..##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"v",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.......@..##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.......@..##",
|
||||
"##############",
|
||||
],
|
||||
"<",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##......@...##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##......@...##",
|
||||
"##############",
|
||||
],
|
||||
"<",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##..........##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##############",
|
||||
],
|
||||
"^",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"^",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##.....@....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"<",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##....@.....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##....@.....##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"<",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##...@......##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##....[]....##",
|
||||
"##...@......##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"^",
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##...@[]....##",
|
||||
"##..........##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
|
||||
yield return () => new(
|
||||
[
|
||||
"##############",
|
||||
"##......##..##",
|
||||
"##...[][]...##",
|
||||
"##...@[]....##",
|
||||
"##..........##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
],
|
||||
"^",
|
||||
[
|
||||
"##############",
|
||||
"##...[].##..##",
|
||||
"##...@.[]...##",
|
||||
"##....[]....##",
|
||||
"##..........##",
|
||||
"##..........##",
|
||||
"##############",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public record MoveTestCase(string[] MapInput, string Directions, string[] ExpectedMap);
|
||||
}
|
||||
Reference in New Issue
Block a user