Ejemplo n.º 1
0
        public void Move_RobotDoesNotExistInList_ExceptionThrown()
        {
            _coordinator.InitializeBoard(5, 5);

            var ex = Assert.Throws <Exception>(() =>
            {
                _coordinator.Move(Guid.NewGuid());
            });

            Assert.AreEqual("Robot for specified id does not exist, place robot on the board again", ex.Message);
        }
Ejemplo n.º 2
0
        public void Move_RobotDoesNotExistOnBoard_ExceptionThrown()
        {
            var board = new Toy.Robot.Board.Board();

            board.InitializePlayArea(5, 5);

            var robotId = Guid.NewGuid();

            _coordinator = new Toy.Robot.Coordinator(board);
            _coordinator.Robots.Add(new Toy.Robot.Robot.Robot(Direction.North, robotId));

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

            Assert.AreEqual("Cannot find robot on the board, place same robot on the board again", ex.Message);
        }
Ejemplo n.º 3
0
        public void Move_RobotExistsAt1X1YNorthFacing_BoardPlaceIsFiredWith1X2Y()
        {
            var playArea = new Guid[5, 5];

            playArea.Initialize();

            var robotId = Guid.NewGuid();

            playArea[1, 1] = robotId;

            _mockBoard = new Mock <IBoard>();
            _mockBoard.Setup(m => m.Place(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <int>()));
            _mockBoard.Setup(m => m.PlayArea).Returns(playArea);

            _coordinator = new Toy.Robot.Coordinator(_mockBoard.Object);
            _coordinator.Robots.Add(new Toy.Robot.Robot.Robot(Direction.North, robotId));

            Assert.DoesNotThrow(() =>
            {
                _coordinator.Move(robotId);
            });

            _mockBoard.Verify(m => m.Place(robotId, 1, 2), Times.Once(), "Place was not called with correct parameters");
        }
Ejemplo 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);
        }