Beispiel #1
0
        public void Should_not_create_a_plateau_and_return_error_message_if_format_is_incorrect()
        {
            const string plateauSize   = "A 5";
            var          plateauParser = new PlateauParser();

            plateauParser.Invoking(x => x.Parse(plateauSize)).Should().Throw <InvalidPlateauMeasurementsException>();
        }
        public void ParseAndExecuteCommands()
        {
            string[] inputByLines = cardonoCommand.Split(newLineDelimiter);

            if (inputByLines.Length % 2 == 0)
            {
                throw new InvalidEnumArgumentException("Unexpected number of lines in the cardano command");
            }

            Coordinates plateauUpperRightCoordinate = PlateauParser.ParsePlateauDimenstion(inputByLines[0]);
            Plateau     plateau = new Plateau(plateauUpperRightCoordinate);

            int lineIndex = 1;

            while (inputByLines.Length > lineIndex)
            {
                var roverPositionAndDirection = RoverPositionAndDirectionParser
                                                .ParseRoverPositionAndDirection(inputByLines[lineIndex]);

                MarsRover rover = new MarsRover(plateau,
                                                roverPositionAndDirection.Position,
                                                roverPositionAndDirection.Direction);
                lineIndex++;

                rover.ExecuteCommands(inputByLines[lineIndex]);
                lineIndex++;
                Console.WriteLine($"{rover.CurrentCoordinates.XCoordinate} {rover.CurrentCoordinates.YCoordinate} " +
                                  $"{rover.CurrentDirection.ToString()}");
            }
        }
 public void ShouldParseValidInput()
 {
     var parser = new PlateauParser();
     var result = parser.Parse("1 2");
     var expected = new Plateau(1, 2);
     result.Width.ShouldEqual(expected.Width);
     result.Height.ShouldEqual(expected.Height);
 }
        public void ShouldThrowExceptionWhenParseInvalidInput()
        {
            var parser = new PlateauParser();

            var result = Record.Exception(() => parser.Parse("A B"));

            result.ShouldBeType<ParserException>();
        }
Beispiel #5
0
        public void Should_receive_measurements_on_a_string_and_create_the_plateau()
        {
            const string plateauSize     = "3 5";
            var          plateauParser   = new PlateauParser();
            var          expectedPlateau = new Plateau(3, 5);

            var parsedPlateau = plateauParser.Parse(plateauSize);

            parsedPlateau.Should().BeEquivalentTo(expectedPlateau);
        }