public void TestRobotRotateCommand() { var rotateLeft = new RotateLeftCommand(); var robot = new Robot(new Point(0, 0), RobotOrientation.North); rotateLeft.ExecuteCommandFor(robot); Assert.AreEqual(robot.Orientation, RobotOrientation.West); }
public void GivenRotateLeftCommand_WhenExecute_ThenRoverTurnedLeft() { IControlCommand command = new RotateLeftCommand(); 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("W", rover.CurrentPosition.Direction); }
/// <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 Execute_RobotGiven_ShouldCallRobotRotateLeftMethod() { // Arrange var robotMock = new Mock <IRobot>(); var rotateLeftCommand = new RotateLeftCommand(); // Act rotateLeftCommand.Execute(robotMock.Object); // Assert robotMock.Verify(robot => robot.RotateLeft(), Times.Once()); }
public void Rover_FacingSouth_AtPosition34_5x5Grid_TurnsEast() { Coordinates startPosition = new Coordinates(3, 4); IDirection currentDirection = new South(); Grid grid = new Grid(new Coordinates(0, 0), new Coordinates(5, 5)); IRover rover = new MarsRover(currentDirection, startPosition, grid); ICommand moveCommand = new RotateLeftCommand(); moveCommand.Execute(rover); Assert.That(rover.CurrentDirection, Is.TypeOf <East>()); Assert.That(rover.CurrentPosition.XCoordinate == 3); Assert.That(rover.CurrentPosition.YCoordinate == 4); }
public void RotateLeftCommand_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 RotateLeftCommand(marsRoverService.Object, directionManagerStrategy.Object); //Act moveForwardCommand.Execute(); //Assert directionManagerStrategy.Verify(mock => mock.RotateLeft(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); }
static void Main() { var robot = new Robot(); var controller = new RobotController(); var move = new MoveCommand(robot); move.ForwardDistance = 1000; controller.Commands.Enqueue(move); var rotate = new RotateLeftCommand(robot); rotate.LeftRotationAngle = 45; controller.Commands.Enqueue(rotate); var scoop = new TakeSampleCommand(robot); scoop.TakeSample = true; controller.Commands.Enqueue(scoop); controller.ExecuteCommands(); controller.UndoCommands(3); }
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); }
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 RotateLeftCommand(spyCommand); rotateCommand.Execute(testTrackingModule); var actualTrackingModule = spyCommand.TrackingModule; actualTrackingModule.Position.Orientation.Should().Be(expectedOrientation); }
static void Main(string[] args) { // Try fix the robot example. Client does not need to know about receiver. // Basiicall the idea is that we are passing the receiver to the command and then passing the command to the // invoker which will then invoke the command on the relevant receiver. // So the invoker has the power of turing the light on. #region Robot var robot = new RobotObject(); var controller = new RobotController(); // Setting up the commands var move = new MoveCommand(robot); move.ForwardDistance = 1000; controller.Commands.Enqueue(move); var rotate = new RotateLeftCommand(robot); rotate.LeftRotationAngle = 45; controller.Commands.Enqueue(rotate); var scoop = new TakeSampleCommand(robot); scoop.TakeSample = true; controller.Commands.Enqueue(scoop); // Executing the commands controller.ExecuteCommands(); controller.UndoCommands(3); #endregion #region Calculator // Create user and let her compute User user = new User(); // User presses calculator buttons user.Compute('+', 100); user.Compute('-', 50); user.Compute('*', 10); user.Compute('/', 2); // Undo 4 commands user.Undo(4); // Redo 3 commands user.Redo(3); #endregion #region Fast Food Patron patron = new Patron(); patron.SetCommand(1 /*Add*/); patron.SetMenuItem(new MenuItem("French Fries", 2, 1.99)); patron.ExecuteCommand(); patron.SetCommand(1 /*Add*/); patron.SetMenuItem(new MenuItem("Hamburger", 2, 2.59)); patron.ExecuteCommand(); patron.SetCommand(1 /*Add*/); patron.SetMenuItem(new MenuItem("Drink", 2, 1.19)); patron.ExecuteCommand(); patron.ShowCurrentOrder(); //Remove the french fries patron.SetCommand(3 /*Remove*/); patron.SetMenuItem(new MenuItem("French Fries", 2, 1.99)); patron.ExecuteCommand(); patron.ShowCurrentOrder(); //Now we want 4 hamburgers rather than 2 patron.SetCommand(2 /*Edit*/); patron.SetMenuItem(new MenuItem("Hamburger", 4, 2.59)); patron.ExecuteCommand(); patron.ShowCurrentOrder(); Console.ReadKey(); #endregion }
public void setRotateLeftCommand(RotateLeftCommand rotateLeftCommand) { this.rotateLeftCommand = rotateLeftCommand; }