public void Move(Orientation testOrientation, int expectedXPosition, int expectedYPosition)
        {
            const int testX        = 2;
            const int testY        = 2;
            var       testPosition = new Position(testX, testY, testOrientation);

            const int testGridSizeX      = 3;
            const int testGridSizeY      = 3;
            var       testTrackingModule = new TrackingModule
            {
                GridMaximumX = testGridSizeX,
                GridMaximumY = testGridSizeY,
                Position     = testPosition
            };

            var spyCommand  = new SpyCommand();
            var moveCommand = new MoveForwardCommand(spyCommand);

            moveCommand.Execute(testTrackingModule);

            var actualTrackingModule = spyCommand.TrackingModule;

            actualTrackingModule.Position.Y.Should().Be(expectedYPosition);
            actualTrackingModule.Position.X.Should().Be(expectedXPosition);
        }
Esempio n. 2
0
        public void Move_TableTopFiveIntoFiveAlreadyPlacedMovedTwiceForward()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 3),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();
            moveCommand.Execute();


            //assert: actual/expected
            Assert.AreEqual(tr.GetCurrentRobotPosition(), new ToyRobot(new Coordinate(3, 5), Facing.NORTH).GetCurrentRobotPosition());
        }
Esempio n. 3
0
        public void Move_TableTop5Into5Placed3Into3RobotMovedFiveTimesForward()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 3),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();


            //assert: actual/expected
            Assert.IsTrue(tr.RobotStillOnTableTop(tt));
        }
Esempio n. 4
0
    void HandleInput()
    {
        Command command = null;

        if (Input.GetKeyDown(KeyCode.W))
        {
            command = new MoveForwardCommand();
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            command = new MoveBackwardCommand();
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            command = new MoveLeftCommand();
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            command = new MoveRightCommand();
        }
        else if (Input.GetKeyDown(KeyCode.Z))
        {
            Undo();
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            Redo();
        }

        if (command != null)
        {
            undoCommands.Push(command);
            command.Execute(Box);
        }
    }
Esempio n. 5
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            var     mf      = new MoveForwardCommand();
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());
        }
Esempio n. 6
0
        public void Robot_MoveForwardFromPosition_RobotSetToCorrespondingState(
            Facing initialFacing,
            int initial_location_X,
            int initial_location_Y,
            int initialBattery,
            Facing estimatedFacing,
            int estimaded_location_X,
            int estimaded_location_Y,
            int estimatedBattery)
        {
            // Arrange
            var position = new Position(new Location(initial_location_X, initial_location_Y), initialFacing);
            var robot    = new Robot(position, initialBattery, robotStrategies,
                                     new FacingControl(), new MovingControl(),
                                     new ElementType[x, y], new Stack <CommandType>());

            // Act
            var command = new MoveForwardCommand();

            command.ExecuteCommand(robot);

            // Assert
            Assert.AreEqual(robot.Position.Facing, estimatedFacing);
            Assert.AreEqual(robot.Battery, estimatedBattery);
            Assert.AreEqual(robot.Position.Location.X, estimaded_location_X);
            Assert.AreEqual(robot.Position.Location.Y, estimaded_location_Y);
            Assert.IsTrue(robot.VisitedCells.Contains(robot.Position.Location));
        }
Esempio n. 7
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);
            var turnCommand = new TurnClockwiseCommand(tractor);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);
        }
Esempio n. 8
0
        public async Task Navigate(string commands)
        {
            foreach (Command command in commands)
            {
                switch (command)
                {
                case Command.MoveForward:
                    var moveCommand = new MoveForwardCommand {
                        CurrentPosition = Position, Direction = Direction
                    };
                    var moveResult = await _mediator.Send(moveCommand);

                    Position = moveResult.NewPosition;
                    break;

                case Command.TurnLeft:
                    var turnLeftCommand = new TurnLeftCommand {
                        CurrentDirection = Direction
                    };
                    var turnLeftResult = await _mediator.Send(turnLeftCommand);

                    Direction = turnLeftResult.NewDirection;
                    break;

                case Command.TurnRight:
                    var turnRightCommand = new TurnRightCommand {
                        CurrentDirection = Direction
                    };
                    var turnRightResult = await _mediator.Send(turnRightCommand);

                    Direction = turnRightResult.NewDirection;
                    break;
                }
            }
        }
Esempio n. 9
0
 // Start is called before the first frame update
 void Start()
 {
     commandSpace = new JumpCommand();
     commandA     = new MoveLeftCommand();
     commandS     = new MoveBackwardCommand();
     commandD     = new MoveRightCommand();
     commandW     = new MoveForwardCommand();
 }
