public void MoveFFRFF_Blocked()
        {
            //Arrange
            var start     = new Point();
            var grid      = new Point(10, 10);
            var obstacles = new ReadOnlyCollection <Point>(new List <Point>
            {
                new Point(0, 2)
            });
            var       terrain     = new PlanetaryTerrain(grid, obstacles);
            var       orientation = OrientationEnum.North;
            IMovement rover       = new PlutoRover(terrain, start, orientation);

            const string moveCommand      = "FFRFF";
            ILocation    expectedLocation = new LocationBlocked("", 0, 1, orientation);

            //Act
            ILocation newLocation = rover.Move(moveCommand);

            //Assert
            Assert.That(newLocation, Is.Not.Null);
            Assert.That(newLocation.X, Is.EqualTo(expectedLocation.X));
            Assert.That(newLocation.Y, Is.EqualTo(expectedLocation.Y));
            Assert.That(newLocation.Orientation, Is.EqualTo(expectedLocation.Orientation));
        }
        public void CanMoveAllAround_WhenCommandNotSupported_ShouldThrowException()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            //act
            rover.MakeCommand("MickeyMouse");
        }
 public PlutoRoverTests()
 {
     _mockObstaclesChecker = new Mock<ICheckObstacles>();
     _mockObstaclesChecker
         .Setup(x => x.ObstacleExist(It.IsAny<int>(), It.IsAny<int>()))
         .Returns(false);
     _plutoRover = new PlutoRover(_defaultPosition, _defaultGridWidth, _defaultGridHeight, _mockObstaclesChecker.Object);
 }
Beispiel #4
0
        public void ReceiveCommand_MoveOffGrid_West()
        {
            Planet     planet = new Planet(10, 10);
            PlutoRover rover  = new PlutoRover(new Position(0, 3, Orientation.W));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.F);
            Assert.AreEqual(rover.GetPosition(), new Position(9, 3, Orientation.W));
        }
Beispiel #5
0
        public void CanMoveBackwars_WhenAt00FacingEast_CoordinateXEquals99()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.East);

            //act
            rover.MakeCommand("B");
            //assert
            Assert.AreEqual(Convert.ToUInt32(99), rover.CoordinateX);
        }
Beispiel #6
0
        public void CanMoveForward_WhenAtEdgeFacingNorth_CoordinateYEquals0()
        {
            // arrange
            var rover = new PlutoRover(PlutoRover.SURFACE_SIZE - 1, PlutoRover.SURFACE_SIZE - 1, CardinalDirection.North);

            //act
            rover.MakeCommand("F");
            //assert
            Assert.AreEqual(Convert.ToUInt32(0), rover.CoordinateY);
        }
Beispiel #7
0
        public void CanMoveBackWardOneField()
        {
            // arrange
            var rover = new PlutoRover(0, 1, CardinalDirection.North);

            //act
            rover.MakeCommand("B");
            //assert
            Assert.AreEqual("00North", rover.GetRoverCoordinatesAndDirection());
        }
        public void ExecuteCommands_WhenRotateRightCommand_TheRoverRotatesRight(int x, int y, Direction start_dir, Direction end_dir)
        {
            _plutoRover = new PlutoRover(x, y, start_dir, _defaultGridWidth, _defaultGridHeight, _mockObstaclesChecker.Object);

            _plutoRover.ExecuteCommands("R");

            Assert.Equal(x, _plutoRover.Position.X);
            Assert.Equal(y, _plutoRover.Position.Y);
            Assert.Equal(end_dir, _plutoRover.Position.Direction);
        }
        public void ExecuteCommands_WhenMoveBackwardCommand_TheRoverMovesBackward(int start_x, int start_y, Direction direction, int end_x, int end_y)
        {
            _plutoRover = new PlutoRover(start_x, start_y, direction, _defaultGridWidth, _defaultGridHeight, _mockObstaclesChecker.Object);

            _plutoRover.ExecuteCommands("B");

            Assert.Equal(end_x, _plutoRover.Position.X);
            Assert.Equal(end_y, _plutoRover.Position.Y);
            Assert.Equal(direction, _plutoRover.Position.Direction);
        }
        public void CanMoveAndRotateAllAround()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            //act
            rover.MakeCommand("FFRFF");
            //assert
            Assert.AreEqual("22East", rover.GetRoverCoordinatesAndDirection());
        }
