public void GetCommand_Should_Success(int surfaceRowsCount, int surfaceColumnsCount, int robotPositionRow, int robotPositionColumn, SurfaceDirection surfaceDirection, string commandsString, int expectedPositionRow, int expectedPositionColumn, SurfaceDirection expectedDirection, bool expectedIsLost) { SurfaceGrid _marsSurface = new SurfaceGrid(surfaceRowsCount + 1, surfaceColumnsCount + 1); MarsInvasionControlCenter controlCenter = new MarsInvasionControlCenter(_marsSurface); var position = new SurfacePosition(robotPositionRow, robotPositionColumn); var newRobot = controlCenter.AddNewRobot(position, surfaceDirection); if (!newRobot.IsLost) { var commandSet = RobotCommandSet.Create(_commandsFactory, commandsString); newRobot.ExecuteCommands(commandSet); PrintPosition(newRobot); } else { PrintPosition(newRobot); } Assert.AreEqual(expectedPositionRow, newRobot.Position.Row); Assert.AreEqual(expectedPositionColumn, newRobot.Position.Column); Assert.AreEqual(expectedDirection, newRobot.Direction); Assert.AreEqual(expectedIsLost, newRobot.IsLost); }
public void ExecuteCommands(RobotCommandSet commandSet) { CheckIfLost(); foreach (var command in commandSet.Commands) { try { command.Execute(this, _marsSurface); } catch (RobotLostException) { IsLost = true; break; } } }
public void Robot_Not_Move_If_Scent_Exist() { SurfaceGrid _marsSurface = new SurfaceGrid(2, 2); MarsInvasionControlCenter controlCenter = new MarsInvasionControlCenter(_marsSurface); //First robot is being lost var position = new SurfacePosition(1, 1); var newRobot = controlCenter.AddNewRobot(position, SurfaceDirection.Up); var commandSet = RobotCommandSet.Create(_commandsFactory, "F"); newRobot.ExecuteCommands(commandSet); Assert.IsTrue(newRobot.IsLost); //Second robot is not lost newRobot = controlCenter.AddNewRobot(position, SurfaceDirection.Up); newRobot.ExecuteCommands(commandSet); Assert.IsFalse(newRobot.IsLost); Assert.AreEqual(1, newRobot.Position.Row); Assert.AreEqual(1, newRobot.Position.Column); }
public void Create_Too_Long_Command_Throws(string commandsString) { Assert.Throws <ArgumentOutOfRangeException>(() => RobotCommandSet.Create(_commandsFactory, commandsString)); }
public void Create_Should_Success(string commandsString, int expectedLength) { RobotCommandSet commandSet = RobotCommandSet.Create(_commandsFactory, commandsString); Assert.AreEqual(expectedLength, commandSet.Commands.Count); }