public void Move_RobotIn0_0_N_RobotIn0_1_N_DirectionIsNorth() { var robot = new ToyRobot(); robot.Place(0, 0, Domain.Direction.North); var newPosition = robot.CalculateNextPosition(); robot.Place(newPosition.X, newPosition.Y); Assert.Equal(Domain.Direction.North, robot.CurrentDirection); }
public void Place_WhenStatusIsOn_InvaliadPosition(CompassDirections direction, int positionX, int positionY) { var robot = new ToyRobot(new TableSurface(), _exceptionFactory); robot.Place(new RobotPosition { X = 2, Y = 2, Direction = CompassDirections.NORTH }); robot.MoveForward(); Exception ex = Assert.Throws <SafeException>(() => robot.Place(new RobotPosition { X = positionX, Y = positionY, Direction = direction })); Assert.Equal("the robot cannot place to expected postion", ex.Message); }
public void TestPlacingAToyRobotShouldBePlacedCorrectly() { // Arrange uint width = 5; uint height = 5; var table = new Table(width, height); var toyRobot = new ToyRobot(table); uint xPosition = 1; uint yPosition = 3; Direction robotDirection = Direction.EAST; // Assert // make sure robot is not placed Assert.True(!toyRobot.X.HasValue && !toyRobot.Y.HasValue && !toyRobot.Direction.HasValue && !toyRobot.IsPlaced); // ACT toyRobot.Place(xPosition, yPosition, robotDirection); // make sure robot is placed Assert.True(toyRobot.IsPlaced); Assert.True(toyRobot.X.HasValue && toyRobot.X.Value == xPosition); Assert.True(toyRobot.Y.HasValue && toyRobot.Y.Value == yPosition); Assert.True(toyRobot.Direction.HasValue && toyRobot.Direction.Value == robotDirection); }
public void TestMoveOnTable() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Define a test input and output value: int x = 0; int y = 0; Facing facing = Facing.North; robot.Place(x, y, facing); // Run the method under test and verify test when facing North robot.Move(); Assert.AreEqual(robot.X, 0); Assert.AreEqual(robot.Y, 1); Assert.AreEqual(robot.Facing, Facing.North); // Run the method under test and verify test when facing East robot.GetType().GetProperty("Facing").SetValue(robot, Facing.East); robot.Move(); Assert.AreEqual(robot.X, 1); Assert.AreEqual(robot.Y, 1); Assert.AreEqual(robot.Facing, Facing.East); // Run the method under test and verify test when facing South robot.GetType().GetProperty("Facing").SetValue(robot, Facing.South); robot.Move(); Assert.AreEqual(robot.X, 1); Assert.AreEqual(robot.Y, 0); Assert.AreEqual(robot.Facing, Facing.South); // Run the method under test and verify test when facing West robot.GetType().GetProperty("Facing").SetValue(robot, Facing.West); robot.Move(); Assert.AreEqual(robot.X, 0); Assert.AreEqual(robot.Y, 0); Assert.AreEqual(robot.Facing, Facing.West); }
public void WhenPlacingARobotInInvalidPositionsMakeSurePlaceCommandIsIgnored() { // create a robot that knows about it's environment var board = new Board(5, 5); var robot = new ToyRobot(board); Assert.IsNotNull(board); Assert.IsNotNull(robot); var direction = Direction.North; robot.Place(new Vector2d <ulong>(new Point2d <ulong>(0, 0), direction)); Assert.IsTrue(robot.HasAPosition); Assert.IsTrue(ComparePosition(robot, 0, 0, direction)); // get robot current position & direction var origRobotX = robot.Vector.Position.X; var origRobotY = robot.Vector.Position.Y; var origRobotDir = robot.Vector.Dir; var extraXDim = (ulong)5; var extraYDim = (ulong)5; // test some invalid positions for (var x = board.Width; x < board.Width + extraXDim; x++) { WhenPlacingARobotInInvalidPositionsMakeSurePlaceCommandIsIgnoredOnEachColumn(board, robot, direction, origRobotX, origRobotY, origRobotDir, extraYDim, x); } }
public ToyRobot PlaceRobotInPosition(Position position, Direction direction) { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 robot.Place(new Route(position, direction)); return(robot); }
public void TheRobotCouldWalkThroughTheBoardSurfaceFromSouthToNorthAndReturnAndReportLastPosition() { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 //walk from start position 0,0 face to NORTH, move to the edge of NORTH //then turn Right and one move right, // agian turn Right to face back SOUTH and move to the edge of SOUTH // continue this pattern to seek all the board surface to position 5,0 robot.Place(new Route(new Position(0, 0), Direction.NORTH)); for (int horizontalStep = 0; horizontalStep <= 5; horizontalStep++) { Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); for (int verticalStep = 1; verticalStep <= 5; verticalStep++) { robot.Move(); Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); } if (robot.RobotRoute.RobotFaceDirection == Direction.NORTH) { robot.TurnRight(); robot.Move(); robot.TurnRight(); continue; } if (robot.RobotRoute.RobotFaceDirection == Direction.SOUTH) { robot.TurnLeft(); robot.Move(); robot.TurnLeft(); } } // the report should be "OutPuT: 5,0, NORTH" Assert.AreEqual(robot.Report(), "OutPuT: 5,0, NORTH"); Console.WriteLine(robot.Report()); }
public void TheRobotCouldWalkThroughTheBoardSurfaceFromEastToWestAndReturnAndReportLastPosition() { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 //walk from start position 0,0 face to east, move to the edge of EAST //then turn left and one move up, // agian turn left to face back WEST and move to the edge of WEST // continue this pattern to seek all the board surface to position 0,5 robot.Place(new Route(new Position(0, 0), Direction.EAST)); for (int verticalStep = 0; verticalStep <= 5; verticalStep++) { Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); for (int horizontalStep = 1; horizontalStep <= 5; horizontalStep++) { robot.Move(); Assert.AreEqual(robot.RobotStatus, RobotStatus.CorrectPlaceToStand); } if (robot.RobotRoute.RobotFaceDirection == Direction.EAST) { robot.TurnLeft(); robot.Move(); robot.TurnLeft(); continue; } if (robot.RobotRoute.RobotFaceDirection == Direction.WEST) { robot.TurnRight(); robot.Move(); robot.TurnRight(); } } // The report should be "OutPuT: 0,5, EAST" Assert.AreEqual(robot.Report(), "OutPuT: 0,5, EAST"); Console.WriteLine(robot.Report()); }
// combining all actions of robots to make sure it returns expect result public void TestAToyRobotWithAllActionsShouldBeReturnCorrectPosAndDirection() { // Arrange uint width = 5; uint height = 5; var table = new Table(width, height); // initializing position for a toy robot var toyRobot = new ToyRobot(table); // add PLACE action toyRobot.Place(1, 1, Direction.NORTH); // add three move actions toyRobot.Move(); toyRobot.Move(); toyRobot.Move(); // then turn right toyRobot.TurnRight(); // then turn left toyRobot.TurnLeft(); // Testing key point, just move once again, should ignore the Move step, because robot position beyond table height toyRobot.Move(); var expectXPostion = 1; var expectYPostion = 4; var expectDirection = Direction.NORTH; // Assert Assert.True(toyRobot.X == expectXPostion && toyRobot.Y == expectYPostion && toyRobot.Direction == expectDirection); }
public void ToyRobot_internal_MoveTest() { ToyTable tb = ToyTableTests.ToyTableCreate_successtest(100, 500); ToyRobot robot = new ToyRobot(tb); robot.Place(new CoordinateXY(55, 45), Direction.NORTH); // test move in different directions robot.Move(); TestLocation(robot, new CoordinateXY(55, 46), Direction.NORTH); robot.Turn(true); robot.Move(); robot.Move(); TestLocation(robot, new CoordinateXY(53, 46), Direction.WEST); robot.Turn(true); robot.Move(); robot.Move(); TestLocation(robot, new CoordinateXY(53, 44), Direction.SOUTH); robot.Turn(true); robot.Move(); robot.Move(); TestLocation(robot, new CoordinateXY(55, 44), Direction.EAST); Assert.AreEqual(robot.Report(), "55,44,EAST"); // test out of bound movements robot.Place(new CoordinateXY(0, 0), Direction.NORTH); robot.Turn(true); AssertOutofBoundException(() => { robot.Move(); }); robot.Turn(true); TestLocation(robot, new CoordinateXY(0, 0), Direction.SOUTH); AssertOutofBoundException(() => { robot.Move(); }); robot.Turn(true); robot.Move(); robot.Move(); TestLocation(robot, new CoordinateXY(2, 0), Direction.EAST); robot.Turn(true); TestLocation(robot, new CoordinateXY(2, 0), Direction.NORTH); // move 499 times north to the edge. for (int i = 0; i < 499; i++) { robot.Move(); TestLocation(robot, new CoordinateXY(2, i + 1), Direction.NORTH); } // next move sound be out of bound. AssertOutofBoundException(() => { robot.Move(); }); TestLocation(robot, new CoordinateXY(2, 499), Direction.NORTH); }
public void Robot_Ctor_PlaceIn0_0_N_VerifyCurrentDirection() { var robot = new ToyRobot(); robot.Place(0, 0, Domain.Direction.North); Assert.Equal(Domain.Direction.North, robot.CurrentDirection); }
public void Discard_command_when_X_is_invalid(int x) { var toyRobot = new ToyRobot(); toyRobot.Place(x, 2, Direction.South); toyRobot.X.Should().NotBe(x); }
public void Discard_command_when_direction_is_invalid(string direction) { var toyRobot = new ToyRobot(); toyRobot.Place(1, 2, direction); toyRobot.Facing.Should().NotBe(direction); }
public void Set_robots_direction(string direction) { var toyRobot = new ToyRobot(); toyRobot.Place(1, 2, direction); toyRobot.Facing.Should().Be(direction); }
public void Set_robots_Y_position(int y) { var toyRobot = new ToyRobot(); toyRobot.Place(1, y, Direction.South); toyRobot.Y.Should().Be(y); }
public void Place_WhenStatusIsOn_ValiadPosition(CompassDirections direction, int positionX, int positionY) { var robot = new ToyRobot(new TableSurface(), _exceptionFactory); robot.Place(new RobotPosition { X = 2, Y = 2, Direction = CompassDirections.NORTH }); robot.MoveForward(); robot.Place(new RobotPosition { X = positionX, Y = positionY, Direction = direction }); Assert.Equal(RobotStatus.On, robot.Status); Assert.Equal(positionX, robot.Position.X); Assert.Equal(positionY, robot.Position.Y); Assert.Equal(direction, robot.Position.Direction); }
public void Set_robots_X_position(int x) { var toyRobot = new ToyRobot(); toyRobot.Place(x, 2, Direction.South); toyRobot.X.Should().Be(x); }
public void Discard_command_when_Y_is_invalid(int y) { var toyRobot = new ToyRobot(); toyRobot.Place(1, y, Direction.South); toyRobot.Y.Should().NotBe(y); }
public void TestMoveRobotWillFallException() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Define a test input and output value: int x = 4; int y = 4; Facing facing = Facing.North; robot.Place(x, y, facing); // Run the method under test and verify test when facing North try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing East robot.GetType().GetProperty("Facing").SetValue(robot, Facing.East); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing South robot.GetType().GetProperty("Facing").SetValue(robot, Facing.South); robot.GetType().GetProperty("Y").SetValue(robot, 0); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing West robot.GetType().GetProperty("Facing").SetValue(robot, Facing.West); robot.GetType().GetProperty("X").SetValue(robot, 0); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } }
public void Rotate_CurrentDirectionNorthMoveRight_CurrentDirectionEast() { var robot = new ToyRobot(); robot.Place(0, 0, Domain.Direction.North); robot.Rotate(Domain.Rotation.Right); Assert.Equal(Domain.Direction.East, robot.CurrentDirection); }
public void Rotate_CurrentDirectionWestMoveLeft_CurrentDirectionSouth() { var robot = new ToyRobot(); robot.Place(0, 0, Domain.Direction.West); robot.Rotate(Domain.Rotation.Left); Assert.Equal(Domain.Direction.South, robot.CurrentDirection); }
public void Move_RobotIn0_0_N_RobotIn0_1_N_XIs1() { var robot = new ToyRobot(); robot.Place(0, 0, Domain.Direction.North); var nextPosition = robot.CalculateNextPosition(); Assert.Equal(1, nextPosition.Y); }
public void ToyRobot_internal_tests() { try { // when table is null ToyRobot failbot = new ToyRobot(null); } catch (ArgumentException) { } // create table and robot instance ToyTable tb = ToyTableTests.ToyTableCreate_successtest(522, 522); Assert.IsNotNull(tb); ToyRobot robot = new ToyRobot(tb); Assert.IsNotNull(robot); // running commands before robot is placed AssertInvalidRobotCommandException(() => { robot.Report(); }); AssertInvalidRobotCommandException(() => { robot.Move(); }); AssertInvalidRobotCommandException(() => { robot.Turn(true); }); AssertInvalidRobotCommandException(() => { robot.Turn(false); }); // placing robot at invalid locations AssertOutofBoundException(() => { robot.Place(new CoordinateXY(0, -1)); }); AssertOutofBoundException(() => { robot.Place(new CoordinateXY(0, 522)); }); AssertOutofBoundException(() => { robot.Place(new CoordinateXY(521, 522)); }); AssertOutofBoundException(() => { robot.Place(new CoordinateXY(524, 522)); }); AssertOutofBoundException(() => { robot.Place(new CoordinateXY(-14, -1)); }); // place robot tests PlaceRobotTest(robot, new CoordinateXY(0, 0), Direction.NORTH); PlaceRobotTest(robot, new CoordinateXY(0, 0), Direction.SOUTH); PlaceRobotTest(robot, new CoordinateXY(0, 0), Direction.EAST); robot.Report(); PlaceRobotTest(robot, new CoordinateXY(0, 22), Direction.WEST); PlaceRobotTest(robot, new CoordinateXY(521, 521), Direction.WEST); robot.Report(); PlaceRobotTest(robot, new CoordinateXY(520, 21), Direction.NORTH); PlaceRobotTest(robot, new CoordinateXY(0, 24), Direction.SOUTH); PlaceRobotTest(robot, new CoordinateXY(55, 0), Direction.EAST); Assert.AreEqual(robot.Report(), "55,0,EAST"); Assert.AreEqual(robot.Report(), "55,0,EAST"); //report multiple times Assert.AreEqual(robot.Report(), "55,0,EAST"); //report multiple times }
public void Return_position_when_it_is_valid(int x, int y, string direction, string report) { var toyRobot = new ToyRobot(); toyRobot.Place(x, y, direction); var result = toyRobot.Report(); result.Should().Be(report); }
public void Rotate_robot_left_90_degrees(string before, string after) { var toyRobot = new ToyRobot(); toyRobot.Place(1, 1, before); toyRobot.Left(); toyRobot.Facing.Should().Be(after); }
public void TheRobotMovementToWrongXPositionWillBeIgnored() { ToyRobot robot = new ToyRobot(new Board());//Default Borad is 5 x 5 //Place Robot At the edge of east, face to EAST robot.Place(new Route(new Position(5, 0), Direction.EAST)); robot.Move(); Assert.AreEqual(robot.RobotStatus, RobotStatus.InvalidPositionForRobot); //Robot stayed at the last correct position Assert.AreEqual(robot.RobotRoute.RobotPosition.X, 5); }
public void Move_North_when_facing_North() { var toyRobot = new ToyRobot(); toyRobot.Place(2, 2, Direction.North); toyRobot.Move(); toyRobot.X.Should().Be(2); toyRobot.Y.Should().Be(3); }
public void Not_cause_the_robot_to_fall_outside_the_table(int x, int y, string direction) { var toyRobot = new ToyRobot(); toyRobot.Place(x, y, direction); toyRobot.Move(); toyRobot.X.Should().Be(x); toyRobot.Y.Should().Be(y); }
public void Move_West_when_facing_West() { var toyRobot = new ToyRobot(); toyRobot.Place(2, 2, Direction.West); toyRobot.Move(); toyRobot.X.Should().Be(1); toyRobot.Y.Should().Be(2); }
private void Window_MouseButtonReleased(object sender, MouseButtonEventArgs e) { var coords = window.MapPixelToCoords(new SFML.System.Vector2i(e.X, e.Y)); // Flip the vertical axis. var finalPosition = new TRS.Library.Vector2i { x = (int)coords.X / size, y = height - 1 - (int)coords.Y / size }; if (e.Button == Mouse.Button.Left) { toyRobot.Place(finalPosition.x, finalPosition.y); } if (e.Button == Mouse.Button.Right) { toyRobot.Place(map, finalPosition.x, finalPosition.y, toyRobot.Direction); } }