Пример #1
0
        public void Test_Rover_Can_Move_Forward_One_Square_When_Facing_West()
        {
            var startPosition = new Position { Direction = Direction.West, X = 1, Y = 0 };
            var rover = new Rover(startPosition);
            rover.MoveFoward();

            var newPosition = rover.GetCurrentPosition();
            var expectedPosition = new Position { Direction = Direction.West, X = 0, Y = 0 };

            Assert.AreEqual(newPosition, expectedPosition);
        }
Пример #2
0
        public void Test_Rover_Can_Rotate_90_Degrees(Direction startDirection, Rotation rotateDirection, Direction endDirection)
        {
            var startPosition = new Position { Direction = startDirection, X = 0, Y = 0 };
            var rover = new Rover(startPosition);

            rover.Rotate(rotateDirection);

            var newPosition = rover.GetCurrentPosition();
            var expectedPosition = new Position { Direction = endDirection, X = 0, Y = 0 };

            Assert.AreEqual(newPosition, expectedPosition);
        }
Пример #3
0
        public void Test_NavigationService_Moves_Rover_Correctly_Forward_Multiple_Square()
        {
            INavigationService service = new NavigationService();
            Plateau plateau = new Plateau(5, 5);
            List<Command> commands = new List<Command>();

            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);

            var startPosition = new Position { Direction = Direction.North, X = 0, Y = 0 };
            var expectedPosition = new Position { Direction = Direction.North, X = 0, Y = 5 };
            var rover = new Rover(startPosition);

            Position position = service.ExploreTerrain(plateau, rover, commands);
            Assert.AreEqual(position, expectedPosition);
        }
Пример #4
0
        public ActionResult AddRover(int x, int y, string direction, string movements)
        {
            var rovers = new List<RoverModel>();

            if(TempData["Rovers"] != null)
            {
                rovers = TempData["Rovers"] as List<RoverModel>;
            }

            var position = new Position {X = x, Y = y, Direction = DirectionParser.Parse(direction)};
            var rover = new Rover(position);
            if (rovers != null)
            {
                rovers.Add(new RoverModel {Movements = movements, Rover = rover});

                TempData["Rovers"] = ViewData.Model = rovers;
            }

            return new ViewResult {ViewName = "SubmitPlateau", ViewData = ViewData};
        }
Пример #5
0
        public Position ExploreTerrain(Plateau plateau, Rover rover, List<Command> commands)
        {
            /* Need to do some out of bounds validation here, hence I passed the plateau in, but it is not mentioned in the 'spec' */

            foreach (var command in commands)
            {
                switch(command)
                {
                    case Command.MoveForward:
                        rover.MoveFoward();
                        break;
                    case Command.TurnLeft:
                        rover.Rotate(Rotation.Left);
                        break;
                    case Command.TurnRight:
                        rover.Rotate(Rotation.Right);
                        break;
                }
            }

            return rover.GetCurrentPosition();
        }
Пример #6
0
        public void Test_NavigationService_Moves_Rover_Correctly_According_To_Supplied_Test_Data_Two()
        {
            INavigationService service = new NavigationService();
            Plateau plateau = new Plateau(5, 5);
            List<Command> commands = new List<Command>();

            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);
            commands.Add(Command.TurnRight);
            commands.Add(Command.MoveForward);
            commands.Add(Command.MoveForward);
            commands.Add(Command.TurnRight);
            commands.Add(Command.MoveForward);
            commands.Add(Command.TurnRight);
            commands.Add(Command.TurnRight);
            commands.Add(Command.MoveForward);

            var startPosition = new Position { Direction = Direction.East, X = 3, Y = 3 };
            var expectedPosition = new Position { Direction = Direction.East, X = 5, Y = 1 };
            var rover = new Rover(startPosition);

            Position position = service.ExploreTerrain(plateau, rover, commands);
            Assert.AreEqual(position, expectedPosition);
        }