public void TestValidToyTurnRight() { // arrange var robot = new ToyRobo { Direction = Direction.West, Coordinates = new Coordinates(2, 2) }; // act robot.RotateRight(); // assert Assert.AreEqual(Direction.North, robot.Direction); }
public void TestValidToyPositionAndDirection() { // arrange var coordinates = new Coordinates(3, 3); var robot = new ToyRobo(); // act robot.Place(coordinates, Direction.North); // assert Assert.AreEqual(3, robot.Coordinates.X); Assert.AreEqual(3, robot.Coordinates.Y); Assert.AreEqual(Direction.North, robot.Direction); }
public void TestValidToyMove() { // arrange var robot = new ToyRobo { Direction = Direction.East, Coordinates = new Coordinates(2, 2) }; // act var nextPosition = robot.GetNextPosition(); // assert Assert.AreEqual(3, nextPosition.X); Assert.AreEqual(2, nextPosition.Y); }
public void TestInvalidBehaviourPlace() { // arrange IGrid grid = new Grid(5, 5); ICommandParser inputParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var simulator = new Behaviour(robot, grid, inputParser); // act simulator.ProcessInput("PLACE 9,7,EAST".Split(' ')); // assert Assert.IsNull(robot.Coordinates); }
public void TestValidBehaviourMove() { // arrange IGrid grid = new Grid(5, 5); ICommandParser inputParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var simulator = new Behaviour(robot, grid, inputParser); // act simulator.ProcessInput("PLACE 3,2,SOUTH".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); // assert Assert.AreEqual("Output: 3,1,SOUTH", simulator.GetReport()); }
public void TestValidBehaviourPlace() { // arrange IGrid grid = new Grid(5, 5); ICommandParser inputParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var simulator = new Behaviour(robot, grid, inputParser); // act simulator.ProcessInput("PLACE 1,3,EAST".Split(' ')); // assert Assert.AreEqual(1, robot.Coordinates.X); Assert.AreEqual(4, robot.Coordinates.Y); Assert.AreEqual(Direction.East, robot.Direction); }
public void TestInvalidBehaviourMove() { // arrange IGrid grid = new Grid(5, 5); ICommandParser inputParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var simulator = new Behaviour(robot, grid, inputParser); // act simulator.ProcessInput("PLACE 2,2,NORTH".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); // if the robot goes out of the board it ignores the command simulator.ProcessInput("MOVE".Split(' ')); // assert Assert.AreEqual("Output: 2,4,NORTH", simulator.GetReport()); }
public void TestValidBehaviourReport() { // arrange IGrid grid = new Grid(5, 5); ICommandParser inputParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var simulator = new Behaviour(robot, grid, inputParser); // act simulator.ProcessInput("PLACE 3,3,WEST".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); simulator.ProcessInput("LEFT".Split(' ')); simulator.ProcessInput("MOVE".Split(' ')); var output = simulator.ProcessInput("REPORT".Split(' ')); // assert Assert.AreEqual("Output: 1,2,SOUTH", output); }
public static void Main(string[] args) { var exitApp = false; const string message = @" *************************************************** *************************************************** **** Welcome to the TOY ROBO Challenge ***** *************************************************** *************************************************** *************************************************** Instructions: 1: Place the toy on a 5 x 5 grid using the following command: PLACE X,Y,F (Where X and Y are integers and F must be either NORTH, SOUTH, EAST or WEST) 2: When the toy is placed, have at go at using the following commands. REPORT – Shows the current status of the toy. LEFT – turns the toy 90 degrees left. RIGHT – turns the toy 90 degrees right. MOVE – Moves the toy 1 unit in the facing direction. EXIT – Closes the toy Simulator."; Console.WriteLine(message); IGrid grid = new Grid(5, 5); ICommandParser commandParser = new CommandParser(); IToyRobo robot = new ToyRobo(); var robo = new Behaviour.Behaviour(robot, grid, commandParser); do { var command = Console.ReadLine(); if (command == null) { continue; } if (command.Equals("EXIT")) { exitApp = true; } else { try { //Need an object which will hold the robo position and the current commands var output = robo.ProcessInput(command.Split(' ')); if (!string.IsNullOrEmpty(output)) { Console.WriteLine(output); } } catch (ArgumentException exp) { Console.WriteLine(exp.Message); } } } while (!exitApp); }