public void ReturnInitialPositionWhenAnyCommandIsGiven()
        {
            //arrange
            var command  = string.Empty;
            var expected = "0:0:N";

            //act
            _marsRover.Execute(command);

            //assert
            Assert.Equal(expected, _marsRover.CurrentPosition);
        }
        public void ExecuteCommands(string initialState, string commands, string expectedFinalState)
        {
            var marsRover = new MarsRover(initialState);

            var result = marsRover.Execute(commands);

            result.Should().Be(expectedFinalState);
        }
        public void DontReportAnObstacleIfNotEncountered()
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(1, 1)
            };
            var grid      = new Grid(10, 10, obstacles);
            var marsRover = new MarsRover(grid);

            marsRover.Execute("MMMMRMMLMM").ShouldNotStartWith("O:");
        }
        public void ReportAnObstacleIfEncountered(string input, int x, int y, string output)
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(x, y), new Coordinate(10, 10)
            };
            var grid      = new Grid(10, 10, obstacles);
            var marsRover = new MarsRover(grid);

            marsRover.Execute(input).ShouldBe(output);
        }
Exemple #5
0
        public void StopBeforeAnObstacle(string command, string expectedOutput)
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(0, 3)
            };
            var gridWithObstacles = new MarsRoverGrid(10, 10, obstacles);
            var rover             = new MarsRover(gridWithObstacles);

            rover.Execute(command).ShouldBe(expectedOutput);
        }
Exemple #6
0
        public void DodgeMultipleObstacles(string command, string expectedOutput)
        {
            var obstacles = new List <Coordinate> {
                new Coordinate(0, 3),
                new Coordinate(3, 0),
                new Coordinate(0, 7),
                new Coordinate(7, 0)
            };
            var gridWithObstacles = new MarsRoverGrid(10, 10, obstacles);
            var rover             = new MarsRover(gridWithObstacles);

            rover.Execute(command).ShouldBe(expectedOutput);
        }
        public void Rotate(char direction, string instruction, char expectedDirection)
        {
            Position position = APosition()
                                .Facing(direction)
                                .Build();

            MarsRover rover = ARover()
                              .With(position)
                              .Build();

            MarsRover moved = rover.Execute(instruction);

            Position expectedPosition = APosition()
                                        .Facing(expectedDirection)
                                        .Build();

            Assert.Equal(expectedPosition, moved.Position);
        }
        public void MoveAgainstObstacle()
        {
            Position position = APosition()
                                .WithCoordinates(0, 0)
                                .WithGrid(10, new Coordinates(0, 1))
                                .Facing('N')
                                .Build();

            MarsRover rover = ARover()
                              .With(position)
                              .Build();

            MarsRover moved = rover.Execute("f");

            Position expectedPosition = position;

            Assert.Equal(expectedPosition, moved.Position);
        }
        public void Move(int x, int y, char direction, int gridSize, string instruction, int expectedX, int expectedY)
        {
            Position position = APosition()
                                .WithCoordinates(x, y)
                                .WithGridSize(gridSize)
                                .Facing(direction)
                                .Build();

            MarsRover rover = ARover()
                              .With(position)
                              .Build();

            MarsRover moved = rover.Execute(instruction);

            Position expectedPosition = APosition()
                                        .WithCoordinates(expectedX, expectedY)
                                        .WithGridSize(gridSize)
                                        .Facing(direction)
                                        .Build();

            Assert.Equal(expectedPosition, moved.Position);
        }
 public void TurnLeft(string input, string output)
 {
     _marsRover.Execute(input).ShouldBe(output);
 }
Exemple #11
0
 public void StartByFacingNorth()
 {
     _rover.Execute("").ShouldBe("0:0:N");
 }
        public void IfTheNextMovementIsOnAnObstacleDonNotMove()
        {
            var position = _marsRoverWithObstacleOnXZeroYOne.Execute("M");

            Assert.Equal("0:0:N", position);
        }
        public void MoveOnePositionForEachCompassDirection(string expectedPosition, string commands)
        {
            var position = _marsRoverWithStartNavigate.Execute(commands);

            Assert.Equal(expectedPosition, (string)position);
        }
        public void StayInPlaceGivenNoCommand()
        {
            var result = _marsRover.Execute(string.Empty);

            Assert.Equal((string)"0:0:N", (string)result);
        }