public void ProcessScenarioTest1() { // Arrange const int xRobotPos = 1; const int yRobotPos = 2; const int xTableSize = 5; const int yTableSize = 5; const Direction direction = Direction.South; Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, xTableSize, yTableSize); Process process = new Process(robot, table); // Act process.RunPlaceCommand("PLACE", $"{xRobotPos},{yRobotPos},{direction}"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("RIGHT"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("MOVE"); process.RunSingleCommand("MOVE"); process.RunSingleCommand("REPORT"); // Assert StringAssert.AreEqualIgnoringCase("The robot is at position: 1, 0 and facing South", robot.Report()); }
private static void RunCommands(Robot robot, SquareTableTop table, Process process, string readLine) { if (readLine == null) { return; } string[] commandSplit = readLine.Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (commandSplit.Any()) { string commandToExecute = commandSplit[0]; if (CommandHasOneArgument(commandSplit)) { process.RunSingleCommand(commandToExecute); } else if (CommandHasTwoArguments(commandSplit)) { string input = commandSplit[1]; process.RunPlaceCommand(commandToExecute, input); } else { Console.WriteLine("Command is not valid"); } } }
public void ProcessScenarioTest3() { // Arrange const int xRobotPos1 = 1; const int yRobotPos1 = 1; const int xRobotPos2 = 2; const int yRobotPos2 = 3; const int xRobotPos3 = 4; const int yRobotPos3 = 4; const int xTableSize = 5; const int yTableSize = 5; const Direction direction1 = Direction.South; const Direction direction2 = Direction.North; const Direction direction3 = Direction.East; Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, xTableSize, yTableSize); Process process = new Process(robot, table); // Act process.RunPlaceCommand("PLACE", $"{xRobotPos1},{yRobotPos1},{direction1}"); process.RunPlaceCommand("PLACE", $"{xRobotPos2},{yRobotPos2},{direction2}"); process.RunSingleCommand("LEFT"); process.RunSingleCommand("MOVE"); process.RunSingleCommand("MOVE"); process.RunPlaceCommand("PLACE", $"{xRobotPos3},{yRobotPos3},{direction3}"); process.RunSingleCommand("REPORT"); // Assert StringAssert.AreEqualIgnoringCase("The robot is at position: 4, 4 and facing East", robot.Report()); }
private static void ProcessFile(Robot robot, SquareTableTop table, Process process, string file) { string[] lines = File.ReadAllLines(@file); foreach (string line in lines) { RunCommands(robot, table, process, line); } }
public void ToyRobotShouldNotBeAbleToBePlacedPastTheEdgeOfTheTableTop() { // Arrange const int xRobotPos = 6; const int yRobotPos = 6; const int xTableSize = 5; const int yTableSize = 5; Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, xTableSize, yTableSize); const Command command = Command.Place; // Assert Assert.Throws <ArgumentOutOfRangeException>(() => table.ValidatePlacedRobotWillNotFall(command, xRobotPos, yRobotPos)); }
private static void ProcessArgs(Robot robot, SquareTableTop table, Process process, string[] args) { foreach (string file in args) { if (File.Exists(@file)) { ProcessFile(robot, table, process, file); } else { Console.WriteLine("File does not exist"); } } }
public void ToyRobotWillNotFallOffTableTopIfOnEdgeOfWestSide() { // Arrange const int xRobotPos = 0; const int yRobotPos = 3; const Direction robotDirection = Direction.West; const int xTableSize = 5; const int yTableSize = 5; Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, xTableSize, yTableSize); const Command command = Command.Move; // Act robot.Place(xRobotPos, yRobotPos, robotDirection.ToString()); // Assert Assert.Throws <InvalidOperationException>(() => table.ValidateMoveRobotWillNotFall(command)); }
static void Main(string[] args) { Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, 5, 5); Process process = new Process(robot, table); PrintSimulatorInstructions(); if (args.Any()) { ProcessArgs(robot, table, process, args); } while (true) { string readLine = Console.ReadLine(); RunCommands(robot, table, process, readLine); } }
public void ProcessScenarioTestA() { // Arrange const int xRobotPos = 0; const int yRobotPos = 0; const int xTableSize = 5; const int yTableSize = 5; const Direction direction = Direction.North; Robot robot = new Robot(); SquareTableTop table = new SquareTableTop(robot, xTableSize, yTableSize); Process process = new Process(robot, table); // Act process.RunPlaceCommand("PLACE", $"{xRobotPos},{yRobotPos},{direction}"); process.RunSingleCommand("MOVE"); process.RunSingleCommand("REPORT"); // Assert Assert.That("The robot is at position: 0, 1 and facing North", Is.EqualTo(robot.Report())); }
static void Main(string[] args) { Robot robot = new Robot(); TableTop table = new SquareTableTop(5); IRobotMovingService movingService = new ToyRobotMovingService(); IRobotReportingService reportingService = new ToyRobotReportingService(); IRobotTurningService turningService = new ToyRobotTurningService(); RobotSimulator simulator = new RobotSimulator(robot, table, movingService, turningService, reportingService); RobotSimulatorCommandLineParser parser = new RobotSimulatorCommandLineParser(); RobotSimulatorCommandController controler = new RobotSimulatorCommandController(simulator); while (true) { string input = Console.ReadLine(); Command command = parser.Parsing(input); if (command != null) { controler.Run(command); } } }
public void RobotSimulatorCommandControllerTest() { Robot robot = new Robot(); TableTop table = new SquareTableTop(5); IRobotMovingService movingService = new ToyRobotMovingService(); IRobotReportingService reportingService = new ToyRobotReportingService(); IRobotTurningService turningService = new ToyRobotTurningService(); RobotSimulator simulator = new RobotSimulator(robot, table, movingService, turningService, reportingService); RobotSimulatorCommandController controler = new RobotSimulatorCommandController(simulator); controler.Run(new Command_Left()); controler.Run(new Command_Right()); controler.Run(new Command_Move()); controler.Run(new Command_Place(new Position(5, 5), Facing.EAST)); Assert.IsNull(robot.Position); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); Console.SetOut(sw); string startPoint = sb.ToString(); controler.Run(new Command_Report()); string middleAPoint = sb.ToString(); Assert.AreEqual(startPoint, middleAPoint); controler.Run(new Command_Place(new Position(3, 3), Facing.EAST)); Assert.AreEqual(3, robot.Position.X); Assert.AreEqual(3, robot.Position.Y); Assert.AreEqual(Facing.EAST, robot.Facing); controler.Run(new Command_Report()); string middleBPoint = sb.ToString(); string expectedString = "Output: 3,3,EAST" + System.Environment.NewLine; Assert.AreEqual(expectedString, middleBPoint); controler.Run(new Command_Left()); Assert.AreEqual(Facing.NORTH, robot.Facing); controler.Run(new Command_Left()); Assert.AreEqual(Facing.WEST, robot.Facing); controler.Run(new Command_Left()); Assert.AreEqual(Facing.SOUTH, robot.Facing); controler.Run(new Command_Left()); Assert.AreEqual(Facing.EAST, robot.Facing); controler.Run(new Command_Right()); Assert.AreEqual(Facing.SOUTH, robot.Facing); controler.Run(new Command_Right()); Assert.AreEqual(Facing.WEST, robot.Facing); controler.Run(new Command_Right()); Assert.AreEqual(Facing.NORTH, robot.Facing); controler.Run(new Command_Right()); Assert.AreEqual(Facing.EAST, robot.Facing); controler.Run(new Command_Move()); Assert.AreEqual(4, robot.Position.X); Assert.AreEqual(3, robot.Position.Y); controler.Run(new Command_Move()); Assert.AreEqual(4, robot.Position.X); Assert.AreEqual(3, robot.Position.Y); }