Пример #1
0
        public void Rover_GIVENInputs_WHENTurnLeft_THENItBecomesSuccessfully()
        {
            _plateau.SetSize(new Coordinate(5, 5));
            _location.SetLocation(new Coordinate(2, 3));
            _rover.TurnDirection(DirectionType.South);
            _rover.GiveCommand("L");

            _rover.GetCurrentPosition().ShouldBe("2 3 East");
        }
Пример #2
0
        public void MoveTo_PassValidLocation_ShouldBeSuccess(DirectionType directionType)
        {
            var coordinate = new Coordinate(3, 1);

            _rover.SetCoordinate(coordinate);
            _rover.SetDirection(directionType);

            _rover.MoveForward(directionType);

            var result = _rover.GetCurrentPosition();

            result.Should().NotBeNullOrEmpty();
            result.Should().Be($"{_rover.GetCoordinate().X } {_rover.GetCoordinate().Y} {directionType}");
        }
Пример #3
0
        public void Throw_Exception_Validate_To_Position_When_Position_Is_Wrong()
        {
            IRover rover = Substitute.For <IRover>();

            rover.GetCurrentPosition().Returns(new Position(3, 3, Orientation.North));
            Plateau plateau = new Plateau(1, 1);

            Assert.Throws <OutOfPlateauException>(() => plateau.ValidateToPosition(rover));
        }
Пример #4
0
        public void Does_Not_Throw_Validate_To_Position_When_Position_Is_Correct()
        {
            IRover rover = Substitute.For <IRover>();

            rover.GetCurrentPosition().Returns(new Position(0, 0, Orientation.North));
            Plateau plateau = new Plateau(1, 1);

            plateau.ValidateToPosition(rover);
        }
Пример #5
0
        public void ValidateToPosition(IRover rover)
        {
            Position position = rover.GetCurrentPosition();

            if (position.CoordinateX > Width)
            {
                throw new OutOfPlateauException(string.Format("Your X coordinate is {0} but the plateau max X coordinate is {1}", position.CoordinateX, Width));
            }

            if (position.CoordinateY > Height)
            {
                throw new OutOfPlateauException(string.Format("Your Y coordinate is {0} but the plateau max Y coordinate is {1}", position.CoordinateY, Height));
            }
        }
        public void GivenFacingSouth_AndOnTheTopRight_WhenMovesBackward_ShouldMoveToBottomRight()
        {
            //Arrange
            _sut = new Rover(_planet, 10, 10, Direction.S);
            var expcPositionString = "10, -10, S";

            //Act
            var isSuccessfulMove = _sut.ProcessCommands("B");
            var currentPosition  = _sut.GetCurrentPosition();

            //Assert
            isSuccessfulMove.Should().BeTrue("Wrapping On TopRight boundary failed");
            expcPositionString.ToString().Should().Be(currentPosition);
        }
        public void GivenFacingWest_AndOnTheTopLeft_WhenMovesForward_ShouldMoveToTopRight()
        {
            //Arrange
            _sut = new Rover(_planet, -10, 10, Direction.W);
            var expcPositionString = "10, 10, W";

            //Act
            var isSuccessfulMove = _sut.ProcessCommands("F");
            var currentPosition  = _sut.GetCurrentPosition();

            //Assert
            isSuccessfulMove.Should().BeTrue("Wrapping On TopLeft boundary failed");
            expcPositionString.ToString().Should().Be(currentPosition);
        }
Пример #8
0
        public void GivenInitialPosition_WhenProbed_ShouldReturnCurrentPosition()
        {
            //Arrange
            _sut = new Rover(_planet, 0, 0, Direction.N);

            var expcPositionString = "0, 0, N";

            //Act
            var currentPosition = _sut.GetCurrentPosition();

            //Assert

            expcPositionString.ToString().Should().Be(currentPosition);
        }
Пример #9
0
        public void GivenBackCommand_WhenRoverMoves_ShouldMoveDownwardsVertically()
        {
            //Arrange
            _sut = new Rover(_planet, 2, 3, Direction.N);

            var expcPositionString = "2, 2, N";

            //Act
            var isSuccess       = _sut.ProcessCommands("B");
            var currentPosition = _sut.GetCurrentPosition();

            //Assert
            isSuccess.Should().BeTrue("Vertial Downwards operation failed");
            expcPositionString.ToString().Should().Be(currentPosition, "Rover is not at expected position");
        }
Пример #10
0
        public void GivenBackwardCommand_WhenRoverMoves_ShouldMoveBackHorizontally()
        {
            //Arrange
            _sut = new Rover(_planet, 2, 3, Direction.E);

            var expcPositionString = "1, 3, E";

            //Act
            var isSuccess       = _sut.ProcessCommands("B");
            var currentPosition = _sut.GetCurrentPosition();

            //Assert
            isSuccess.Should().BeTrue("Horizontal Backward operation failed");
            expcPositionString.ToString().Should().Be(currentPosition, "Rover is not at expected position");
        }
Пример #11
0
        public void GivenSeriesOfCommands_WhenRoverMoves_ShouldMoveToExpectionPosition()
        {
            //Arrange
            _sut = new Rover(_planet, 0, 0, Direction.N);

            var expcPositionString = "2, 2, E";

            //Act
            var isSuccess       = _sut.ProcessCommands("FFRFF");
            var currentPosition = _sut.GetCurrentPosition();

            //Assert
            isSuccess.Should().BeTrue("Rover Move operation failed");
            expcPositionString.ToString().Should().Be(currentPosition, "Rover is not at expected position");
        }
Пример #12
0
        public void GivenObstacleIsPresentImmediately_WhenMovesForward_ShouldNotChangeInPosition()
        {
            //Arrange
            _obstacles = new List <Point>
            {
                new Point(1, 0)
            };
            _planet.SetObstacles(_obstacles);

            _sut = new Rover(_planet, 0, 0, Direction.E);

            var expcPositionString = "0, 0, E";

            //Act
            var isSuccessfulMove = _sut.ProcessCommands("F");
            var currentPosition  = _sut.GetCurrentPosition();

            //Assert
            isSuccessfulMove.Should().BeFalse("Rover moved past obstacle");
            expcPositionString.ToString().Should().Be(currentPosition);
        }
Пример #13
0
        public void GivenCommandsToMove_WhenObstacleIsEncounteredInTheMiddle_ShouldReturnLastSuccessfulPoint()
        {
            //Arrange
            _obstacles = new List <Point>
            {
                new Point(80, 80)
            };
            _planet = new Pluto(100, 0, 100, 0);
            _planet.SetObstacles(_obstacles);

            _sut = new Rover(_planet, 70, 70, Direction.N);

            var expcPositionString = "79, 80, E";

            //Act
            var isSuccessfulMove = _sut.ProcessCommands("FFFFFFFFFFRFFFFFFFFFF");
            var currentPosition  = _sut.GetCurrentPosition();

            //Assert
            isSuccessfulMove.Should().BeFalse("Rover moved past obstacle");
            expcPositionString.ToString().Should().Be(currentPosition);
        }