public void ExecuteCommands() { var gridCoord = CommandsParser.CommandToCoordinate(_gridCommand); if (gridCoord == null) { Console.WriteLine("Command {0} is invalid", _gridCommand); return; } var grid = new Grid(gridCoord.X, gridCoord.Y); foreach (var robotCmd in _robotCommands) { var coord = CommandsParser.CommandToCoordinate(robotCmd.Orientation); var orientation = CommandsParser.RobotCommandToOrientation(robotCmd.Orientation); if (CommandsParser.IsRobotCommandValid(coord, orientation)) { var robot = new Robot(coord.X, coord.Y, orientation, GetInstructionsParser(), grid); Console.WriteLine(robot.ExecuteInstructions(robotCmd.Instruction)); } else { Console.WriteLine("Command {0} is invalid", robotCmd.Orientation); } } }
public void ExecuteInstructions_Returns_1_1_E_For_RFRFRFRF() { // Arrange var expectedX = 1; var expectedY = 1; var expectedDegrees = 90; var instructions = "RFRFRFRF"; _sut = new Robot(1, 1, "E", _instructionsParser, _grid); // Act var result = _sut.ExecuteInstructions(instructions); // Assert Assert.AreEqual(expectedX, result.Coordinate.X); Assert.AreEqual(expectedY, result.Coordinate.Y); Assert.AreEqual(expectedDegrees, result.Degrees); }
public void Execute_Instructions_Calls_InstructionParser_Parse() { // Arrange var instructions = "RFFL"; var mockInstructionsParser = new Mock<IInstructionsParser>(); mockInstructionsParser.Setup(x => x.Parse(It.IsAny<string>())).Returns(new List<Instruction>()).Verifiable(); _sut = new Robot(0, 0, "E", mockInstructionsParser.Object, _grid); // Act _sut.ExecuteInstructions(instructions); // Assert mockInstructionsParser.VerifyAll(); }
public void ExecuteInstructions_Returns_Position() { // Arrange var instructions = "RFFL"; _sut = new Robot(0, 0, "E", _instructionsParser, _grid); // Act var result = _sut.ExecuteInstructions(instructions); // Assert Assert.IsInstanceOf<Position>(result); }
public void ExecuteInstructions_Returns_3_3_N_For_FRRFLLFFRRFLL() { // Arrange var expectedX = 3; var expectedY = 3; var expectedDegrees = 0; var instructions = "FRRFLLFFRRFLL"; _sut = new Robot(3, 2, "N", _instructionsParser, _grid); // Act var result = _sut.ExecuteInstructions(instructions); // Assert Assert.AreEqual(expectedX, result.Coordinate.X); Assert.AreEqual(expectedY, result.Coordinate.Y); Assert.AreEqual(expectedDegrees, result.Degrees); }