public Robot(RobotInstructions instructions) { _instructions = instructions; _position = new Position(_instructions._position.X, _instructions._position.Y); _cleanedPlaces = new SortedSet <Position>(); _cleanedPlaces.Add(_instructions._position); }
public void Move_Move_Rotate_Left_Move_Robot_After_Placing_On_Table_Report() { var robotInstructions = new RobotInstructions(); var placeResult = robotInstructions.Place(1, 2, FacingDirection.East); Assert.AreEqual(placeResult, true); var moveResult1 = robotInstructions.Move(); Assert.AreEqual(moveResult1, true); var moveResult2 = robotInstructions.Move(); Assert.AreEqual(moveResult2, true); var rotateResult = robotInstructions.Left(); Assert.AreEqual(rotateResult, true); var moveResult3 = robotInstructions.Move(); Assert.AreEqual(moveResult3, true); var reportResult = robotInstructions.Report(); Assert.AreEqual("3,3,NORTH", reportResult); }
public void Setup() { Robot robot1 = new Robot() { RobotId = 1, CurrentPosition = "1 2 N", Instruction = "<^<^<^<^^" }; Robot robot2 = new Robot() { RobotId = 2, CurrentPosition = "3 3 E", Instruction = "^^>^^>^>>^" }; var robots = new List <Robot>(); robots.Add(robot1); robots.Add(robot2); instructions = new Models.RobotInstructions() { UpperRightCoordination = " 5 5 ", Robots = robots }; service = new RobotInstructionsService(instructions); }
public void Report_Before_Placing_On_Table() { var robotInstructions = new RobotInstructions(); var reportResult = robotInstructions.Report(); Assert.AreEqual("Can not generate the report!! Robot is not placed on the table.", reportResult); }
public void Robot_NumberOfInstructions_Greater_Than_10000() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("15000"); robotInstructions.GetInputInstructions("10 2"); Assert.AreEqual(10000, robotInstructions._numbersOfInstructions); }
public void Robot_NumberOfInstructions_Less_Than_Zero() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("-1"); robotInstructions.GetInputInstructions("10 2"); Assert.AreEqual(0, robotInstructions._numbersOfInstructions); }
public Robot(OrientatedCoordinates position, RobotInstructions instruction) { InitalPosition = position; CurrentPosition = new OrientatedCoordinates() { Orientation = InitalPosition.Orientation, X = InitalPosition.X, Y = InitalPosition.Y }; Instructions = instruction; }
public void Move_Robot_Before_Placing_On_Table() { var robotInstructions = new RobotInstructions(); var moveResult = robotInstructions.Move(); Assert.AreEqual(moveResult, false); Assert.AreEqual("Robot can not move!! Robot is not placed on the table.", robotInstructions._error); }
public void Robot_With_Incomplete_Input() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("10"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 0"); Assert.IsFalse(robotInstructions.InputsAreComplete); }
public void Robot_InputPosition() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("1"); robotInstructions.GetInputInstructions("10 2"); Assert.AreEqual(10, robotInstructions._position.X); Assert.AreEqual(2, robotInstructions._position.Y); }
public void Robot_One_Movement_Instruction() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("1"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 2"); Assert.AreEqual(1, robotInstructions._movementInstruction.Count); }
public void CreateRobot() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("0"); commands.GetInputInstructions("0 0"); Robot robot = new Robot(commands); Assert.IsNotNull(robot); }
public void Robot_With_Complete_Input() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("3"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 1"); robotInstructions.GetInputInstructions("E 1"); robotInstructions.GetInputInstructions("E 1"); Assert.IsTrue(robotInstructions.InputsAreComplete); }
public void Robot_Movement_With_Zero_Step() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("1"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 1"); MovementInstruction moveCommand = robotInstructions._movementInstruction[0]; Assert.AreEqual(1, moveCommand.StepstoMove); }
public void Robot_Movement_With_Morethan99999_Steps() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("1"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 1500000"); MovementInstruction moveCommand = robotInstructions._movementInstruction[0]; Assert.AreEqual(99999, moveCommand.StepstoMove); }
public void MoveRobot_With_OutOfRangeCoordinates() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("1"); commands.GetInputInstructions("-100000 200000"); commands.GetInputInstructions("E 1"); Robot robot = new Robot(commands); robot.FollowInstructions(); Assert.IsTrue(robot._position.ValidateInPlan(robot._position)); }
public void Robot_WithZeroCommand() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("0"); commands.GetInputInstructions("6 8"); Robot robot = new Robot(commands); robot.FollowInstructions(); Assert.AreEqual(commands._position.X, robot._position.X); Assert.AreEqual(commands._position.Y, robot._position.Y); }
public void Move_Robot_After_Placing_On_Table() { var robotInstructions = new RobotInstructions(); var placeResult = robotInstructions.Place(0, 0, FacingDirection.North); Assert.AreEqual(placeResult, true); var moveResult = robotInstructions.Move(); Assert.AreEqual(moveResult, true); }
public void Move_Robot_After_Placing_On_Table_But_Out_Of_Table_Boundary() { var robotInstructions = new RobotInstructions(); var placeResult = robotInstructions.Place(0, 0, FacingDirection.South); Assert.AreEqual(placeResult, true); var moveResult = robotInstructions.Move(); Assert.AreEqual("Can not Move the Robot out of the table boundary.", robotInstructions._error); }
public void Report_After_Placing_On_Table() { var robotInstructions = new RobotInstructions(); var placeResult = robotInstructions.Place(0, 0, FacingDirection.North); Assert.AreEqual(placeResult, true); var reportResult = robotInstructions.Report(); Assert.AreEqual("0,0,NORTH", reportResult); }
public void Place_Robot_InsideTableBoundary() { var robotInstructions = new RobotInstructions(); var result = robotInstructions.Place(0, 0, FacingDirection.North); Assert.AreEqual(result, true); var result2 = robotInstructions.Place(5, 5, FacingDirection.North); Assert.AreEqual(result2, true); }
public void Robot_Will_Not_Move_More_Than_999999_Steps() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("1"); commands.GetInputInstructions("0 0"); commands.GetInputInstructions("N 100000"); Robot robot = new Robot(commands); robot.FollowInstructions(); //Robot will move towards North, i.e Y++ Assert.AreEqual(99999, robot._position.Y); }
public void Robot_WithOnePlaceCleaned() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("0"); commands.GetInputInstructions("6 8"); Robot robot = new Robot(commands); robot.FollowInstructions(); string output = robot.PrintCleanedPlaces(); Assert.AreEqual("=> Cleaned: 1", output); }
public void MoveRobot_WithOneCommand() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("1"); commands.GetInputInstructions("6 8"); commands.GetInputInstructions("E 1"); Robot robot = new Robot(commands); robot.FollowInstructions(); Assert.AreEqual(commands._position.X + 1, robot._position.X); Assert.AreEqual(commands._position.Y, robot._position.Y); }
public void Robot_Will_Never_Go_OutSide_Of_GridRange() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("1"); commands.GetInputInstructions("-100000 100000"); commands.GetInputInstructions("W 1"); Robot robot = new Robot(commands); robot.FollowInstructions(); Assert.AreEqual(commands._position.X, robot._position.X); Assert.AreEqual(commands._position.Y, robot._position.Y); }
public void Robot_With_Five_Complete_Commands() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("5"); robotInstructions.GetInputInstructions("10 2"); robotInstructions.GetInputInstructions("E 3"); robotInstructions.GetInputInstructions("E 3"); robotInstructions.GetInputInstructions("E 3"); robotInstructions.GetInputInstructions("E 3"); robotInstructions.GetInputInstructions("E 3"); Assert.AreEqual(5, robotInstructions._numbersOfInstructions); }
public void Get_Ten_Thousand_InputCommands() { RobotInstructions robotInstructions = new RobotInstructions(); robotInstructions.GetInputInstructions("10000"); robotInstructions.GetInputInstructions("10 2"); for (int i = 0; i < 10000; i++) { robotInstructions.GetInputInstructions("N 2"); } Assert.IsTrue(robotInstructions.InputsAreComplete); }
public void Rotate_Robot_Before_Placing_On_Table() { var robotInstructions = new RobotInstructions(); var moveResult = robotInstructions.Left(); Assert.AreEqual(moveResult, false); Assert.AreEqual("Robot can not rotate Left!! Robot is not placed on the table.", RobotStatus._error); var moveResult2 = robotInstructions.Right(); Assert.AreEqual(moveResult2, false); Assert.AreEqual("Robot can not rotate Right!! Robot is not placed on the table.", RobotStatus._error); }
public void MoveRobot_InSideTheBounds() { RobotInstructions commands = new RobotInstructions(); commands.GetInputInstructions("1"); commands.GetInputInstructions("-6 8"); commands.GetInputInstructions("W 1"); Robot robot = new Robot(commands); robot.FollowInstructions(); //Robot will move one position towards West Assert.AreEqual(commands._position.X - 1, robot._position.X); Assert.AreEqual(commands._position.Y, robot._position.Y); }
public void Place_Robot_OutsideTableBoundary() { var robotInstructions = new RobotInstructions(); var result = robotInstructions.Place(0, -1, FacingDirection.North); Assert.AreEqual(result, false); Assert.AreEqual("Can not Place the Robot out of the table boundary.", RobotStatus._error); var result2 = robotInstructions.Place(6, 0, FacingDirection.North); Assert.AreEqual(result2, false); Assert.AreEqual("Can not Place the Robot out of the table boundary.", RobotStatus._error); }