public void Robot_TurnRightFromPosition_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[, ] { }, new Stack <CommandType>()); // Act var command = new TurnRightCommand(); command.ExecuteCommand(robot); // Assert Assert.AreEqual(robot.Position.Facing, estimatedFacing); Assert.AreEqual(robot.Battery, estimatedBattery); Assert.AreEqual(robot.Position.Location.X, initial_location_X); Assert.AreEqual(robot.Position.Location.Y, initial_location_Y); }
public void Turnright_TableTop5Into5RobotTurnedRightFourTimesSameFacing_IsTrue() { //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 rightCommand = new TurnRightCommand(tr); //act rightCommand.Execute(); rightCommand.Execute(); rightCommand.Execute(); rightCommand.Execute(); //assert Assert.AreEqual(tr.robotDirection, Facing.NORTH); }
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; } } }
public async Task TurnRight_WhenCalled_ShouldReturnProperDirection(Direction currentDirection, Direction expectedDirection) { var command = new TurnRightCommand { CurrentDirection = currentDirection }; var result = await _turnCommandHandler.Handle(command, It.IsAny <CancellationToken>()); Assert.Equal(expectedDirection, result.NewDirection); }
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 TurnRightCommand(rover); command.Execute(); rover.Location.CardinalDirection.Should().Be(CardinalDirection.North); }
public void Turnright_TableTopFiveIntoFiveRobotNotPlacedBeforeTurnLeft() { //arrange TableTop tt = new TableTop(5, 5); ToyRobot tr = new ToyRobot(); ICommandInterface turnRight = new TurnRightCommand(tr); //act turnRight.Execute(); //assert Assert.IsFalse(tr.isRobotPlaced); }
public void Turn_Right_Command_Should_Change_Heading_Accordingly(Heading input, Heading expected) { //arrange var random = new Random(); var location = new Location(random.Next(), random.Next(), input); ICommand command = new TurnRightCommand(location); //act command.Execute(); //assert Assert.Equal(location.GetHeading(), expected); }
public void Test_TurnRightCommand() { var plateau = new Plateau(5, 5); var coordinate = new Coordinate(1, 2); var direction = DirectionParser.GetDirection('N'); var rover = new MarsRover(plateau, coordinate, direction); var moveCommand = new TurnRightCommand(); moveCommand.Execute(rover); Assert.AreEqual("1 2 E", rover.GetCurrentLocation()); }
public void Run_Should() { Mock <IRover> roverMock = new Mock <IRover>(); Rotate rotate = Rotate.Half; Point roverPoint = new Point(1, 2); roverMock.SetupGet(c => c.Point).Returns(roverPoint); roverMock.Setup(c => c.TurnRight(rotate)).Returns(roverPoint).Verifiable(); ICommand turnRightCommand = new TurnRightCommand(roverMock.Object, rotate); turnRightCommand.Run(); roverMock.Verify(c => c.TurnRight(rotate)); roverMock.Object.Point.X.Should().Be(1); roverMock.Object.Point.Y.Should().Be(2); }
public Command NextCommand() { Command command; if (!commands.Any()) { command = new TurnLeftCommand(hardwareRobot, room); } else if (CanWalk) { command = new WalkCommand(hardwareRobot, room); } else { command = new TurnRightCommand(hardwareRobot, room); } commands.Add(command); return(command); }
public async Task Navigate_WhenThereIsATurnRightCommand_ShouldTurnRight() { var commands = "R"; var initialDirection = _robot.Direction; var expectedDirection = Direction.East; var command = new TurnRightCommand { CurrentDirection = initialDirection }; var result = new TurnResult { NewDirection = expectedDirection }; _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(expectedDirection, _robot.Direction); }
public void Turnright_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 rightCommand = new TurnRightCommand(tr); //act rightCommand.Execute(); //assert Assert.IsTrue(tr.isRobotPlaced); }
public void Setup() { Robot = new Robot(new TableDimensions()); Command = new TurnRightCommand(Robot); }
private Rover ApplyCommand(TurnRightCommand command) => new Rover(_position, _direction.ToRight());
public Command Create() { var command = new TurnRightCommand(); return(command); }
public void Setup() { _piece = new Piece(); _command = new TurnRightCommand(_piece); }