public void GivenRotateRightCommand_WhenExecute_ThenRoverTurnedRight()
        {
            IControlCommand command = new RotateRightCommand();

            var rover = new Rover(plateau, "1 2 N");

            command.Execute(rover);

            Assert.Equal(1, rover.CurrentPosition.X);
            Assert.Equal(2, rover.CurrentPosition.Y);
            Assert.Equal("E", rover.CurrentPosition.Direction);
        }
Example #2
0
    /// <summary>
    /// Sets and Populates all the Commands with their Methods and KeyCode.
    /// </summary>
    private void SetAndPopulateInput()
    {
        inputManager = new InputManager();
        ShootCommand       shootCommand       = new ShootCommand();
        ThrustCommand      thrustCommand      = new ThrustCommand();
        RotateLeftCommand  rotateLeftCommand  = new RotateLeftCommand();
        RotateRightCommand rotateRightCommand = new RotateRightCommand();

        inputManager.BindInputToCommandWithOrigin(KeyCode.Space, shootCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.W, thrustCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.A, rotateLeftCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.D, rotateRightCommand, Player.PlayerGO);
    }
        public void Rover_FacingNorth_AtPosition34_5x5Grid_TurnsEast()
        {
            Coordinates startPosition    = new Coordinates(3, 4);
            IDirection  currentDirection = new North();
            Grid        grid             = new Grid(new Coordinates(0, 0), new Coordinates(5, 5));
            IRover      rover            = new MarsRover(currentDirection, startPosition, grid);
            ICommand    moveCommand      = new RotateRightCommand();

            moveCommand.Execute(rover);
            Assert.That(rover.CurrentDirection, Is.TypeOf <East>());
            Assert.That(rover.CurrentPosition.XCoordinate == 3);
            Assert.That(rover.CurrentPosition.YCoordinate == 4);
        }
Example #4
0
        public void Execute_RobotGiven_ShouldCallRobotRotateRightMethod()
        {
            // Arrange
            var robotMock = new Mock <IRobot>();

            var rotateRightCommand = new RotateRightCommand();

            // Act
            rotateRightCommand.Execute(robotMock.Object);

            // Assert
            robotMock.Verify(robot => robot.RotateRight(), Times.Once());
        }
        public void RotateRightCommand_Should_Call_Create_Method_When_Expected_Value(Direction direction)
        {
            //Arrange
            var marsRoverService         = new Mock <IMarsRoverService>();
            var directionManagerStrategy = new Mock <IDirectionManagerStrategy>();

            marsRoverService.Setup(s => s.GetCurrentRover()).Returns(new RoverPositionModel(1, 1, direction));

            var moveForwardCommand = new RotateRightCommand(marsRoverService.Object, directionManagerStrategy.Object);

            //Act
            moveForwardCommand.Execute();

            //Assert
            directionManagerStrategy.Verify(mock => mock.RotateRight(direction), Times.Once);
        }
        public IExplorationCommand ExecuteInstruction(Instruction instruction)
        {
            IExplorationCommand explorationCommand = null;

            switch (instruction)
            {
            case Instruction.Right:
                explorationCommand = new RotateRightCommand();
                break;

            case Instruction.Left:
                explorationCommand = new RotateLeftCommand();
                break;

            case Instruction.Forward:
                explorationCommand = new MoveForwardCommand();
                break;
            }

            return(explorationCommand);
        }
        public void RotateToNextOrientationOnLCommand(Orientation testOrientation, Orientation expectedOrientation)
        {
            const int dummyX             = 1;
            const int dummyY             = 1;
            var       testPosition       = new Position(dummyX, dummyY, testOrientation);
            const int testGridSizeX      = 3;
            const int testGridSizeY      = 3;
            var       testTrackingModule = new TrackingModule
            {
                GridMaximumX = testGridSizeX,
                GridMaximumY = testGridSizeY,
                Position     = testPosition
            };

            var spyCommand    = new SpyCommand();
            var rotateCommand = new RotateRightCommand(spyCommand);

            rotateCommand.Execute(testTrackingModule);

            var actualTrackingModule = spyCommand.TrackingModule;

            actualTrackingModule.Position.Orientation.Should().Be(expectedOrientation);
        }
Example #8
0
        public static ICommand CreateCommand(char _command)
        {
            ICommand command = null;

            switch (_command)
            {
            case 'R':
                command = new RotateRightCommand();
                break;

            case 'L':
                command = new RotateLeftCommand();
                break;

            case 'M':
                command = new MoveCommand();
                break;

            default: break;
            }

            return(command);
        }
Example #9
0
 public void setRotateRightCommand(RotateRightCommand rotateRightCommand)
 {
     this.rotateRightCommand = rotateRightCommand;
 }