Beispiel #11
0
        public void CanRotateLeft_WhenDirectionIsNorth_OrientationShouldBeEast()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            //act
            rover.MakeCommand("L");
            //assert
            Assert.AreEqual(CardinalDirection.West, rover.RoverDirection);
        }
Beispiel #12
0
        public void CanRotateFullCounterClockWise_WhenDirectionIsNorth_OrientationShouldBeNorth()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            //act
            rover.MakeCommand("LLLL");
            //assert
            Assert.AreEqual(CardinalDirection.North, rover.RoverDirection);
        }
Beispiel #13
0
        public void ReceiveCommand_Forward_FaceEast()
        {
            Planet     planet = new Planet();
            PlutoRover rover  = new PlutoRover(new Position(4, 4, Orientation.E));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.F);
            Assert.IsTrue(rover.GetPosition() == (new Position(5, 4, Orientation.E)));
            rover.ProcessCommand(PlutoCommand.B);
            Assert.IsTrue(rover.GetPosition().Equals(new Position(4, 4, Orientation.E)));
        }
Beispiel #14
0
        public void ReceiveCommand_Forward_FaceWest()
        {
            Planet     planet = new Planet();
            PlutoRover rover  = new PlutoRover(new Position(4, 4, Orientation.W));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.F);
            Assert.AreEqual(rover.GetPosition(), new Position(3, 4, Orientation.W));
            rover.ProcessCommand(PlutoCommand.B);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.W));
        }
        public void TryMoveOneField_WhenObstacleOnThatField_ShouldReportIt()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            rover.Surface[0, 1] = 1;
            //act
            rover.MakeCommand("F");
            //assert
            Assert.AreEqual("00North", rover.GetRoverCoordinatesAndDirection());
            Assert.IsTrue(rover.ObstacleDetected);
        }
        public void TryMoveTwoField_WhenObstacleOnSecondField_CanMoveOneFieldAndReportObstacle()
        {
            // arrange
            var rover = new PlutoRover(0, 0, CardinalDirection.North);

            rover.Surface[0, 2] = 1;
            //act
            rover.MakeCommand("FF");
            //assert
            Assert.AreEqual("01North", rover.GetRoverCoordinatesAndDirection());
            Assert.IsTrue(rover.ObstacleDetected);
        }
Beispiel #17
0
        public void ReceiveCommand_Obstacle_FaceSouth()
        {
            Planet planet = new Planet();
            Rock   rock   = new Rock(new Position(4, 3, Orientation.N));

            planet.AddObject(rock);
            PlutoRover rover = new PlutoRover(new Position(4, 4, Orientation.S));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.F);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.S));
        }
Beispiel #18
0
        public void ReceiveCommand_Obstacle_FaceEast()
        {
            Planet planet = new Planet();
            Rock   rock   = new Rock(new Position(5, 4, Orientation.N));

            planet.AddObject(rock);
            PlutoRover rover = new PlutoRover(new Position(4, 4, Orientation.E));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.F);
            Assert.IsTrue(rover.GetPosition() == (new Position(4, 4, Orientation.E)));
        }
Beispiel #19
0
        public void When_ThereIsAnObstacleInTheWay_Expect_StopAtTheObstacle()
        {
            // Arrange
            var pluto = new Pluto(100, 100, new [] { new Location(0, 2) });
            var rover = new PlutoRover(pluto, new Position(new Location(0, 0), Orientation.N));

            // Act
            rover.Move("FF");

            // Assert
            rover.Position.ToString()
            .Should().Be("0,1,N");
        }
Beispiel #20
0
        public void When_ThereAreNoObstaclesInTheWay_Expect_ReportNone()
        {
            // Arrange
            var pluto = new Pluto(100, 100);
            var rover = new PlutoRover(pluto, new Position(new Location(0, 0), Orientation.N));

            // Act
            rover.Move("FF");

            // Assert
            // Note: not using Fluent assertion (.Should().Be(...)) - it is not compatible with the Option type
            Assert.Equal(rover.ObstacleInTheWay, Option.None <Location>());
        }
