Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("__Test Input:__");
            Console.WriteLine();

            var plateau = new Plataeu();

            plateau.Define("5 5");
            Console.WriteLine(plateau.ToString());

            var roverFirst = new Rover(plateau, "1 2 N");

            Console.WriteLine(roverFirst.StartPosition.ToString());
            roverFirst.SetControlCommands("LMLMLMLMM");
            Console.WriteLine(roverFirst.ControlsString);
            roverFirst.Deploy();

            var roverSecond = new Rover(plateau, "3 3 E");

            Console.WriteLine(roverSecond.StartPosition.ToString());
            roverSecond.SetControlCommands("MMRMMRMRRM");
            Console.WriteLine(roverSecond.ControlsString);
            roverSecond.Deploy();

            Console.WriteLine();
            Console.WriteLine("__Expected Output:__");
            Console.WriteLine();
            Console.WriteLine(roverFirst.ToString());
            Console.WriteLine(roverSecond.ToString());
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 2
0
 public void Asks_if_deploy_point_is_valid_for_landing_surface()
 {
     var aPoint = new Point(0, 0);
     mockLandingSurface.Setup(x => x.IsValid(aPoint)).Returns(true);
     var rover = new Rover();
     rover.Deploy(mockLandingSurface.Object, aPoint, CardinalDirection.South);
     mockLandingSurface.Verify(x => x.IsValid(aPoint), Times.Once());
 }
Exemplo n.º 3
0
        public void WhenRoverDeployedToGivenCoordinates_ThenShouldThrowException(string startCommand, string controlCommand)
        {
            var rover = new Rover(plateau, startCommand);

            rover.SetControlCommands(controlCommand);

            Assert.Throws <RoverOutsidePlateauException>(() => rover.Deploy());
        }
Exemplo n.º 4
0
        public void WhenCreatedRoverToGivenCoordinates_ThenShouldDeployed(string startCommand, string controlCommand, string result)
        {
            var rover = new Rover(plateau, startCommand);

            rover.SetControlCommands(controlCommand);
            rover.Deploy();

            Assert.Equal(result, rover.ToString());
        }
Exemplo n.º 5
0
            public void Asks_if_deploy_point_is_valid_for_landing_surface()
            {
                var aPoint = new Point(0, 0);

                mockLandingSurface.Setup(x => x.IsValid(aPoint)).Returns(true);
                var rover = new Rover();

                rover.Deploy(mockLandingSurface.Object, aPoint, CardinalDirection.South);
                mockLandingSurface.Verify(x => x.IsValid(aPoint), Times.Once());
            }
Exemplo n.º 6
0
            public void Given_valid_deploy_point_and_direction_exposes_as_properties(int expectedX, int expectedY, CardinalDirection expectedCardinalDirection)
            {
                var expectedPoint = new Point(expectedX, expectedY);
                mockLandingSurface.Setup(x => x.IsValid(expectedPoint)).Returns(true);

                var rover = new Rover();
                rover.Deploy(mockLandingSurface.Object, expectedPoint, expectedCardinalDirection);

                Assert.AreEqual(expectedPoint, rover.Position);
                Assert.AreEqual(expectedCardinalDirection, rover.CardinalDirection);
            }
Exemplo n.º 7
0
        public void Deploy_33E_Should_33E()
        {
            // arrange
            var rover = new Rover(plateau);

            // act
            rover.Deploy("3 3 E", plateau.XMax, plateau.YMax, plateau.XMin, plateau.YMin);

            // assert
            Assert.Equal("3 3 E", rover.PositionResult());
        }
Exemplo n.º 8
0
            public void Given_invalid_deploy_point_throws_RoverDeployException()
            {
                var aPoint = new Point(0, 0);
                var aSize = new Size(0, 0);

                mockLandingSurface.Setup(x => x.IsValid(aPoint)).Returns(false);
                mockLandingSurface.Setup(x => x.GetSize()).Returns(aSize);
                var rover = new Rover();

                Assert.Throws<RoverDeployException>(() =>
                    rover.Deploy(mockLandingSurface.Object, aPoint, CardinalDirection.West));
            }
Exemplo n.º 9
0
            public void Given_invalid_deploy_point_throws_RoverDeployException()
            {
                var aPoint = new Point(0, 0);
                var aSize  = new Size(0, 0);

                mockLandingSurface.Setup(x => x.IsValid(aPoint)).Returns(false);
                mockLandingSurface.Setup(x => x.GetSize()).Returns(aSize);
                var rover = new Rover();

                Assert.Throws <RoverDeployException>(() =>
                                                     rover.Deploy(mockLandingSurface.Object, aPoint, CardinalDirection.West));
            }
