Example #1
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);
        }
        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();
        }
Example #3
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);
        }
 /* I assumed that you were more interested in how I structured the main logic, than the view Logic. Hence:
 *  Needs lots of validation, null reference checking ect, but as I only have one hour lets just keep it very simple.
 * Also, I would not normally use TempData, but it is a versy simple abstraction that saves me having to wire up databses in a short space of time. */
 public ActionResult SubmitPlateau(int height, int width)
 {
     TempData["Plateau"] = new Plateau(width, height);
     ViewData.Model = new List<RoverModel>();
     return View();
 }