Example #1
0
        public string CalculateLastPositions(string inputAsString)
        {
            var input  = RoverMovementCalculatorInput.CreateFromInputFormat(inputAsString);
            var output = input.RoverPositionAndControlSignals
                         .Select(x => x.RoverPosition.CalculateLastPosition(x.RoverControlSignals))
                         .Select(lastPosition => $"{lastPosition.X} {lastPosition.Y} {lastPosition.Heading.ToShortCode()}")
                         .Aggregate((result, item) => $"{result}{Environment.NewLine}{item}");

            return(output);
        }
        public void RoverMovementCalculatorInput_Should_Be_Created_From_Input_Format(
            string inputFormat,
            Position upRightCoordinateOfPlateau,
            RoverPosition firstRoverPosition,
            RoverControlSignal[] firstRoverControlSignal)
        {
            var input = RoverMovementCalculatorInput.CreateFromInputFormat(inputFormat);

            input.UpRightCoordinateOfPlateau.X.ShouldBe(upRightCoordinateOfPlateau.X);
            input.UpRightCoordinateOfPlateau.Y.ShouldBe(upRightCoordinateOfPlateau.Y);

            var positionAndSignal = input.RoverPositionAndControlSignals.First();

            positionAndSignal.RoverPosition.Heading.ShouldBe(firstRoverPosition.Heading);
            positionAndSignal.RoverPosition.X.ShouldBe(firstRoverPosition.X);
            positionAndSignal.RoverPosition.Y.ShouldBe(firstRoverPosition.Y);

            positionAndSignal.RoverControlSignals.ShouldBe(firstRoverControlSignal);
        }