示例#1
0
 public void Move_InMap()
 {
     rover.RoverDirection = Direction.E;
     rover.PosX           = 1;
     rover.PosY           = 2;
     rover.Move();
     Assert.AreEqual(2, rover.PosY);
     Assert.AreEqual(2, rover.PosX);
     Assert.AreEqual(Direction.E, rover.RoverDirection);
 }
示例#2
0
        static void WaitForInstructions(BaseRover rover)
        {
            try
            {
                var command = Console.ReadLine();
                if (Validator.ValidateMapCommand(command))
                {
                    // NASA can reset the rover's map
                    rover.Map = Map.Parse(command);
                    command   = Console.ReadLine();
                }

                if (Validator.ValidatePositionCommand(command))
                {
                    rover.CurrentPosition = Position.Parse(command);
                }
                else
                {
                    throw new ApplicationException(string.Format("Invalid position command [{0}]", command));
                }

                command = Console.ReadLine();
                if (Validator.ValidateMoveCommand(command))
                {
                    rover.Move(command);
                }
                else
                {
                    throw new ApplicationException(string.Format("Invalid move command [{0}]", command));
                }

                Console.WriteLine(rover.CurrentPosition.ToString());
                WaitForInstructions(rover);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                WaitForInstructions(rover);
            }
        }