public void Move_Always_PerformsExpectedWork(string command, int expectedInvocationCount)
        {
            _gridServiceMock.Setup(x => x.CanMove(It.IsAny <Point>(), It.IsAny <string>(), It.IsAny <char>()))
            .Returns(true);

            var newPoint = new Point(1, 1);

            _gridServiceMock.Setup(x => x.CalculatePosition(It.IsAny <Point>(), It.IsAny <string>(), It.IsAny <char>()))
            .Returns(newPoint);

            _rover.Move(command);

            _gridServiceMock.Verify(x => x.CalculatePosition(It.IsAny <Point>(), It.IsAny <string>(), It.IsAny <char>()), Times.Exactly(expectedInvocationCount));
            Assert.Equal(newPoint, _rover.Position);
        }
        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));
        }
Exemple #3
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>());
        }
Exemple #4
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");
        }
Exemple #5
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));
        }
Exemple #6
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);
        }
Exemple #7
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));
        }
Exemple #8
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));
        }
        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));
        }