Esempio n. 10
0
        public void TestShouldMoveForward()
        {
            var     mf      = new MoveForwardCommand();
            Tractor tractor = new Tractor();

            mf.Execute(tractor);

            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(1, tractor.GetPositionY());
        }
Esempio n. 11
0
        public void South_boundary_reaching_throws_location_out_of_bound_exception()
        {
            var plateau = new Plateau(new Point(0, 0));
            var rover   = new Rover(plateau, new Location(new Point(0, 0), CardinalDirection.South));
            RoboticRoverCommand command = new MoveForwardCommand(rover);

            Action action = () => command.Execute();

            action.Should().ThrowExactly <LocationOutOfBoundException>();
        }
Esempio n. 12
0
        public void TestShouldStatic()
        {
            var   mf    = new MoveForwardCommand();
            Stone stone = new Stone(new int[] { 2, 4 });

            mf.Execute(stone);

            Assert.AreEqual(2, stone.GetPositionX());
            Assert.AreEqual(4, stone.GetPositionY());
        }
Esempio n. 13
0
        public void HoverCommand_ShouldExecuteClientMoveForward()
        {
            // arrange
            moveForwardCommand = new MoveForwardCommand(DroneClientMock.Object);

            // act
            moveForwardCommand.Execute();

            // assert
            DroneClientMock.Verify(x => x.MoveForward(), Times.Once);
        }
Esempio n. 14
0
        public void West_direction_rover()
        {
            var plateau = new Plateau(new Point(5, 5));
            var rover   = new Rover(plateau, new Location(new Point(1, 2), CardinalDirection.West));
            RoboticRoverCommand command = new MoveForwardCommand(rover);

            command.Execute();

            rover.Location.Point.XCoordinate.Should().Be(0);
            rover.Location.Point.YCoordinate.Should().Be(2);
        }
Esempio n. 15
0
 public void TestInitialize()
 {
     _field   = new Field(5, 5);
     _tractor = new Tractor(_field);
     _stone   = new Stone(_field);
     _wind    = new Wind(_field);
     _units   = new List <Unit> {
         _tractor, _stone, _wind
     };
     _moveCommand = new MoveForwardCommand(_units);
     _turnCommand = new TurnClockwiseCommand(_units);
 }
Esempio n. 16
0
        public void TestShouldMoveForward()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);

            moveCommand.Execute();

            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(1, tractor.UnitPosition.Y);
        }
Esempio n. 17
0
        public void Move_TableTopFiveIntoFiveRobotNotPlacedBeforeMove()
        {
            //arrange
            TableTop          tt          = new TableTop(5, 5);
            ToyRobot          tr          = new ToyRobot();
            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();

            //assert
            Assert.IsFalse(tr.isRobotPlaced);
        }
        public void Rover_FacingWest_AtPosition34_5x5Grid_MovesTo24Position()
        {
            Coordinates startPosition    = new Coordinates(3, 4);
            IDirection  currentDirection = new West();
            Grid        grid             = new Grid(new Coordinates(0, 0), new Coordinates(5, 5));
            IRover      rover            = new MarsRover(currentDirection, startPosition, grid);
            ICommand    moveCommand      = new MoveForwardCommand();

            moveCommand.Execute(rover);
            Assert.That(rover.CurrentDirection, Is.TypeOf <West>());
            Assert.That(rover.CurrentPosition.XCoordinate == 2);
            Assert.That(rover.CurrentPosition.YCoordinate == 4);
        }
Esempio n. 19
0
        public async Task MoveForward_WhenYMoveIsNotValid_ShouldNotMove()
        {
            _moveValidatorMock.Setup(v => v.IsValidYMove(It.IsAny <int>())).ReturnsAsync(false);
            var direction = It.IsAny <Direction>();
            var position  = It.IsAny <Point>();
            var command   = new MoveForwardCommand {
                CurrentPosition = position, Direction = direction
            };

            var result = await _moveCommandHandler.Handle(command, It.IsAny <CancellationToken>());

            Assert.Equal(position, result.NewPosition);
        }
Esempio n. 20
0
        public Command CreateCommand(CommandType commandType)
        {
            Command command = null;

            switch (commandType)
            {
            case CommandType.Start:
                command = new StartCommand(drone);
                break;

            case CommandType.Stop:
                command = new StopCommand(drone);
                break;

            case CommandType.Configure:
                command = new ConfigureCommand(drone);
                break;

            case CommandType.MoveBackward:
                command = new MoveBackwardCommand(drone);
                break;

            case CommandType.MoveDown:
                command = new MoveDownCommand(drone);
                break;

            case CommandType.MoveForward:
                command = new MoveForwardCommand(drone);
                break;

            case CommandType.MoveLeft:
                command = new MoveLeftCommand(drone);
                break;

            case CommandType.MoveRight:
                command = new MoveRightCommand(drone);
                break;

            case CommandType.MoveUp:
                command = new MoveUpCommand(drone);
                break;

            case CommandType.Hover:
                command = new HoverCommand(drone);
                break;

            default:
                throw new ArgumentException("Invalid command type");
            }
            return(command);
        }
        public void MoveForwardCommand_Should_Call_Create_Method_When_Expected_Value()
        {
            //Arrange
            var marsRoverService         = new Mock <IMarsRoverService>();
            var directionManagerStrategy = new Mock <IDirectionManagerStrategy>();

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

            //Act
            moveForwardCommand.Execute();

            //Assert
            directionManagerStrategy.Verify(mock => mock.MoveForward(It.IsAny <RoverPositionModel>()), Times.Once);
        }
