Пример #1
0
        public ActionResult Index(string command)
        {
            string[] commandLines;
            string roversPosition, roversInstruction, result = null;

            if (!String.IsNullOrEmpty(command))
            {
                Plateau plateau = null;
                command = command.Trim().Replace("\r\n", ",");
                commandLines = command.Split(',');

                if (commandLines.Length > 0) {
                    plateau = DefiningPlateauSize(commandLines[0]);
                }

                for (int i = 1; i < commandLines.Length; i = i + 2)
                {
                    roversPosition = commandLines[i];
                    roversInstruction = commandLines[i + 1];

                    string[] roversPositionSplitted = roversPosition.Split(' ');

                    try
                    {
                        Rover rover = new Rover(
                        Convert.ToInt32(roversPositionSplitted[0]),
                        Convert.ToInt32(roversPositionSplitted[1]),
                        (CardinalCompass)Convert.ToChar(roversPositionSplitted[2]));

                        result = result + "\r\n" + rover.SetCommands(roversInstruction, plateau);
                    }
                    catch (Exception exception)
                    {
                        result = exception.Message;
                    }
                }

                @ViewBag.Result = result;
            }

            return View();
        }
Пример #2
0
 private void ThenIExpectARoverOnThePosition(Rover rover, int x, int y, CardinalCompass cardinal)
 {
     Assert.AreEqual(rover.PointX, x);
     Assert.AreEqual(rover.PointY, y);
     Assert.AreEqual(rover.CardinalCompass, cardinal);
 }
Пример #3
0
 private void WhenACommandIsExecuted(Rover rover, string command)
 {
     rover.SetCommands(command, PlateauFeature.GivenAPlateau(5, 5));
 }
Пример #4
0
 private void ThenIExpectARover(Rover rover, int expectedX, int expectedY, CardinalCompass expectedCardinalCompass)
 {
     Assert.IsNotNull(rover);
     Assert.AreEqual(rover.PointX, expectedX);
     Assert.AreEqual(rover.PointY, expectedY);
     Assert.AreEqual(rover.CardinalCompass, expectedCardinalCompass);
 }