コード例 #1
0
        public void TestReadTwoLinesOfInstructions3rdInput()
        {
            var service = new InstructionReaderService();

            _ = service.ReadTwoLinesOfInstructions("2 3 E", "LRLRLRLRLR");
            _ = service.ReadTwoLinesOfInstructions("2 3 E", "RRRRLLLLMMMMM");
            var result = service.ReadTwoLinesOfInstructions("2 3 E", "LLRRMM");

            Assert.AreEqual(Directions.East, result.InitialDirection);
            Assert.AreEqual(2, result.InitialPosition.X);
            Assert.AreEqual(3, result.InitialPosition.Y);

            var expectedSteps = new[] {
                ExecutionSteps.TurnLeft,
                ExecutionSteps.TurnLeft,
                ExecutionSteps.TurnRight,
                ExecutionSteps.TurnRight,
                ExecutionSteps.GoForward,
                ExecutionSteps.GoForward,
            };

            Assert.AreEqual(expectedSteps.Count(), result.Steps.Count());
            expectedSteps
            .Zip(result.Steps)
            .ToList()
            .ForEach(x => Assert.AreEqual(x.First, x.Second));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            PrintBanner();

            IInstructionReaderService instructionReaderService = new InstructionReaderService();

            string areaDimensionsLine = Console.ReadLine();
            var    areaDimensions     = instructionReaderService.ReadAreaDimensions(areaDimensionsLine);

            while (true)
            {
                string firstLine = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(firstLine))
                {
                    return;
                }

                string secondLine = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(secondLine))
                {
                    return;
                }

                var instructions = instructionReaderService.ReadTwoLinesOfInstructions(firstLine, secondLine);
                var drone        = new Drone(instructions.InitialPosition, instructions.InitialDirection, areaDimensions);

                foreach (var step in instructions.Steps)
                {
                    drone.ExecuteStep(step);
                }

                Console.WriteLine($"{drone.Position.X} {drone.Position.Y} {drone.Direction.GetCode()}");
            }
        }
コード例 #3
0
        public void TestReadInitialPosition(string input, int expectedX, int expectedY)
        {
            var service = new InstructionReaderService();
            var result  = service.ReadAreaDimensions(input);

            Assert.AreEqual(expectedX, result.X);
            Assert.AreEqual(expectedY, result.Y);
        }