public void Rover_Should_GenerateOutput() { _location.Initialize(new Position(5, 5)); IRover rover1 = new MarsRover(new Position(1, 2), CompassDirection.North, _location); rover1.Rotate(Rotation.Left); rover1.Move(); rover1.Rotate(Rotation.Left); rover1.Move(); rover1.Rotate(Rotation.Left); rover1.Move(); rover1.Rotate(Rotation.Left); rover1.Move(); rover1.Move(); IRover rover2 = new MarsRover(new Position(3, 3), CompassDirection.East, _location); rover2.Move(); rover2.Move(); rover2.Rotate(Rotation.Right); rover2.Move(); rover2.Move(); rover2.Rotate(Rotation.Right); rover2.Move(); rover2.Rotate(Rotation.Right); rover2.Rotate(Rotation.Right); rover2.Move(); string output = rover1.PrintPositionAndCompassDirection() + rover2.PrintPositionAndCompassDirection(); string expectedString = "1 3 N\r\n5 1 E\r\n"; Assert.Equal(expectedString, output); }
public void When_A_Rover_Is_Facing_North_At_0_9_And_Given_The_Command_F_On_A_10_By_10_Grid_The_Position_Should_Be_0_0_N() { var rover = new MarsRover(new Mars()); rover.Move("FFFFFFFFF"); Assert.AreEqual("0, 9, N", rover.CurrentPosition); rover.Move("F"); Assert.AreEqual("0, 0, N", rover.CurrentPosition); }
public void When_A_New_Rover_Is_Facing_East_And_Given_The_Command_B_On_A_10_By_10_Grid_The_Position_Should_Be_9_0_E() { var rover = new MarsRover(new Mars()); rover.Move("R"); Assert.AreEqual("0, 0, E", rover.CurrentPosition); rover.Move("B"); Assert.AreEqual("9, 0, E", rover.CurrentPosition); }
public void When_A_Rover_Is_Facing_East_And_Given_The_Command_F_The_Position_Should_Be_1_0_E() { var rover = new MarsRover(new Mars()); rover.Move("R"); Assert.AreEqual("0, 0, E", rover.CurrentPosition); rover.Move("F"); Assert.AreEqual("1, 0, E", rover.CurrentPosition); }
public void When_A_Rover_Is_Facing_West_At_9_0_And_Given_The_Command_B_On_A_10_By_10_Grid_The_Position_Should_Be_0_0_W() { var rover = new MarsRover(new Mars()); rover.Move("L"); rover.Move("BBBBBBBBB"); Assert.AreEqual("9, 0, W", rover.CurrentPosition); rover.Move("B"); Assert.AreEqual("0, 0, W", rover.CurrentPosition); }
public void When_A_Rover_Is_Facing_South_And_Given_The_Command_B_The_Position_Should_Be_0_1_S() { var rover = new MarsRover(new Mars()); rover.Move("R"); rover.Move("R"); Assert.AreEqual("0, 0, S", rover.CurrentPosition); rover.Move("B"); Assert.AreEqual("0, 1, S", rover.CurrentPosition); }
public void When_A_Rover_Is_Facing_South_At_0_9_And_Given_The_Command_B_On_A_10_By_10_Grid_The_Position_Should_Be_0_0_S() { var rover = new MarsRover(new Mars()); rover.Move("RR"); rover.Move("BBBBBBBBB"); Assert.AreEqual("0, 9, S", rover.CurrentPosition); rover.Move("B"); Assert.AreEqual("0, 0, S", rover.CurrentPosition); }
public void When_A_Rover_Facing_South_At_0_0_Is_Given_The_Command_B_And_An_Obstacle_Is_At_0_1_An_Exception_Should_Be_Thrown() { var rover = new MarsRover(new MarsWithObstacles(new[] { new Obstacle(0, 1) // Obstacle at (0, 1) })); rover.Move("RR"); Assert.AreEqual("0, 0, S", rover.CurrentPosition); rover.Move("B"); }
public void When_A_Rover_Facing_East_At_0_0_Is_Given_The_Command_F_And_An_Obstacle_Is_At_1_0_An_Exception_Should_Be_Thrown() { var rover = new MarsRover(new MarsWithObstacles(new[] { new Obstacle(1, 0) // Obstacle at (1, 0) })); rover.Move("R"); Assert.AreEqual("0, 0, E", rover.CurrentPosition); rover.Move("F"); }
public void TestExampleMovements() { var rover = new MarsRover(); rover.Map = Map.Parse("5 5"); rover.CurrentPosition = Position.Parse("1 2 N"); rover.Move("LMLMLMLMM"); Assert.AreEqual(rover.CurrentPosition.ToString(), "1 3 N"); rover.CurrentPosition = Position.Parse("3 3 E"); rover.Move("MMRMMRMRRM"); Assert.AreEqual(rover.CurrentPosition.ToString(), "5 1 E"); }
public void NotMoveBeyondGridBoundary(string marsRoverInput, string expectedResult) { var marsRover = new MarsRover(); var result = MarsRover.Move(marsRoverInput); result.Should().Be(expectedResult); }
public void When_A_New_Rover_Is_Given_The_Command_R_Four_Times_The_Position_Should_Be_0_0_N() { var rover = new MarsRover(new Mars()); rover.Move("R"); Assert.AreEqual("0, 0, E", rover.CurrentPosition); rover.Move("R"); Assert.AreEqual("0, 0, S", rover.CurrentPosition); rover.Move("R"); Assert.AreEqual("0, 0, W", rover.CurrentPosition); rover.Move("R"); Assert.AreEqual("0, 0, N", rover.CurrentPosition); }
public void RespondToObstacle() { //Arrange Point startingPoint = new Point(0, 0); var obstacleCoords = new Point(0, 1); var obstacles = new List <Point>() { obstacleCoords }; MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North; var ObstacleDetector = new ObstacleDetector(obstacles); MarsRover rover = new MarsRover(startingPoint, startingDirection, null, ObstacleDetector); var moves = new[] { 'f' }; Point expectedCoordinates = startingPoint; MarsRover.CardinalDirection expectedStartingDirection = startingDirection; //Act rover.Move(moves); //Assert Assert.AreEqual(expectedCoordinates, rover.Coordinates); //rover did not move Assert.AreEqual(expectedStartingDirection, rover.Direction); //rover did not move Assert.AreEqual($"obstacle detected at: ({obstacleCoords})", rover.Status.StatusMessage); Assert.AreEqual(RoverStatus.RoverStatusCode.Fail, rover.Status.StatusCode); }
public void execute_command_return_position(string command, string expected) { var rover = new MarsRover(); var position = rover.Move(command); Assert.That(position, Is.EqualTo(expected)); }
public void MoveForwardOnceWhenSpecifiedByInput(string marsRoverInput, string expectedResult) { var marsRover = new MarsRover(); var result = MarsRover.Move(marsRoverInput); result.Should().Be(expectedResult); }
public void When_A_New_Rover_Is_Given_The_Command_FFRFF_The_Position_Should_Be_2_2_E() { var rover = new MarsRover(new Mars()); rover.Move("FFRFF"); Assert.AreEqual("2, 2, E", rover.CurrentPosition); }
public void When_A_New_Rover_Is_Given_The_Command_L_The_Position_Should_Be_0_0_W() { var rover = new MarsRover(new Mars()); rover.Move("L"); Assert.AreEqual("0, 0, W", rover.CurrentPosition); }
public void RotateToOrientationSpecifiedByInput(string roverInput, string expectedOutput) { var marsRover = new MarsRover(); var result = MarsRover.Move(roverInput); result.Should().Be(expectedOutput); }
public void MoveBackward_OneUnit_AccordingToDirection(int startingX, int startingY, Direction startingDirection, int expectedX, int expectedY) { marsRover = new MarsRover(startingX, startingY, startingDirection); marsRover.Move(Movement.Backward); Assert.AreEqual(expectedX, marsRover.X); Assert.AreEqual(expectedY, marsRover.Y); }
public void ThrowARoverOutsideOfPlateauExceptionWhenMovedOutsideOfThePlateauBounds() { var initialPosition = new VectorWithHeading(2, 2, Heading.North); var plateau = new Plateau(2, 2); var marsRover = new MarsRover(initialPosition, plateau); Assert.Throws <RoverOutsideOfPlateauException>(() => marsRover.Move()); }
public void Test7() { string plateauInput = "5 5"; string initialStateInput = "1 2 N"; var marsRover = new MarsRover(plateauInput); marsRover.UpdateValues(initialStateInput); marsRover.Move(); Assert.Equal("1 3 N", marsRover.RunAndGetResult()); }
public void When_A_New_Rover_Is_Given_The_Command_B_And_An_Obstacle_Is_At_0_9_An_Exception_Should_Be_Thrown() { var rover = new MarsRover(new MarsWithObstacles(new[] { new Obstacle(0, 9) // Obstacle at (0, 9) })); Assert.AreEqual("0, 0, N", rover.CurrentPosition); rover.Move("B"); }
public void Test_Move() { var plateau = new Plateau(5, 5); var coordinate = new Coordinate(1, 2); var direction = DirectionParser.GetDirection('N'); var rover = new MarsRover(plateau, coordinate, direction); rover.Move(); Assert.AreEqual("1 3 N", rover.GetCurrentLocation()); }
public void When_A_Rover_Facing_East_At_0_0_Is_Given_The_Command_B_And_An_Obstacle_Is_At_9_0_The_Rover_Should_Stay_At_0_0() { var rover = new MarsRover(new MarsWithObstacles(new[] { new Obstacle(9, 0) // Obstacle at (9, 0) })); rover.Move("R"); Assert.AreEqual("0, 0, E", rover.CurrentPosition); try { rover.Move("B"); } catch (ObstacleDetectedException) { } finally { Assert.AreEqual("0, 0, E", rover.CurrentPosition); } }
public void MovePositionByOneFromInitialPositionWhenMoveCommandCalled() { var initialPosition = new VectorWithHeading(2, 2, Heading.North); var plateau = new Plateau(5, 5); var marsRover = new MarsRover(initialPosition, plateau); marsRover.Move(); var result = marsRover.GetVectorWithHeading(); Assert.That(result, Is.EqualTo(new VectorWithHeading(2, 3, Heading.North))); }
public void Move_InvalidCommand_Error() { //Arrange Point startingPoint = new Point(0, 0); MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North; MarsRover rover = new MarsRover(startingPoint, startingDirection, null, null); //Act rover.Move(new[] { '?' }); //Assert Assert.AreEqual(RoverStatus.RoverStatusCode.Error, rover.Status.StatusCode); }
public void ReturnExpectedOutputOnSetSequenceofMovementCommands() { var initialPosition = new VectorWithHeading(1, 2, Heading.North); var expectedPosition = new VectorWithHeading(1, 3, Heading.North); var plateau = new Plateau(5, 5); var marsRover = new MarsRover(initialPosition, plateau); marsRover.TurnLeft(); marsRover.Move(); marsRover.TurnLeft(); marsRover.Move(); marsRover.TurnLeft(); marsRover.Move(); marsRover.TurnLeft(); marsRover.Move(); marsRover.Move(); var result = marsRover.GetVectorWithHeading(); Assert.That(result, Is.EqualTo(expectedPosition)); }
public void Move_AccordingToCommands() { int x = 5; int y = 5; string direction = "N"; int forward_amount = 3; int backward_amount = 1; MarsRover marsRover = new MarsRover(x, y, direction); string[] commands = { "F", "B", "F", "F" }; marsRover.Move(commands); Assert.AreEqual(y + (forward_amount - backward_amount), marsRover.Y); }
public void TurnRight_00N_00E() { //Arrange Point startingPoint = new Point(0, 0); MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North; MarsRover rover = new MarsRover(startingPoint, startingDirection); var moves = new[] { 'r' }; Point expectedCoordinates = new Point(0, 0); MarsRover.CardinalDirection expectedStartingDirection = MarsRover.CardinalDirection.East; //Act rover.Move(moves); //Assert Assert.AreEqual(expectedCoordinates, rover.Coordinates); Assert.AreEqual(expectedStartingDirection, rover.Direction); Assert.AreEqual(RoverStatus.RoverStatusCode.Ok, rover.Status.StatusCode); }
public void When_A_New_Rover_Is_Given_The_Command_F_And_An_Obstacle_Is_At_0_1_The_Rover_Should_Stay_At_0_0() { var rover = new MarsRover(new MarsWithObstacles(new[] { new Obstacle(0, 1) // Obstacle at (0, 1) })); Assert.AreEqual("0, 0, N", rover.CurrentPosition); try { rover.Move("F"); } catch (ObstacleDetectedException) { } finally { Assert.AreEqual("0, 0, N", rover.CurrentPosition); } }