public void Obstacle_ObstacleOnRobot_ReturnsTrue() { // obstacle must not be placed on robot var board = new Board(); var robot = new ToyRobot(); robot.Execute("PLACE 2,3,NORTH", board); robot.Execute("PLACE 2,2,NORTH", board); board.Execute("OBSTACLE 2,2", robot); Assert.AreEqual(expected: board.ObstacleList.Count, actual: 0); }
public void Place_PlaceOnObstacle_ReturnsTrue() { // robot must not place on an obstacle var board = new Board(); var robot = new ToyRobot(); board.Execute("OBSTACLE 2,2", robot); robot.Execute("PLACE 2,3,NORTH", board); robot.Execute("PLACE 2,2,NORTH", board); Assert.AreEqual(expected: robot.CurrentPosition.X, actual: 2); Assert.AreEqual(expected: robot.CurrentPosition.Y, actual: 3); }
public void Move_MoveThroughObstacle_ReturnsTrue() { // robot must not move if theres an obstacle var board = new Board(); var robot = new ToyRobot(); board.Execute("OBSTACLE 2,2", robot); robot.Execute("PLACE 2,1,NORTH", board); robot.Execute("MOVE", board); Assert.AreEqual(expected: robot.CurrentPosition.X, actual: 2); Assert.AreEqual(expected: robot.CurrentPosition.Y, actual: 1); }
public void MoveRobot_MovingRightAndCheckBounds_ReturnsTrue() { var board = new Board(); var toyRobot = new ToyRobot(); // placing robot at 1,2,EAST toyRobot.Execute("PLACE 1,2,EAST", board); // moves to 2,2 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 2); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 2); // moves to 3,2 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 3); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 2); // moves to 4,2 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 4); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 2); // moves to 4,2 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 4); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 2); // moves to 4,2 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 4); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 2); }
public void MoveRobot_MovingUpAndCheckBounds_ReturnsTrue() { var board = new Board(); var toyRobot = new ToyRobot(); // placing robot at 1,2,NORTH toyRobot.Execute("PLACE 1,2,NORTH", board); // moves to 1,3 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 1); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 3); // moves to 1,4 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 1); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 4); // moves to 1,4 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 1); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 4); // moves to 1,4 toyRobot.MoveForward(board); Assert.AreEqual(expected: toyRobot.CurrentPosition.X, actual: 1); Assert.AreEqual(expected: toyRobot.CurrentPosition.Y, actual: 4); }
static void Main(string[] args) { ExceptionFactory exceptionFactory = new ExceptionFactory(); var robot = new ToyRobot(new TableSurface(), exceptionFactory); robot.ProgressChanged += OnProgressChanged; string commandLine = string.Empty; while (true) { try { Console.WriteLine("Please input a command, or input Quit to exit."); commandLine = Console.ReadLine(); if (commandLine.Trim().ToLower().Equals("quit")) { break; } robot.Execute(commandLine); } catch (SafeException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { // log this exception Console.WriteLine(ex.Message); } } Console.WriteLine("This demo is finished. Thanks for your time!"); }
public void RotateRight_AllValidBoardPositions_ReturnsTrue() { var board = new Board(); var toyRobot = new ToyRobot(); // init robot position and board toyRobot.Execute("PLACE 1,1,NORTH", board); var boardHeight = toyRobot.CurrentBoard.Height; var boardLength = toyRobot.CurrentBoard.Length; for (int x = 0; x < boardLength; x++) { for (int y = 0; y < boardHeight; y++) { toyRobot.Execute("PLACE " + x + "," + y + "," + Facing.NORTH, board); RotateRight_AtSpecificBoardPositions_ReturnsTrue(toyRobot, x, y); } } }
public void PlaceRobot_CorrectPositionWhenPlacedMultipleTimesWithinBoard_ReturnsTrue() { var board = new Board(); var toyRobot = new ToyRobot(); // init robot placement and board toyRobot.Execute("PLACE 1,2,EAST", board); var boardHeight = toyRobot.CurrentBoard.Height; var boardLength = toyRobot.CurrentBoard.Length; var dirCount = Enum.GetNames(typeof(Facing)).Length; for (int x = 0; x < boardLength; x++) { for (int y = 0; y < boardHeight; y++) { for (int z = 0; z < dirCount; z++) { PlaceRobot_CorrectPosition_ReturnsTrue(toyRobot, x, y, (Facing)z); } } } }
public void PlaceRobotInMap() { /* * Should test each of the cases where a robot can be placed in a map * 1. Test initial state * 2. Out of bounds * 3. Between (0,0) and (4,4) */ //1 Assert.Throws <ToyRobotHasNotBeenPlacedException>(() => toyRobot.GetCurrentPosition()); Assert.IsFalse(toyRobot.HasBeenPlaced()); //2 var args = "-1,0,WEST"; PlaceCommand placeCommand = new PlaceCommand(map, args); Assert.Throws <InvalidPlaceCommandException>(() => toyRobot.Execute(placeCommand)); //2.1 args = "2,5,WEST"; placeCommand = new PlaceCommand(map, args); Assert.Throws <InvalidPlaceCommandException>(() => toyRobot.Execute(placeCommand)); //3 args = "0,0,NORTH"; placeCommand = new PlaceCommand(map, args); toyRobot.Execute(placeCommand); //3.1 args = "3,4,NORTH"; placeCommand = new PlaceCommand(map, args); toyRobot.Execute(placeCommand); }