public void Turnleft_TableTop5Into5RobotTurnedLeftFourTimesSameFaing_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 leftCommand = new TurnLeftCommand(tr); //act leftCommand.Execute(); leftCommand.Execute(); leftCommand.Execute(); leftCommand.Execute(); //assert Assert.AreEqual(tr.robotDirection, Facing.NORTH); }
public void Robot_TurnLeftFromPosition_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 TurnLeftCommand(); 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 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 TurnLeft_WhenCalled_ShouldReturnProperDirection(Direction currentDirection, Direction expectedDirection) { var command = new TurnLeftCommand { 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 TurnLeftCommand(rover); command.Execute(); rover.Location.CardinalDirection.Should().Be(CardinalDirection.South); }
public void Turnleft_TableTopFiveIntoFiveRobotNotPlacedBeforeTurnLeft() { //arrange TableTop tt = new TableTop(5, 5); ToyRobot tr = new ToyRobot(); ICommandInterface leftCommand = new TurnLeftCommand(tr); //act leftCommand.Execute(); //assert Assert.IsFalse(tr.isRobotPlaced); }
public void Turn_Left_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 TurnLeftCommand(location); //act command.Execute(); //assert Assert.Equal(location.GetHeading(), expected); }
public void Test_TurnLeftCommand() { 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 TurnLeftCommand(); moveCommand.Execute(rover); Assert.AreEqual("1 2 W", 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.TurnLeft(rotate)).Returns(roverPoint).Verifiable(); ICommand turnLeftCommand = new TurnLeftCommand(roverMock.Object, rotate); turnLeftCommand.Run(); roverMock.Verify(c => c.TurnLeft(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_WhenThereIsATurnLeftCommand_ShouldTurnLeft() { var commands = "L"; var initialDirection = _robot.Direction; var expectedDirection = Direction.West; var command = new TurnLeftCommand { 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 Turnleft_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 leftCommand = new TurnLeftCommand(tr); //act leftCommand.Execute(); //assert Assert.IsTrue(tr.isRobotPlaced); }
public void Setup() { Robot = new Robot(new TableDimensions()); Command = new TurnLeftCommand(Robot); }
public void Setup() { _piece = new Piece(); _command = new TurnLeftCommand(_piece); }
public Command Create() { var command = new TurnLeftCommand(); return(command); }
private Rover ApplyCommand(TurnLeftCommand command) => new Rover(_position, _direction.ToLeft());