Пример #1
0
        static async Task Start()
        {
            try
            {
                System.Console.WriteLine("Welcome to plateau on Mars.");

                RoverInvoker roverInvoker = RoverInvoker.Create <RoboticRover>();

                #region CreatePlateauArea

                System.Console.WriteLine("Please enter the plateau area such as 5 5");

                var plateauAreaValue = System.Console.ReadLine();

                await roverInvoker.CreatePlateauArea(plateauAreaValue);

                System.Console.WriteLine("Plateau area is configured succesfully.");

                #endregion CreatePlateauArea

                #region SetLocation

                System.Console.WriteLine("Please enter rover start location such as : 1 2 N");

                var roverLocationValue = System.Console.ReadLine();
                await roverInvoker.SetRoverLocation(roverLocationValue);

                System.Console.WriteLine("Rover start location is configured succesfully.");

                #endregion SetLocation

                #region ExecuteMovement

                System.Console.WriteLine("Please enter movement Instruction such as : LMLMLMLMM");

                var movementValue = System.Console.ReadLine();

                await roverInvoker.ExecuteMovement(movementValue);

                System.Console.WriteLine("Rover moved");

                #endregion ExecuteMovement

                System.Console.WriteLine("Your rover current location");

                RoverLocation roverLocation = await roverInvoker.GetRoverLocation();

                System.Console.WriteLine($"{roverLocation.X} {roverLocation.Y} {(char)roverLocation.Direction}");
            }
            catch (MarsRoverException rex)
            {
                System.Console.WriteLine("Invalid Command. " + rex.Message);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("MarsRover has unknown error : " + ex.Message);
            }
        }
        public async Task SetRoverLocation()
        {
            await _roverInvoker.SetRoverLocation("1 2 N");

            RoverLocation roverLocation = await _roverInvoker.GetRoverLocation();

            Assert.IsNotNull(roverLocation);
            Assert.AreNotSame(roverLocation.Direction, Direction.Unknown);
            Assert.IsTrue(roverLocation.X >= 0);
            Assert.IsTrue(roverLocation.Y >= 0);
        }
Пример #3
0
        public async Task ExecuteMovement()
        {
            await _roverInvoker.ExecuteMovement("LMLMLMLMM");

            RoverLocation roverLocation = await _roverInvoker.GetRoverLocation();

            Assert.IsNotNull(roverLocation);
            Assert.AreNotSame(roverLocation.Direction, Direction.Unknown);
            Assert.IsTrue(roverLocation.X >= 0);
            Assert.IsTrue(roverLocation.Y >= 0);
        }