Exemplo n.º 10
0
            public void Given_valid_deploy_point_and_direction_exposes_as_properties(int expectedX, int expectedY, CardinalDirection expectedCardinalDirection)
            {
                var expectedPoint = new Point(expectedX, expectedY);

                mockLandingSurface.Setup(x => x.IsValid(expectedPoint)).Returns(true);

                var rover = new Rover();

                rover.Deploy(mockLandingSurface.Object, expectedPoint, expectedCardinalDirection);

                Assert.AreEqual(expectedPoint, rover.Position);
                Assert.AreEqual(expectedCardinalDirection, rover.CardinalDirection);
            }
Exemplo n.º 11
0
            public void After_Rover_has_been_deployed_returns_true()
            {
                var point = new Point(0, 0);

                mockLandingSurface.Setup(x => x.IsValid(point)).Returns(true);
                var rover = new Rover();

                rover.Deploy(mockLandingSurface.Object, point, CardinalDirection.North);

                var isDeployed = rover.IsDeployed();

                Assert.That(isDeployed);
            }
Exemplo n.º 12
0
        public void Deploy_14E_ShouldTrowExcepiton()
        {
            // arrange
            var rover = new Rover(plateau);

            // act
            Action act = () => rover.Deploy("-1 4 E", plateau.XMax, plateau.YMax, plateau.XMin, plateau.YMin);

            //assert
            PositionException exception = Assert.Throws <PositionException>(act);

            Assert.Equal("Rover X coordinate lower from plateau xMin coordinate", exception.Message);
        }
Exemplo n.º 13
0
        public void Deploy_36E_ShouldThrowException()
        {
            // arrange
            var rover = new Rover(plateau);

            // act
            Action act = () => rover.Deploy("3 6 E", plateau.XMax, plateau.YMax, plateau.XMin, plateau.YMin);

            //assert
            PositionException exception = Assert.Throws <PositionException>(act);

            Assert.Equal("Rover Y coordinate higher from plateau yMax coordinate", exception.Message);
        }
Exemplo n.º 14
0
            public void Alters_position_and_direction_in_response_to_movement_list(int startX, int startY,
                                                                                   CardinalDirection startDirection, Movement firstMove, Movement secondMove, Movement thirdMove,
                                                                                   int expectedX, int expectedY, CardinalDirection expectedDirection)
            {
                var startPosition    = new Point(startX, startY);
                var expectedPosition = new Point(expectedX, expectedY);
                var movements        = new List <Movement> {
                    firstMove, secondMove, thirdMove
                };

                var mockLandingSurface = new Mock <ILandingSurface>();

                mockLandingSurface.Setup(x => x.IsValid(startPosition)).Returns(true);

                var rover = new Rover();

                rover.Deploy(mockLandingSurface.Object, startPosition, startDirection);
                rover.Move(movements);

                Assert.AreEqual(expectedPosition.X, rover.Position.X);
                Assert.AreEqual(expectedPosition.Y, rover.Position.Y);
                Assert.AreEqual(expectedDirection, rover.CardinalDirection);
            }
Exemplo n.º 15
0
            public void After_Rover_has_been_deployed_returns_true()
            {
                var point = new Point(0, 0);
                mockLandingSurface.Setup(x => x.IsValid(point)).Returns(true);
                var rover = new Rover();
                rover.Deploy(mockLandingSurface.Object, point, CardinalDirection.North);

                var isDeployed = rover.IsDeployed();

                Assert.That(isDeployed);
            }
Exemplo n.º 16
0
            public void Alters_position_and_direction_in_response_to_movement_list(int startX, int startY, 
                CardinalDirection startDirection, Movement firstMove, Movement secondMove, Movement thirdMove, 
                int expectedX, int expectedY, CardinalDirection expectedDirection)
            {
                var startPosition = new Point(startX, startY);
                var expectedPosition = new Point(expectedX, expectedY);
                var movements = new List<Movement> {firstMove, secondMove, thirdMove};

                var mockLandingSurface = new Mock<ILandingSurface>();
                mockLandingSurface.Setup(x => x.IsValid(startPosition)).Returns(true);

                var rover = new Rover();
                rover.Deploy(mockLandingSurface.Object, startPosition, startDirection);
                rover.Move(movements);

                Assert.AreEqual(expectedPosition.X, rover.Position.X);
                Assert.AreEqual(expectedPosition.Y, rover.Position.Y);
                Assert.AreEqual(expectedDirection, rover.CardinalDirection);
            }