Ejemplo n.º 1
0
        public void TestConvertResult()
        {
            RoverLogic logic = new RoverLogic();

            int[]  coordinates = { 1, 3, 0 };
            var    testResult  = logic.ConvertToResult(coordinates);
            string expected    = "1 3 N";

            Assert.AreEqual(expected, testResult);
        }
Ejemplo n.º 2
0
        public void Given_MovementCommandThatGoesOutOfBounds_ShouldReturnFalse()
        {
            var listOfInstructions = new List <string> {
                "8 8",
                "8 8 N",
                "M",
            };

            var roverLogic = new RoverLogic(listOfInstructions);
            var result     = roverLogic.Execute();

            Assert.That(result, Is.EqualTo("Rover moved out of grid at point 8 8 \n End position 8 9 N"));
        }
Ejemplo n.º 3
0
        public void Given_PositionOutOfGrid_ShouldReturnStatementAndExitLocation(string grid, string position, string movements, bool expected)
        {
            var listOfInstructions = new List <string> {
                grid,
                position,
                movements,
            };

            var roverLogic = new RoverLogic(listOfInstructions);
            var result     = roverLogic.IsInBounds();

            Assert.That(result, Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
        public void GoldenTest()
        {
            var listOfInstructions = new List <string> {
                "8 8",
                "1 2 E",
                "MMLMRMMRRMML",
            };

            var roverLogic = new RoverLogic(listOfInstructions);
            var result     = roverLogic.Execute();

            Assert.That(result, Is.EqualTo("3 3 S"));
        }
Ejemplo n.º 5
0
        public void TestCreateBorder()
        {
            RoverLogic logic = new RoverLogic();
            string     input = "5 5";

            int[] testResult = logic.CreateBorder(input);
            int[] expected   = { 5, 5 };
            Assert.AreEqual(expected.Length, testResult.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], testResult[i]);
            }
        }
Ejemplo n.º 6
0
        public void TestConvertToCoordinates()
        {
            RoverLogic logic = new RoverLogic();
            string     input = "1 2 N";

            int[] testResult = logic.ConvertToCoordinates(input);
            int[] expected   = { 1, 2, 0 };
            Assert.AreEqual(expected.Length, testResult.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], testResult[i]);
            }
        }
Ejemplo n.º 7
0
        public void Given_UnknownInstuction_ShouldReturnUnknownInstructions()
        {
            var listOfInstructions = new List <string> {
                "8 8",
                "1 2 E",
                "MMLMFMMRRMML",
            };

            var roverLogic = new RoverLogic(listOfInstructions);
            var result     = roverLogic.Execute();

            Assert.That(roverLogic.UnknownInstructions.Count, Is.EqualTo(1));
            Assert.That(roverLogic.UnknownInstructions[0], Is.EqualTo("F"));
        }
Ejemplo n.º 8
0
        public void TestIsLimit()
        {
            RoverLogic logic = new RoverLogic();

            int[] coordinates = { 1, 5, 0 };
            int[] border      = { 5, 5 };
            int[] testResult  = logic.IsLimit(coordinates, border);
            int[] expected    = { 0, 0, 0, 1 };
            Assert.AreEqual(expected.Length, testResult.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], testResult[i]);
            }
        }
Ejemplo n.º 9
0
        public void Given_MovementCommand_ShouldExecuteCorrectly()
        {
            var listOfInstructions = new List <string> {
                "8 8",
                "1 2 E",
                "MMLMRMMRRMML",
            };

            var roverLogic = new RoverLogic(listOfInstructions);

            roverLogic.ExecuteMovementCommand("M");

            Assert.That(roverLogic.X, Is.EqualTo(2));
            Assert.That(roverLogic.Y, Is.EqualTo(2));
            Assert.That(roverLogic.D, Is.EqualTo("E"));
        }
Ejemplo n.º 10
0
        public void TestGetRoute()
        {
            RoverLogic logic = new RoverLogic();

            int[]  coordinates = { 1, 2, 0 };
            string directions  = "LMLMLMLMM";

            int[] borders    = { 5, 5 };
            var   testResult = logic.GetRoute(coordinates, directions, borders);

            int[] expected = { 1, 3, 0 };
            Assert.AreEqual(expected.Length, testResult.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], testResult[i]);
            }
        }
Ejemplo n.º 11
0
        public void Given_ListOfInstructions_Should_BuildRoverLogicBaseCorrectly()
        {
            var listOfInstructions = new List <string> {
                "8 8",
                "1 2 E",
                "MMLMRMMRRMML",
            };

            var roverLogic = new RoverLogic(listOfInstructions);

            Assert.That(roverLogic.XMax, Is.EqualTo(8));
            Assert.That(roverLogic.YMax, Is.EqualTo(8));

            Assert.That(roverLogic.X, Is.EqualTo(1));
            Assert.That(roverLogic.Y, Is.EqualTo(2));
            Assert.That(roverLogic.D, Is.EqualTo("E"));

            Assert.That(roverLogic.Instructions.Count, Is.EqualTo(12));
        }