Esempio n. 1
0
        public void ReportTest()
        {
            Robot                  robot            = new Robot();
            TableTop               table            = new TableTop(5, 6);
            IRobotMovingService    movingService    = new ToyRobotMovingService();
            IRobotReportingService reportingService = new ToyRobotReportingService();
            IRobotTurningService   turningService   = new ToyRobotTurningService();

            RobotSimulator simulator = new RobotSimulator(robot, table, movingService, turningService, reportingService);


            string result = simulator.Report();

            Assert.IsNull(result);
            Assert.IsNull(robot.Position);


            simulator.Place(new Position(3, 3), Facing.EAST);

            result = simulator.Report();
            Assert.AreEqual("Output: 3,3,EAST", result);
        }
        public void Run(Command command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(Command));
            }

            if (command is Command_Left)
            {
                _simulator.TurnLeft();
            }
            else if (command is Command_Right)
            {
                _simulator.TurnRight();
            }
            else if (command is Command_Move)
            {
                _simulator.Move();
            }
            else if (command is Command_Place)
            {
                Command_Place cp = (Command_Place)command;
                _simulator.Place(cp.Position, cp.Facing);
            }
            else if (command is Command_Report)
            {
                string message = _simulator.Report();
                if (message != null)
                {
                    System.Console.WriteLine(message);
                }
            }
            else
            {
                return;
            }
        }
Esempio n. 3
0
 public void RotateLeft()
 {
     Assert.IsTrue(oRobotSimulator.Place("0,0,NORTH"));
     Assert.IsTrue(oRobotSimulator.Left());
     Assert.AreEqual(oRobotSimulator.Report(), "0,0,WEST");
 }