public void Parse_IfNotSupportedFormat_Throw(string commands) { // Arrange SimpleCommandParser sut = CreateSut(); // Act Action act = () => sut.Parse(commands); // Assert act.Should().Throw <ArgumentException>() .WithMessage($"Unsupported format. (Parameter 'commands')"); }
public void Parse_IfSupportedFormat_DoesNotThrow() { // Arrange string commands = "RFRFRFRF"; SimpleCommandParser sut = CreateSut(); // Act Action act = () => sut.Parse(commands); // Assert act.Should().NotThrow(); }
public void Parse_IfCommandNotNull_DoesNotThrow() { // Arrange string commands = string.Empty; SimpleCommandParser sut = CreateSut(); // Act Action act = () => sut.Parse(commands); // Assert act.Should().NotThrow <ArgumentNullException>(); }
public void Parse_IfCommandNull_Throws() { // Arrange string commands = null; SimpleCommandParser sut = CreateSut(); // Act Action act = () => sut.Parse(commands); // Assert act.Should().Throw <ArgumentNullException>() .WithMessage($"Parameter can not be null. (Parameter 'commands')"); }
public void Parse_ReturnsCommands() { // Arrange string commands = "RFLF"; SimpleCommandParser sut = CreateSut(); // Act IReadOnlyCollection <IRobotCommand> resultCommands = sut.Parse(commands); // Assert Type[] expectedTypes = new Type[] { typeof(RCommand), typeof(FCommand), typeof(LCommand), typeof(FCommand) }; Type[] actualTypes = resultCommands.Select(command => command.GetType()).ToArray(); actualTypes.Should().Equal(expectedTypes); }
private void Run() { var area = new RectangularAreaParser().Parse(Console.ReadLine()); var parser = new SimpleStateParser(); foreach (var item in GetInputs().ToArray()) { var state = parser.Parse(item.State); var robot = new SimpleRobot { Area = area, LastPosition = state.Position, Orientation = state.Orientation }; var commands = new SimpleCommandParser(robot).Parse(item.Commands); foreach (var command in commands) { command.Execute(); } Console.WriteLine($"{robot.LastPosition.X} {robot.LastPosition.Y} {robot.Orientation}" + $"{(robot.Status == Status.Lost ? ' ' + robot.Status.ToString() : string.Empty)}"); } }