Beispiel #21
0
        public void When_ThereIsAnObstacleInTheWay_Expect_ReportTheObstacleLocation()
        {
            // Arrange
            var obstacleLocation = new Location(0, 2);
            var pluto            = new Pluto(100, 100, new [] { obstacleLocation });
            var rover            = new PlutoRover(pluto, new Position(new Location(0, 0), Orientation.N));

            // Act
            rover.Move("FF");

            // Assert
            // Note: not using Fluent assertion (.Should().Be(...)) - it is not compatible with the Option type
            Assert.Equal(rover.ObstacleInTheWay, Option.Some(obstacleLocation));
        }
Beispiel #22
0
        private void RunCommand(
            string initialPosition,
            string command,
            string expectedFinalPosition,
            int plutoWidth  = 100,
            int plutoHeight = 100)
        {
            // Arrange
            var pluto = new Pluto(plutoWidth, plutoHeight);
            var rover = new PlutoRover(pluto, new Position(initialPosition));

            // Act
            rover.Move(command);

            // Assert
            rover.Position.ToString()
            .Should().Be(expectedFinalPosition);
        }
Beispiel #23
0
        public void ReceiveCommand_MultipleCommands()
        {
            Planet     planet = new Planet();
            PlutoRover rover  = new PlutoRover(new Position(4, 4, Orientation.N));

            planet.AddObject(rover);
            var commands = new List <PlutoCommand>()
            {
                PlutoCommand.F,
                PlutoCommand.F,
                PlutoCommand.R,
                PlutoCommand.F,
                PlutoCommand.F
            };
            MovementReport report = rover.ProcessCommands(commands);

            Assert.AreEqual(rover.GetPosition(), new Position(6, 6, Orientation.E));
            Assert.IsTrue(report.Success);
        }
        public void MoveFFRFF_RequirementsExample()
        {
            //Arrange
            var       start       = new Point();
            var       grid        = new Point(100, 100);
            var       terrain     = new PlanetaryTerrain(grid, new ImmutableArray <Point>());
            var       orientation = OrientationEnum.North;
            IMovement rover       = new PlutoRover(terrain, start, orientation);

            const string moveCommand      = "FFRFF";
            ILocation    expectedLocation = new Location(2, 2, OrientationEnum.East);

            //Act
            ILocation newLocation = rover.Move(moveCommand);

            //Assert
            Assert.That(newLocation, Is.Not.Null);
            Assert.That(newLocation.X, Is.EqualTo(expectedLocation.X));
            Assert.That(newLocation.Y, Is.EqualTo(expectedLocation.Y));
            Assert.That(newLocation.Orientation, Is.EqualTo(expectedLocation.Orientation));
        }
Beispiel #25
0
        public void MoveForward_StartAtGridBoundary_OrientatedEast_WrapAround()
        {
            //Arrange
            var       grid        = new Point(10, 10);
            var       start       = new Point(grid.X, PlutoRover.ROOT_Y);
            var       terrain     = new PlanetaryTerrain(grid, new ImmutableArray <Point>());
            var       orientation = OrientationEnum.East;
            IMovement rover       = new PlutoRover(terrain, start, orientation);

            const string moveCommand      = Movement.Forwards;
            ILocation    expectedLocation = new Location(PlutoRover.ROOT_X, start.Y, orientation);

            //Act
            ILocation newLocation = rover.Move(moveCommand);

            //Assert
            Assert.That(newLocation, Is.Not.Null);
            Assert.That(newLocation.X, Is.EqualTo(expectedLocation.X));
            Assert.That(newLocation.Y, Is.EqualTo(expectedLocation.Y));
            Assert.That(newLocation.Orientation, Is.EqualTo(expectedLocation.Orientation));
        }
