Exemple #1
0
        /// <summary>
        /// Парсит строку с данными в робота.
        /// </summary>
        /// <param name="line">Строка с необходимыми данными.</param>
        /// <returns>Робота <see cref="SimpleMartianRobot"/>.</returns>
        public SimpleMartianRobot ParseRobotData(string line)
        {
            line = Guard.ArgumentIsNotNullOrWhiteSpace(line, nameof(line));

            var inputs = line
                         .ToUpperInvariant()
                         .Where(char.IsLetterOrDigit)
                         .Select(_ => _.ToString())
                         .ToArray();

            var xPos = Convert.ToInt32(inputs[0]);
            var yPos = Convert.ToInt32(inputs[1]);

            Orientation robotOrientation;

            switch (inputs[2])
            {
            case "N":
            {
                robotOrientation = Orientation.North;

                break;
            }

            case "E":
            {
                robotOrientation = Orientation.East;

                break;
            }

            case "S":
            {
                robotOrientation = Orientation.South;

                break;
            }

            case "W":
            {
                robotOrientation = Orientation.West;

                break;
            }

            default:
            {
                throw new ArgumentException("Invalid orientation. Cannot parse.");
            }
            }

            var position = new Position(xPos, yPos);

            var newRobot = new SimpleMartianRobot("Test robot", position, robotOrientation);

            return(newRobot);
        }
Exemple #2
0
        public void RobotNotLostAfterPreviousLostSamePoint()
        {
            // Arrange
            var robot = new SimpleMartianRobot(_coordinate, new _2DDirection(90), _grid);

            // Act
            _robot.Move(1);
            robot.Move(5);

            // Assert
            Assert.IsFalse(robot.isLost);
        }
        public void IsRobotNotAddedOnPoint()
        {
            // Arrange
            var coordinate = new _2DCoordinate(5, 1);
            var robot      = new SimpleMartianRobot(coordinate, new _2DDirection(0), _grid);

            // Act
            _grid.AddRobotOnPoint(robot);
            var robotSet = _grid.AcquireRobot(coordinate);

            // Assert
            Assert.IsNull(robotSet);
        }
        public void IsRobotRemovedPoint()
        {
            // Arrange
            var coordinate = new _2DCoordinate(3, 5);
            var robot      = new SimpleMartianRobot(coordinate, new _2DDirection(0), _grid);

            // Act
            _grid.AddRobotOnPoint(robot);
            var robotSet = _grid.AcquireRobot(coordinate);

            _grid.RemoveRobotFromPoint(robot);
            var robotDel = _grid.AcquireRobot(coordinate);

            // Assert
            Assert.AreNotEqual(robotDel, robotSet);
        }
Exemple #5
0
        public void Should_ParseData_Correctly()
        {
            // Arrange.
            const string robotDataString = "1 3 W";

            var position    = new Position(1, 3);
            var orientation = Orientation.West;

            var expectedResult = new SimpleMartianRobot("TestRobot", position, orientation);

            var target = new RobotDataParser();

            // Act.
            var actualResult = target.ParseRobotData(robotDataString);

            // Assert.
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult.CurrentPosition, actualResult.CurrentPosition);
            Assert.AreEqual(expectedResult.Orientation, actualResult.Orientation);
        }
Exemple #6
0
 public void Setup()
 {
     _coordinate = new _2DCoordinate(4, 1);
     _grid       = new RectangularGrid(4, 7);
     _robot      = new SimpleMartianRobot(_coordinate, new _2DDirection(90), _grid);
 }