예제 #1
0
        public void ParseTwoRovers()
        {
            var lines = new[]
            {
                "10 12",
                "5 6 N",
                "M",
                "7 8 E",
                "L"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsTrue(result.Ok);
            Assert.AreEqual((10, 12), (result.MaxX, result.MaxY));

            Assert.AreEqual(2, result.RoverSpecs.Length);
            var roverSpecA = result.RoverSpecs[0];
            var roverSpecB = result.RoverSpecs[1];

            Assert.AreEqual(
                (5, 6, CompassDirection.North, RoverInstruction.Move),
                (roverSpecA.X, roverSpecA.Y, roverSpecA.Facing, roverSpecA.Instructions.Single()));

            Assert.AreEqual(
                (7, 8, CompassDirection.East, RoverInstruction.TurnLeft),
                (roverSpecB.X, roverSpecB.Y, roverSpecB.Facing, roverSpecB.Instructions.Single()));
        }
예제 #2
0
        public void ParseSingleRover()
        {
            var lines = new[]
            {
                "10 12",
                "5 6 N",
                "MMLR"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsTrue(result.Ok);
            Assert.AreEqual((10, 12), (result.MaxX, result.MaxY));

            Assert.AreEqual(1, result.RoverSpecs.Length);
            var roverSpec = result.RoverSpecs[0];

            Assert.AreEqual((5, 6, CompassDirection.North), (roverSpec.X, roverSpec.Y, roverSpec.Facing));
            Assert.AreEqual(
                new[]
            {
                RoverInstruction.Move,
                RoverInstruction.Move,
                RoverInstruction.TurnLeft,
                RoverInstruction.TurnRight
            },
                roverSpec.Instructions);
        }
예제 #3
0
        public void RejectsBadHeader(string line, string expectedError)
        {
            var lines = new[]
            {
                line
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsFalse(result.Ok);
            Assert.AreEqual(expectedError, result.ParseError);
        }
예제 #4
0
        public void AllCornersAreInBounds(int x, int y)
        {
            var lines = new[]
            {
                "10 12",
                $"{x} {y} N",
                "M"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsTrue(result.Ok);
        }
예제 #5
0
        public void RejectsEvenLineCount()
        {
            var lines = new[]
            {
                "5 5",
                "1 1 N"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsFalse(result.Ok);
            Assert.AreEqual("Expected odd number of lines", result.ParseError);
        }
예제 #6
0
        public void RejectsBadInstruction()
        {
            var lines = new[]
            {
                "10 10",
                "5 5 N",
                "MxLR"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsFalse(result.Ok);
            Assert.AreEqual("Unexpected instruction on line: MxLR", result.ParseError);
        }
예제 #7
0
        public void RejectsOutOfBounds(int x, int y)
        {
            var lines = new[]
            {
                "10 12",
                $"{x} {y} N",
                "M"
            };

            var result = RoverSimInputParser.Parse(lines);

            Assert.IsFalse(result.Ok);
            Assert.AreEqual($"Rover at {x}, {y} is out of bounds", result.ParseError);
        }
예제 #8
0
파일: Program.cs 프로젝트: agmt76/wed-sho
        static void Main(string[] args)
        {
            //TODO - read this from file path specified in args?
            string[] lines = new[]
            {
                "5 5",
                "1 2 N",
                "LMLMLMLMM",
                "3 3 E",
                "MMRMMRMRRM"
            };

            var parseResult = RoverSimInputParser.Parse(lines);

            if (!parseResult.Ok)
            {
                Console.Out.WriteLine("Parse error: " + parseResult.ParseError);
                Environment.Exit(0);
            }

            var rovers = ProcessRovers(parseResult);

            OutputRovers(rovers);
        }