Esempio n. 22
0
        public void ShouldBeAbleToHandleCommandWhenMoveDirectionIsNorth()
        {
            // arrange
            var command = new MoveForwardCommand
            {
                Direction = Directions.Directions.North
            };

            var handler = new MoveNorthCommandHandler(5);

            // act
            var canHandle = handler.CanHandle(command);

            // assert
            Assert.IsTrue(canHandle);
        }
Esempio n. 23
0
        public void ShouldNotBeAbleToHandleCommandWhenMoveDirectionIsNotEast()
        {
            // arrange
            var command = new MoveForwardCommand
            {
                Direction = Directions.Directions.South
            };

            var handler = new MoveEastCommandHandler(5);

            // act
            var canHandle = handler.CanHandle(command);

            // assert
            Assert.IsFalse(canHandle);
        }
Esempio n. 24
0
        public async Task MoveForward_WhenMoveIsValid_ShouldMoveProperly(Direction direction, int currentX, int currentY, int expectedX, int expectedY)
        {
            _moveValidatorMock.Setup(v => v.IsValidXMove(expectedX)).ReturnsAsync(true);
            _moveValidatorMock.Setup(v => v.IsValidYMove(expectedY)).ReturnsAsync(true);
            var position = new Point {
                X = currentX, Y = currentY
            };
            var expectedPosition = new Point {
                X = expectedX, Y = expectedY
            };
            var command = new MoveForwardCommand {
                CurrentPosition = position, Direction = direction
            };

            var result = await _moveCommandHandler.Handle(command, It.IsAny <CancellationToken>());

            Assert.Equal(expectedPosition, result.NewPosition);
        }
Esempio n. 25
0
    private void OnCurrentActorUpdated()
    {
        if (currentActor == null)
        {
            return;
        }
        Camera.main.GetComponent <CameraFollow360>().player = currentActor.transform;
        if (beautifySettings)
        {
            beautifySettings.depthOfFieldTarget = currentActor.transform;
        }

        // TODO: Refactor
        jumpCommand        = new JumpCommand(currentActor);
        kickCommand        = new KickCommand(currentActor);
        punchCommand       = new PunchCommand(currentActor);
        moveForwardCommand = new MoveForwardCommand(currentActor);
    }
Esempio n. 26
0
        public void TestShouldThrowExceptionIfFallsOffPlateau()
        {
            var     mf      = new MoveForwardCommand();
            Tractor tractor = new Tractor();

            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);

            try
            {
                mf.Execute(tractor);
                Assert.Fail("Tractor was expected to fall off the plateau");
            }
            catch (TractorInDitchException ex)
            {
            }
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        public void Move_TableTopFiveIntoFiveRobotIsPlacedBeforeMove()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 4),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();

            //assert
            Assert.IsTrue(tr.isRobotPlaced);
        }
Esempio n. 29
0
        public void TestShouldThrowExceptionIfFallsOffPlateau()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);

            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();

            try
            {
                moveCommand.Execute();
                Assert.Fail("Tractor was expected to fall off the plateau");
            }
            catch (TractorInDitchException)
            {
            }
        }
Esempio n. 30
0
        public async Task Navigate_WhenThereIsAMoveForwardCommand_ShouldMoveForward()
        {
            var commands         = "F";
            var initialPosition  = _robot.Position;
            var initialDirection = _robot.Direction;
            var command          = new MoveForwardCommand {
                CurrentPosition = initialPosition, Direction = initialDirection
            };
            var expectedPosition = new Point {
                X = 1, Y = 2
            };
            var result = new MoveResult {
                NewPosition = expectedPosition
            };

            _mediatorMock.Setup(m => m.Send(command, It.IsAny <CancellationToken>())).ReturnsAsync(result);

            await _robot.Navigate(commands);

            _mediatorMock.Verify(m => m.Send(command, It.IsAny <CancellationToken>()), Times.Once);
            _mediatorMock.VerifyNoOtherCalls();
            Assert.Equal(expectedPosition, _robot.Position);
        }