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); }
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()); }
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)); }
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); } }
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()); }
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)); }
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); }
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; } } }
// 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(); }
public void TestShouldMoveForward() { var mf = new MoveForwardCommand(); Tractor tractor = new Tractor(); mf.Execute(tractor); Assert.AreEqual(0, tractor.GetPositionX()); Assert.AreEqual(1, tractor.GetPositionY()); }
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>(); }
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()); }
public void HoverCommand_ShouldExecuteClientMoveForward() { // arrange moveForwardCommand = new MoveForwardCommand(DroneClientMock.Object); // act moveForwardCommand.Execute(); // assert DroneClientMock.Verify(x => x.MoveForward(), Times.Once); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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) { } }
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 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); }
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) { } }
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); }