public void TestCommandPlaceExecuteXParameter() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "A,2,NORTH"); }
public void TestCommandPlaceExecuteYParameterOverflow() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "1,23456789012,NORTH"); }
public void TestCommandPlaceExecuteYParameterFloat() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "1,2.0,NORTH"); }
public void IfRobotPlacedCorrectlyAtFirstTimeButNotCorrectlyAfterReportShouldShowLastPosition() { ToyRobot robot = PlaceRobotInPosition(new Position(1, 2), Direction.NORTH); Assert.IsNotNull(robot.RobotRoute); Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); MoveCommand moveCommand = new MoveCommand(); moveCommand.Execute(robot); PlaceCommand placeCommand = new PlaceCommand(new Route(new Position(10, 2), Direction.NORTH)); //This wrong Place will not set placeCommand.Execute(robot); Assert.AreEqual(robot.RobotStatus, RobotStatus.InvalidPositionForRobot); ReportCommand reportCommand = new ReportCommand(); //The report should be Last Position "OutPuT: 1,3, NORTH" reportCommand.Execute(robot); Assert.AreEqual(reportCommand.LastReportOfRobot, "OutPuT: 1,3, NORTH"); Console.WriteLine(reportCommand.LastReportOfRobot); moveCommand.Execute(robot); Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); reportCommand.Execute(robot); Assert.AreEqual(reportCommand.LastReportOfRobot, "OutPuT: 1,4, NORTH"); Console.WriteLine(reportCommand.LastReportOfRobot); }
public void TestCommandPlaceExecuteHasParameters() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, ""); }
public void Execute_AlreadyPlacedOnTable_OK() { // Arrange // Place robot on table var robot = new Robot(); var table = new Table(); var x = 0; var y = 0; var heading = CompassPoint.North; var placeCommand = new PlaceCommand(table, x, y, heading); placeCommand.Execute(robot); // Act // Replace robot on table in different location and heading. x = 1; y = 1; heading = CompassPoint.West; var replaceCommand = new PlaceCommand(table, x, y, heading); replaceCommand.Execute(robot); // Assert Assert.NotNull(placeCommand); Assert.Equal(x, robot.X); Assert.Equal(y, robot.Y); Assert.Equal(heading, (CompassPoint)robot.Heading); Assert.Same(table, robot.Table); }
public void Execute_PlacedDifferentTable_OK() { // Arrange // Place robot on table1 var robot = new Robot(); var table1 = new Table(); var x1 = 0; var y1 = 0; var heading1 = CompassPoint.North; var placeCommand = new PlaceCommand(table1, x1, y1, heading1); placeCommand.Execute(robot); // Act // Replace robot on table2 var table2 = new Table(); var x2 = 0; var y2 = 0; var heading2 = CompassPoint.North; var replaceCommand = new PlaceCommand(table2, x2, y2, heading2); replaceCommand.Execute(robot); // Assert Assert.NotNull(placeCommand); Assert.Equal(x2, robot.X); Assert.Equal(y2, robot.Y); Assert.Equal(heading2, (CompassPoint)robot.Heading); Assert.Same(table2, robot.Table); }
public void TestCommandPlaceExecuteTooManyParameters() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "1,2,NORTH,SHOE"); }
public void TestCommandPlaceExecuteFParameter() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "2,1,ANA"); }
private ToyRobot PlaceRobotInPosition(Position position, Direction direction) { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 Route route = new Route(position, direction); PlaceCommand placeCommand = new PlaceCommand(route); placeCommand.Execute(robot); return(robot); }
public void PlaceCommand_WithoutSetCurrentPosition_AndInvalidNewPositon_Returns_Null() { ICommand placeCommand = new PlaceCommand(new string[] { "5", "1", "NORTH" }); Position currentPosition = null; IPositionValidator positionValidator = new PositionValidator(5, 5); Position newPosition = placeCommand.Execute(currentPosition, positionValidator); Assert.IsNull(newPosition); }
public void IsNotPlacedOutOfBoundsOfGrid() { ILogger logger = new NullLogger <object>(); var grid = new Grid(5, 5); State? state = null; var command = new PlaceCommand(5, 3, MoveDirection.East); state = command.Execute(logger, state, grid); Assert.IsFalse(state.HasValue); }
public void PlaceRobotInCorrectPositionWithPlaceCommandTheRobotIsPlacedCorrectly() { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 Route route = new Route(new Position(1, 2), Direction.NORTH); PlaceCommand placeCommand = new PlaceCommand(route); placeCommand.Execute(robot); Assert.IsNotNull(robot.RobotRoute); Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); }
public void Robot_Placed_Outside_Table_Boundary_Should_Ignore_Command(string parameters) { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, parameters); var currentPosition = toyRobot.CurrentPosition; Assert.Null(currentPosition); }
public void PlaceRobot() { var placeCommand = new PlaceCommand("2,4,south"); var table = new TableTop(5, 5); var robot = new Robot(); placeCommand.Execute(robot, table); Assert.AreEqual(2, robot.X); Assert.AreEqual(4, robot.Y); Assert.AreEqual(Direction.South, robot.DirectionFacing); }
public void TestCommandPlaceExecuteValid() { Robot robot = new Robot(2); var command = new PlaceCommand(); command.Execute(robot, "2,1,NORTH"); Assert.AreEqual(2, robot.xPos); Assert.AreEqual(1, robot.yPos); Assert.AreEqual("NORTH", robot.bearing); }
public void PlaceCommand_WithoutSetCurrentPosition_AndValidNewPositon_Returns_PlacedPosition() { ICommand placeCommand = new PlaceCommand(new string[] { "1", "1", "NORTH" }); Position currentPosition = null; IPositionValidator positionValidator = new PositionValidator(5, 5); Position newPosition = placeCommand.Execute(currentPosition, positionValidator); Assert.That(newPosition.X == 1); Assert.That(newPosition.Y == 1); Assert.That(newPosition.Facing == Direction.NORTH); }
public void IsPlacedOnGrid() { ILogger logger = new NullLogger <object>(); var grid = new Grid(5, 5); State? state = null; var command = new PlaceCommand(3, 3, MoveDirection.East); state = command.Execute(logger, state, grid); Assert.AreEqual(MoveDirection.East, state.Value.Direction); Assert.AreEqual(3, state.Value.Coordinate.X); Assert.AreEqual(3, state.Value.Coordinate.Y); }
public void Robot_Valid_Place_Command_Should_Set_CurrentPosition() { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, "0,0,NORTH"); var currentPosition = toyRobot.CurrentPosition; Assert.NotNull(currentPosition); Assert.Equal(0, currentPosition.Coordinate.X); Assert.Equal(0, currentPosition.Coordinate.Y); Assert.Equal("NORTH", currentPosition.Direction.ToString()); }
public void Robot_Report_Command_With_Place_Should_Success() { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, "2,2,NORTH"); var afterPlacePosition = toyRobot.CurrentPosition; command = new ReportCommand(); var report = command.Execute(toyRobot); Assert.Equal("Output: 2,2,NORTH", report); }
public void TestPlaceCommand() { var rover = new Rover(); var cmd = new PlaceCommand(rover, new Point(1, 1), Direction.NORTH); Assert.IsTrue(cmd.Validate()); cmd.Execute(); Assert.AreEqual(rover.Position.X, 1); Assert.AreEqual(rover.Position.Y, 1); Assert.AreEqual(rover.Direction, Direction.NORTH); }
public void PlaceTest() { var currRobot = new Robot(); var place = new PlaceCommand(); currRobot = place.Execute("Place 4,4, South", currRobot); var expected = new Robot() { Dir = Face.South, X = 4, Y = 4 }; Assert.Equal(expected.Dir, currRobot.Dir); Assert.Equal(expected.X, currRobot.X); Assert.Equal(expected.Y, currRobot.Y); }
public void ShouldHandlePlaceCommand() { var command = new PlaceCommand() { X = 1, Y = 2, Direction = Direction.North }; var robot = new Robot(); command.Execute(robot); Assert.Equal(new Coordinate(1, 2), robot.Coordinate); Assert.Equal(Direction.North, robot.Direction); }
public void PlaceBoundaryNegTest() { var currRobot = new Robot(); var place = new PlaceCommand(); currRobot = place.Execute("Place -2,7, East", currRobot); var expected = new Robot() { Dir = Face.South, X = 0, Y = 0 }; Assert.Equal(expected.Dir, currRobot.Dir); Assert.Equal(expected.X, currRobot.X); Assert.Equal(expected.Y, currRobot.Y); }
public void Execute_RobotAndCoordinatesAndFacingGiven_ShouldCallRobotPlaceMethodWithCorrectCoordinatesAndFacing() { const int x = 2; const int y = 2; const Direction facing = Direction.South; // Arrange var robotMock = new Mock <IRobot>(); var placeCommand = new PlaceCommand(x, y, facing); // Act placeCommand.Execute(robotMock.Object); // Assert robotMock.Verify(robot => robot.Place(x, y, facing), Times.Once()); }
public void Robot_Moved_To_Outside_Table_Boundary_Should_Ignore_Command(string parameters) { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, parameters); var afterPlacePosition = toyRobot.CurrentPosition; command = new MoveCommand(); command.Execute(toyRobot); var afterMovePosition = toyRobot.CurrentPosition; Assert.NotNull(afterPlacePosition); Assert.Equal(afterMovePosition.Coordinate.Y, afterPlacePosition.Coordinate.Y); }
public void Robot_Valid_Rotate_Left_Command_From_North_Should_Turn_Robot_To_West() { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, "2,2,NORTH"); var afterPlacePosition = toyRobot.CurrentPosition; command = new LeftCommand(); command.Execute(toyRobot); var afterTurnLeftPosition = toyRobot.CurrentPosition; Assert.NotNull(afterPlacePosition); Assert.NotNull(afterTurnLeftPosition); Assert.Equal("WEST", afterTurnLeftPosition.Direction.ToString()); }
public void PlaceCommand_AndInvalidNewPositon_Returns_UnchangedPosition() { Position currentPosition = new Position { Facing = Direction.NORTH, X = 1, Y = 1 }; IPositionValidator positionValidator = new PositionValidator(5, 5); ICommand placeCommand = new PlaceCommand(new string[] { "1", "5", "SOUTH" }); Position newPosition = placeCommand.Execute(currentPosition, positionValidator); Assert.That(newPosition.X == 1); Assert.That(newPosition.Y == 1); Assert.That(newPosition.Facing == Direction.NORTH); }
public void Robot_Valid_Move_Command_To_East_Should_Adavance_Step_By_One_Unit() { Robot toyRobot = new Robot(table); Command command = new PlaceCommand(); command.Execute(toyRobot, "2,2,EAST"); var afterPlacePosition = toyRobot.CurrentPosition; command = new MoveCommand(); command.Execute(toyRobot); var afterMovePosition = toyRobot.CurrentPosition; Assert.NotNull(afterPlacePosition); Assert.NotNull(afterMovePosition); Assert.Equal(afterPlacePosition.Coordinate.X + 1, afterMovePosition.Coordinate.X); Assert.Equal("EAST", afterMovePosition.Direction.ToString()); }
public void ReportsPositionWhenPlaced() { string output = null; ILogger logger = new CustomisableTextLogger(delegate(string message) { output = message; }); var grid = new Grid(5, 5); State?state = null; Command command = new PlaceCommand(3, 3, MoveDirection.East); state = command.Execute(logger, state, grid); command = new ReportCommand(); state = command.Execute(logger, state, grid); Assert.AreEqual("3,3,East", output); }