private static void Main() { string[] input = { "1", "2", "N", "LMLMLMLMM", "3", "3", "E", "MMRMMRMRRM" }; var serviceProvider = CreateContainerBuilder(); var plateau = serviceProvider.GetService <IPlateau>(); plateau.SetCoordinate(new Coordinate(5, 5)); for (var i = 0; i < input.Length - 1; i += 4) { var rover = serviceProvider.GetService <IRover>(); var initCoordinate = new Coordinate(Convert.ToInt32(input[i]), Convert.ToInt32(input[i + 1])); Enum.TryParse(input[i + 2], out DirectionType initDirection); rover.SetCoordinate(initCoordinate); rover.SetDirection(initDirection); // Interpreter Pattern var instruction = input[i + 3]; var context = new Context(instruction, rover); RoverRunner.RunExpression(context); } Console.ReadKey(); }
public void RoverRunner_RunWithInValidInstruction_ShouldBeThrowEx() { var instruction = "BLMMRMMM"; var direction = DirectionType.N; var coordinate = new Coordinate(4, 1); _rover.SetCoordinate(coordinate); _rover.SetDirection(direction); var context = new Context(instruction, _rover); Assert.Throws <Exception>(() => RoverRunner.RunExpression(context)); }
public void RoverRunner_RunWithValidInstruction_ShouldBeSuccess() { var instruction = "LMMRMMM"; var direction = DirectionType.N; var coordinate = new Coordinate(2, 1); _rover.SetCoordinate(coordinate); _rover.SetDirection(direction); var context = new Context(instruction, _rover); RoverRunner.RunExpression(context); var result = _rover.GetCurrentPosition(); result.Should().NotBeNullOrEmpty(); result.Should().Be("0 4 N"); }