コード例 #1
0
ファイル: RoverTests.cs プロジェクト: ercanatbas/mars-rover
        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}");
        }
コード例 #2
0
        public void MoveForwardFacingNorth()
        {
            // Arrange
            _rover.SetHeading(Heading.North);

            // Act
            var x = _rover.GetPosition().X;
            var y = _rover.GetPosition().Y;

            _rover.MoveForward();

            // Assert
            Assert.IsTrue(_rover.GetPosition().X == x && _rover.GetPosition().Y == y + 1);
        }
コード例 #3
0
        public void RoverShouldMoveYForward(string landingArea, string position)
        {
            //Arrange
            _rover.Position    = _helper.ToRover(position);
            _rover.LandingArea = _helper.ToPlateau(landingArea);

            //Act
            _rover.MoveForward();

            //Assert
            Assert.IsNotNull(_rover);
            Assert.IsNotNull(_rover.Position);
            Assert.IsNotNull(_rover.LandingArea);
            Assert.AreEqual(_rover.Position.Y, 3);
        }
コード例 #4
0
        public void ProcessCommand(Command command)
        {
            switch (command)
            {
            case Command.MoveForward:
                _rover.MoveForward();
                _logger.Log("Rover moved forward.");
                _logger.Log(FormatRover());
                break;

            case Command.MoveBackward:
                _rover.MoveBackward();
                _logger.Log("Rover moved backward.");
                _logger.Log(FormatRover());
                break;

            case Command.TurnLeft:
                _rover.TurnLeft();
                _logger.Log("Rover turned left.");
                _logger.Log(FormatRover());
                break;

            case Command.TurnRight:
                _rover.TurnRight();
                _logger.Log("Rover turned right.");
                _logger.Log(FormatRover());
                break;

            case Command.Quit:
                _logger.Log("Rover stopped.");
                _logger.Log(FormatRover());
                break;
            }
        }
コード例 #5
0
        public void Move(IRover rover)
        {
            var commands = rover.Commands.ToCharArray();

            foreach (var command in commands)
            {
                switch (command)
                {
                case 'L':
                    rover.TurnLeft();
                    break;

                case 'R':
                    rover.TurnRight();
                    break;

                case 'M':
                    if (CheckBoundaries(rover))
                    {
                        rover.MoveForward();
                    }
                    break;

                default:
                    throw new CommandException();
                }
            }
        }
コード例 #6
0
        public void Rover_MoveForward()
        {
            _rover.MoveForward();

            Assert.AreEqual(1, _rover.PositionX);
            Assert.AreEqual(Directions.W, _rover.Direction);
        }
コード例 #7
0
        public void ProcessCommands(String commands)
        {
            foreach (var command in commands)
            {
                if (command == Forward)
                {
                    rover.MoveForward();
                }
                else if (command == Backward)
                {
                    rover.MoveBackward();
                }
                else if (command == Left)
                {
                    rover.TurnLeft();
                }
                else if (command == Right)
                {
                    rover.TurnRight();
                }

                if (rover.IsObstructed)
                {
                    break;
                }
            }
        }
コード例 #8
0
 public void Execute(string commands, IRover rover)
 {
     foreach (var command in commands)
     {
         if (command == 'M')
             rover.MoveForward();
         else if (command == 'L')
             rover.RotateLeft();
         else
             rover.RotateRight();
     }
 }
コード例 #9
0
 public void Execute(string commands, IRover rover)
 {
     foreach (var command in commands)
     {
         if (command == 'M')
         {
             rover.MoveForward();
         }
         else if (command == 'L')
         {
             rover.RotateLeft();
         }
         else
         {
             rover.RotateRight();
         }
     }
 }
コード例 #10
0
        public void RunStep()
        {
            var command = inputSource.ReadLine();

            switch (command)
            {
            case "L":
                rover.TurnLeft();
                break;

            case "R":
                rover.TurnRight();
                break;

            case "F":
                rover.MoveForward();
                break;

            default:
                throw new Exception("invalid command");
            }
            outputTarget.WriteLine($"Rover is now at ({rover.Position.X},{rover.Position.Y}) - facing {rover.Facing}");
        }
コード例 #11
0
        private void HandleCharacter(char ch)
        {
            switch (ch)
            {
            case 'F':
                rover.MoveForward();
                break;;

            case 'B':
                rover.MoveBackward();
                break;

            case 'R':
                rover.TurnRight();
                break;

            case 'L':
                rover.TurnLeft();
                break;

            default:
                throw new InvalidEnumArgumentException(string.Format("The received command : '%0' is not supported", ch));
            }
        }
コード例 #12
0
 public void Execute(IRover rover)
 {
     rover.MoveForward();
 }
コード例 #13
0
 public void MoveRoverForward(IRover rover)
 {
     rover.MoveForward();
 }
コード例 #14
0
ファイル: RoverTests.cs プロジェクト: bwalko1/mars-rover
 public void RoverMovesForwardCorrectly()
 {
     _defaultRover.MoveForward();
     Assert.AreEqual(new[] { 0, 1 }, _defaultRover.GetCoords());
 }
コード例 #15
0
 public ICmdResult Execute()
 {
     return(rover.MoveForward());
 }
コード例 #16
0
 public void ExecuteCommand(IRover rover)
 {
     rover.MoveForward();
 }