예제 #1
0
        private static void TestRovers(InputFile inputFile)
        {
            //Create the Plateau
            var plateau = new Plateau(inputFile.MaxCoordinate);

            //Create the first rover
            var rover1 = new Rover(plateau, inputFile.RoverPaths[0].StartCoordinate, inputFile.RoverPaths[0].StartDirection);
            //Move the rover
            rover1.SetPath(inputFile.RoverPaths[0].Path);
            //Test against expected result
            Assert.IsTrue(rover1.ToString().Equals("1 3 N"), string.Concat(rover1.ToString(), " should be 1 3 N"));

            //Create the second rover
            var rover2 = new Rover(plateau, inputFile.RoverPaths[1].StartCoordinate, inputFile.RoverPaths[1].StartDirection);
            //Move the rover
            rover2.SetPath(inputFile.RoverPaths[1].Path);
            //Test against expected result
            Assert.IsTrue(rover2.ToString().Equals("5 1 E"), string.Concat(rover2.ToString(), " should be 5 1 E"));
        }
예제 #2
0
        /// <summary>
        /// Load input from a Stream
        /// </summary>
        /// <param name="stream">The stream representing the input file</param>
        /// <returns>Instance of InputFile</returns>
        public static InputFile LoadInputFile(Stream stream)
        {
            var inputFile = new InputFile();

            using (var reader = new StreamReader(stream))
            {
                var maxCoordinateRead = false;

                while (!reader.EndOfStream)
                {
                    if (!maxCoordinateRead)
                    {
                        inputFile.MaxCoordinate = new Coordinate(reader.ReadLine());
                        maxCoordinateRead = true;
                    }

                    inputFile.RoverPaths.Add(new RoverPath(reader.ReadLine(), reader.ReadLine()));
                }
            }

            return inputFile;
        }