Beispiel #26
0
        public void TurnRight_OrientatedNorth()
        {
            //Arrange
            var       start       = new Point();
            var       grid        = new Point(10, 10);
            var       terrain     = new PlanetaryTerrain(grid, new ImmutableArray <Point>());
            var       orientation = OrientationEnum.North;
            IMovement rover       = new PlutoRover(terrain, start, orientation);

            const string moveCommand      = Movement.TurnRight;
            ILocation    expectedLocation = new Location(start.X, start.Y, OrientationEnum.East);

            //Act
            ILocation newLocation = rover.Move(moveCommand);

            //Assert
            Assert.That(newLocation, Is.Not.Null);
            Assert.That(newLocation.X, Is.EqualTo(expectedLocation.X));
            Assert.That(newLocation.Y, Is.EqualTo(expectedLocation.Y));
            Assert.That(newLocation.Orientation, Is.EqualTo(expectedLocation.Orientation));
        }
Beispiel #27
0
        public void ReceiveCommand_Turning()
        {
            Planet     planet = new Planet();
            PlutoRover rover  = new PlutoRover(new Position(4, 4, Orientation.N));

            planet.AddObject(rover);
            rover.ProcessCommand(PlutoCommand.L);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.W));
            rover.ProcessCommand(PlutoCommand.L);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.S));
            rover.ProcessCommand(PlutoCommand.L);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.E));
            rover.ProcessCommand(PlutoCommand.L);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.N));
            rover.ProcessCommand(PlutoCommand.R);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.E));
            rover.ProcessCommand(PlutoCommand.R);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.S));
            rover.ProcessCommand(PlutoCommand.R);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.W));
            rover.ProcessCommand(PlutoCommand.R);
            Assert.AreEqual(rover.GetPosition(), new Position(4, 4, Orientation.N));
        }
Beispiel #28
0
        public void ReceiveCommand_MultipleCommandsAndObstruction()
        {
            Planet planet = new Planet();
            Rock   rock   = new Rock(new Position(6, 6, Orientation.N));

            planet.AddObject(rock);
            PlutoRover rover = new PlutoRover(new Position(4, 4, Orientation.N));

            planet.AddObject(rover);
            var commands = new List <PlutoCommand>()
            {
                PlutoCommand.F,
                PlutoCommand.F,
                PlutoCommand.R,
                PlutoCommand.F,
                PlutoCommand.F
            };
            MovementReport report = rover.ProcessCommands(commands);

            Assert.AreEqual(rover.GetPosition(), new Position(5, 6, Orientation.E));
            Assert.IsFalse(report.Success);
            Assert.IsTrue(object.ReferenceEquals(rock, report.Obstructions[0]));
        }
        public void ExecuteCommands_WhenRoverFindsAnObstacle_TheRoverReportsAFailure(
            int start_x, int start_y, Direction direction, int obstacle_x, int obstacle_y, string cmd)
        {
            SetupObstacle(obstacle_x, obstacle_y);
            _plutoRover = new PlutoRover(start_x, start_y, direction, _defaultGridWidth, _defaultGridHeight, _mockObstaclesChecker.Object);

            var result = _plutoRover.ExecuteCommands(cmd);

            Assert.Equal(Status.Failure, result.Status);
        }
        public void ExecuteCommands_WhenMoveBackwardCommandOverTheGridLimit_TheRoverWrapsAround(
            int start_x, int start_y, int gridWidth, int gridHeight, Direction direction, int end_x, int end_y)
        {
            _plutoRover = new PlutoRover(start_x, start_y, direction, gridWidth, gridHeight, _mockObstaclesChecker.Object);

            _plutoRover.ExecuteCommands("B");

            Assert.Equal(end_x, _plutoRover.Position.X);
            Assert.Equal(end_y, _plutoRover.Position.Y);
            Assert.Equal(direction, _plutoRover.Position.Direction);
        }
 public PlutoRoverTests()
 {
     _gridServiceMock = new Mock <IGridService>();
     _rover           = new(_gridServiceMock.Object);
 }
Beispiel #32
0
 public void SetUp()
 {
     rover = new PlutoRover(
                 new RoverState { Facing = Facing.North, X = 0, Y = 0 },
                 100,
                 100,
                 new List<Tuple<int,int>> { new Tuple<int, int> (5,5),
                                            new Tuple<int, int> (5,7) });
 }