public RoverPosition Parse(string source)
        {
            var tokens = source.Split(' ');

            if (tokens.Length != 3)
            {
                throw new ParserException($"Could not parse {source} into a Rover, expected 3 tokens got {tokens.Length}");
            }

            int x;
            if (!int.TryParse(tokens[0], out x))
            {
                throw new ParserException($"Could not parse {source} into a Rover, first token isn't an integer");
            }

            int y;
            if (!int.TryParse(tokens[1], out y))
            {
                throw new ParserException($"Could not parse {source} into a Rover, second token isn't an integer");
            }

            var coordinate = new Coordinate(x, y);
            IDirectionState direction = ReadDirectionToken(tokens[2]);
            return new RoverPosition(coordinate, direction);
        }
示例#2
0
        public Terrain(Coordinate coordinate)
        {
            if (coordinate.X < 1 || coordinate.Y < 1)
            {
                throw new TerrainInvalidInitializationValueException(Messages.TerrainInvalidInitializationValueExceptionMessage);
            }

            _upperBoundary = coordinate;
        }
示例#3
0
        public Coordinate Move(Coordinate position, Terrain terrain)
        {
            if (position.Y == terrain.UpperBoundary.Y)
            {
                throw new RoverInvalidPositionException(Messages.RoverInvalidUpperBoundaryYExceptionMessage);
            }

            position.Y++;

            return position;
        }
示例#4
0
        public Coordinate Move(Coordinate position, Terrain terrain)
        {
            if (position.X == terrain.LowerBoundary.X)
            {
                throw new RoverInvalidPositionException(Messages.RoverInvalidLowerBoundaryXExceptionMessage);
            }

            position.X--;

            return position;
        }
示例#5
0
        public void CannotMoveForwardWhenObstructed()
        {
            var currentLocation = new Coordinate(5, 4);
            var nextSpace = grid.GetNextSpaceInFront(currentLocation, Direction.North);

            Assert.AreEqual(currentLocation, nextSpace);
        }
示例#6
0
        public void CannotMoveBackwardWhenObstructed()
        {
            var currentLocation = new Coordinate(5, 6);
            var nextSpace = grid.GetNextSpaceBehind(currentLocation, Direction.North);

            Assert.AreEqual(currentLocation, nextSpace);
        }