public void RoverRoute_Should_Be_True(string dimension) { // Act var result = _formatCheckService.RoverRoute(dimension); // Assert result.Should().BeTrue(); }
/// <summary> /// Get Instructions of the rover from user. /// </summary> /// <param name="formatCheckService"></param> /// <param name="roverMovementService"></param> /// <param name="plateauAreaX"></param> /// <param name="plateauAreaY"></param> /// <param name="roverList"></param> /// <param name="roverDirection"></param> /// <param name="roverLocationX"></param> /// <param name="roverLocationY"></param> /// <returns></returns> private static bool GetInstructions(IFormatCheckService formatCheckService, IRoverMovementService roverMovementService, int plateauAreaX, int plateauAreaY, List <Rover> roverList, ref string roverDirection, ref int roverLocationX, ref int roverLocationY) { Console.WriteLine("Enter the rover instructions: "); string roverRoute = Console.ReadLine()?.Trim(); if (!formatCheckService.RoverRoute(roverRoute)) { Console.WriteLine("Please write the rover instructions correctly. For example: LMLMLMRM, L: Left, R: Right, M: Move"); return(true); } if (roverRoute == null) { return(true); } foreach (var route in roverRoute) { switch (route) { case 'L' or 'R': roverDirection = roverMovementService.CalculateDirection(roverDirection, route); break; case 'M': var result = roverMovementService.MoveRover(roverLocationX, roverLocationY, roverDirection); if (!roverMovementService.IsRoverInThePlateau(result.Item1, plateauAreaX, result.Item2, plateauAreaY) && !roverMovementService.CheckRoverPositions(roverList, result.Item1, result.Item2)) { roverLocationX = result.Item1; roverLocationY = result.Item2; } break; } } if (roverMovementService.IsRoverInThePlateau(roverLocationX, plateauAreaX, roverLocationY, plateauAreaY)) { Console.WriteLine("The rover is not in the plateau after instructions!!"); return(true); } if (!roverMovementService.CheckRoverPositions(roverList, roverLocationX, roverLocationY)) { return(false); } Console.WriteLine("Please change the instructions. Newly added rover in same location as another rover!!"); return(true); }