Files

295 lines
6.5 KiB
C#

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);
}