Exemplo n.º 1
0
        public void Report_NewRobotAt1X1YNorth_Returns1X1YNorth()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);

            var robotId = Guid.NewGuid();

            _coordinator.Place(robotId, 1, 1, Direction.North);

            try
            {
                var report = _coordinator.Report();

                Assert.AreEqual(1, report.Count);

                var firstRobot = report.First();

                Assert.AreEqual(robotId, firstRobot.robotId);
                Assert.AreEqual(1, firstRobot.x);
                Assert.AreEqual(1, firstRobot.y);
                Assert.AreEqual(Direction.North, firstRobot.direction);
            }
            catch (Exception)
            {
                Assert.Fail("Exception Thrown");
            }
        }
Exemplo n.º 2
0
        public void Report_RobotExistsInListNotOnBoard_ExceptionThrown()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);

            _coordinator.Robots.Add(new Toy.Robot.Robot.Robot(Direction.North));

            var ex = Assert.Throws <Exception>(() =>
            {
                _coordinator.Report();
            });

            Assert.AreEqual("Cannot find robot on the board, place same robot on the board again", ex.Message);
        }
Exemplo n.º 3
0
        public void Report_MultipleRobots_NoExceptionsResultsValid()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);
            _coordinator.NumberOfRobotsAllowed = 4;

            var expectedResults = new List <(Guid robotId, int x, int y, Direction direction)>
            {
                (Guid.NewGuid(), 0, 0, Direction.North),
                (Guid.NewGuid(), 0, 4, Direction.East),
                (Guid.NewGuid(), 4, 0, Direction.West),
                (Guid.NewGuid(), 4, 4, Direction.South)
            };

            _coordinator.Place(expectedResults[0].robotId, expectedResults[0].x, expectedResults[0].y, expectedResults[0].direction);
            _coordinator.Place(expectedResults[1].robotId, expectedResults[1].x, expectedResults[1].y, expectedResults[1].direction);
            _coordinator.Place(expectedResults[2].robotId, expectedResults[2].x, expectedResults[2].y, expectedResults[2].direction);
            _coordinator.Place(expectedResults[3].robotId, expectedResults[3].x, expectedResults[3].y, expectedResults[3].direction);

            try
            {
                var reportList = _coordinator.Report();

                Assert.AreEqual(4, reportList.Count);

                foreach (var expectedResult in expectedResults)
                {
                    var report = reportList.FirstOrDefault(r => r.robotId == expectedResult.robotId);
                    if (report == default)
                    {
                        Assert.Fail($"Robot {expectedResult.robotId} not included in report");
                    }

                    Assert.AreEqual(expectedResult, report);
                }
            }
            catch (Exception)
            {
                Assert.Fail("Exception Thrown");
            }
        }
Exemplo n.º 4
0
        public (bool isRobotPlaced, string report) ProcessCommand(string[] input)
        {
            var command = input[0].ToLower();

            switch (command)
            {
            case "place":
                if (input.Length == 1)
                {
                    throw new Exception(
                              "Please provide X, Y location and Facing direction for robot to be placed on board");
                }
                var args = CalculatePlaceArguments(input[1]);
                if (_currentRobot == Guid.Empty)
                {
                    _currentRobot = _coordinator.Place(args.x, args.y, args.direction);
                }
                else
                {
                    _coordinator.Place(_currentRobot, args.x, args.y, args.direction);
                }
                break;

            case "left":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Left(_currentRobot);
                break;

            case "right":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Right(_currentRobot);
                break;

            case "move":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                _coordinator.Move(_currentRobot);
                break;

            case "report":
                if (_currentRobot == Guid.Empty)
                {
                    throw new Exception("Please PLACE robot on board");
                }
                var report       = _coordinator.Report().First();
                var reportString = $"Output: {report.x},{report.y},{report.direction}";
                return(_currentRobot != Guid.Empty, reportString);

            default:
                throw new Exception("Command not recognized please try again");
            }

            return(_currentRobot != Guid.Empty, string.Empty);
        }