示例#1
0
        public void MarsRoverTest_InitialPositionNotValidY_ExpectedArgumentException()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new Rover();

            rover.Initialize(1, -1, DirectionEnum.North, world);
        }
示例#2
0
        public void MarsServiceTest_MoveRover_Start_ObstacleDetected_ExpectedException()
        {
            IWorld world       = WorldBuilder.Get4x4WorldWithObstacles();
            var    marsService = Substitute.For <MarsService>(world);

            marsService.LandRover(0, 0, DirectionEnum.East);

            string[] commands = { "F", "L", "F" };

            Position position = marsService.MoveRover(commands);
        }
示例#3
0
        public void MarsServiceTest_LandRover_Position23DirE()
        {
            IWorld world       = WorldBuilder.GetDefault5x5World();
            var    marsService = Substitute.For <MarsService>(world);

            Position position = marsService.LandRover(2, 3, DirectionEnum.East);

            Assert.AreEqual(2, position.X);
            Assert.AreEqual(3, position.Y);
            Assert.AreEqual(DirectionEnum.East, position.Direction);
        }
示例#4
0
        public void MarsRoverTest_MoveLeft_ObstacleEncountred()
        {
            IWorld world = WorldBuilder.Get4x4WorldWithObstacles();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionNorth()
                          .WithInitialPosition(2, 2)
                          .Build();

            rover.MoveLeft();
        }
示例#5
0
        public void MarsRoverTest_InitializPosition0_0_E_InitialiPositionPoint0_0_Direction_E()
        {
            Rover rover = new Rover();

            IWorld world = WorldBuilder.GetDefault5x5World();

            rover.Initialize(0, 0, DirectionEnum.East, world);

            Assert.AreEqual(0, rover.Position.X);
            Assert.AreEqual(0, rover.Position.Y);
            Assert.AreEqual(DirectionEnum.East, rover.Position.Direction);
        }
示例#6
0
        public void MarsRoverTest_RightEdgeDirNorth_MoveRight_RoverStepInLeftEdge()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionNorth()
                          .WithInitialPosition(world.GetRightEdgeXCoordinates(), 3)
                          .Build();

            rover.MoveRight();
            Assert.AreEqual(world.GetLeftEdgeXCoordinates(), rover.Position.X);
        }
示例#7
0
        public void MarsRoverTest_TopEdgeDirWest_MoveRight_RoverStepInBottomEdge()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionWest()
                          .WithInitialPosition(0, world.GetTopEdgeYCoordinates())
                          .Build();

            rover.MoveRight();
            Assert.AreEqual(world.GetBottomEdgeYCoordinates(), rover.Position.Y);
        }
示例#8
0
        public void MarsServiceTest_MoveRoverFFRRLLBB_Start23E_End21E()
        {
            IWorld world       = WorldBuilder.GetDefault5x5World();
            var    marsService = Substitute.For <MarsService>(world);

            marsService.LandRover(2, 3, DirectionEnum.East);

            string[] commands = { "F", "F", "R", "R", "L", "L", "B", "B" };

            Position position = marsService.MoveRover(commands);

            Assert.AreEqual(2, position.X);
            Assert.AreEqual(1, position.Y);
            Assert.AreEqual(DirectionEnum.East, position.Direction);
        }
示例#9
0
        public void MarsRoverTest_InitialPosition00E_MoveForward_FinalPosition10E()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialStateLeftBottomEast()
                          .Build();

            rover.MoveForward();

            Assert.AreEqual(1, rover.Position.X);
            Assert.AreEqual(0, rover.Position.Y);
            Assert.AreEqual(DirectionEnum.East, rover.Position.Direction);
        }
示例#10
0
        public void MarsRoverTest_InitialPosition00N_MoveForward_FinalPosition01N()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialStateLeftBottomNorth()
                          .Build();

            rover.MoveForward();

            Assert.AreEqual(rover.Position.X, 0);
            Assert.AreEqual(rover.Position.Y, 1);
            Assert.AreEqual(rover.Position.Direction, DirectionEnum.North);
        }
示例#11
0
        public void MarsRoverTest_InitialPosition22S_MoveForward_FinalPosition21S()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionSouth()
                          .WithInitialPosition(2, 2)
                          .Build();

            rover.MoveForward();

            Assert.AreEqual(rover.Position.X, 2);
            Assert.AreEqual(rover.Position.Y, 1);
            Assert.AreEqual(rover.Position.Direction, DirectionEnum.South);
        }
示例#12
0
        public void MarsRoverTest_InitialPosition22E_MoveLeft_FinalPosition23N()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionEast()
                          .WithInitialPosition(2, 2)
                          .Build();

            rover.MoveLeft();

            Assert.AreEqual(rover.Position.X, 2);
            Assert.AreEqual(rover.Position.Y, 3);
            Assert.AreEqual(rover.Position.Direction, DirectionEnum.North);
        }
示例#13
0
        public void MarsRoverTest_InitialiPosition22South_MoveRight_FinalPosition12W()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionSouth()
                          .WithInitialPosition(2, 2)
                          .Build();

            rover.MoveRight();

            Assert.AreEqual(1, rover.Position.X);
            Assert.AreEqual(2, rover.Position.Y);
            Assert.AreEqual(DirectionEnum.West, rover.Position.Direction);
        }
示例#14
0
        public void MarsRoverTest_InitialPosition22W_MoveBackward_FinalPosition32W()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionWest()
                          .WithInitialPosition(2, 2)
                          .Build();

            rover.MoveBackward();

            Assert.AreEqual(rover.Position.X, 3);
            Assert.AreEqual(rover.Position.Y, 2);
            Assert.AreEqual(rover.Position.Direction, DirectionEnum.West);
        }
示例#15
0
        public void MarsRoverTest_InitialPosition11DirE_SendCommands_LRFFFFFLRLF_FinalPosition_20N()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Rover rover = new RoverBuilder()
                          .WithWorld(world)
                          .WithInitialDirectionEast()
                          .WithInitialPosition(1, 1)
                          .Build();

            string[] movements = { "L", "R", "F", "F", "F", "F", "L", "R", "L", "F" };


            rover.Move(movements);

            Assert.AreEqual(2, rover.Position.X);
            Assert.AreEqual(0, rover.Position.Y);
            Assert.AreEqual(DirectionEnum.North, rover.Position.Direction);
        }
示例#16
0
        public void MarsServiceTest_MoveRover_ObstacleDetected_LastPosition11N()
        {
            IWorld world       = WorldBuilder.Get4x4WorldWithObstacles();
            var    marsService = Substitute.For <MarsService>(world);

            marsService.LandRover(0, 0, DirectionEnum.East);

            string[] commands = { "F", "L", "F" };

            Position lastPosition = null;

            try
            {
                Position position = marsService.MoveRover(commands);
            }
            catch (RoverException ex)
            {
                lastPosition = ex.LastPosition;
            }

            Assert.AreEqual(1, lastPosition.X);
            Assert.AreEqual(1, lastPosition.Y);
            Assert.AreEqual(DirectionEnum.North, lastPosition.Direction);
        }
示例#17
0
        public void MarsServiceTest_CanInstantiate()
        {
            IWorld world = WorldBuilder.GetDefault5x5World();

            Assert.IsNotNull(new MarsService(world));
        }