Beispiel #1
0
        public void PositionDirection_Should_Be_True(string positionDirection)
        {
            // Act
            var result = _formatCheckService.PositionDirection(positionDirection);

            // Assert
            result.Should().BeTrue();
        }
Beispiel #2
0
        /// <summary>
        /// Get Position and Direction info from user.
        /// </summary>
        /// <param name="formatCheckService"></param>
        /// <param name="roverMovementService"></param>
        /// <param name="plateauAreaX"></param>
        /// <param name="plateauAreaY"></param>
        /// <param name="roverLocationX"></param>
        /// <param name="roverLocationY"></param>
        /// <param name="roverDirection"></param>
        /// <returns></returns>
        private static bool GetPositionDirection(IFormatCheckService formatCheckService, IRoverMovementService roverMovementService, int plateauAreaX, int plateauAreaY, out int roverLocationX, out int roverLocationY, out string roverDirection)
        {
            Console.WriteLine("Enter the rover position and direction: ");

            string positionDirection = Console.ReadLine()?.Trim();

            if (!formatCheckService.PositionDirection(positionDirection))
            {
                Console.WriteLine("Please write the rover position and direction correctly. For example: 5 5 N, N: North, E: East, S: South, W: West");
                roverLocationX = 0;
                roverLocationY = 0;
                roverDirection = null;
                return(true);
            }

            if (positionDirection == null)
            {
                roverLocationX = 0;
                roverLocationY = 0;
                roverDirection = null;
                return(true);
            }

            string[] positionDirectionArray = positionDirection.Split(" ");

            roverLocationX = int.Parse(positionDirectionArray[0]);
            roverLocationY = int.Parse(positionDirectionArray[1]);
            roverDirection = positionDirectionArray[2];

            if (!roverMovementService.IsRoverInThePlateau(roverLocationX, plateauAreaX, roverLocationY, plateauAreaY))
            {
                return(false);
            }

            Console.WriteLine("The rover is not in the plateau after instructions!!");
            return(true);
        }