Ejemplo n.º 1
0
        public void RobotDoNotMove_InvalidInstruction()
        {
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            rob.Move('s');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'N');
        }
Ejemplo n.º 2
0
        public void MoveRight()
        {
            var point = new Point(0, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            robot.Move('R');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(1, newPoint.XPoint);
            Assert.AreEqual(0, newPoint.YPoint);
        }
Ejemplo n.º 3
0
        public void TestXBoundry0()
        {
            var point = new Point(0, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            //try to move left from 0,0: make sure we stay there
            robot.Move('L');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(0, newPoint.XPoint);
            Assert.AreEqual(0, newPoint.YPoint);
        }
Ejemplo n.º 4
0
        public void TestYBoundry0()
        {
            var point = new Point(0, 0);
            //set init direction to south (2)
            var robot = new SimpleRobot(point, 2, _holder, 5, 5);

            //move F, make sure we stay @ 00
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(0, newPoint.XPoint);
            Assert.AreEqual(0, newPoint.YPoint);
        }
Ejemplo n.º 5
0
        public void TestSpinner()
        {
            var point = new Point(2, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            _holder.SetObstacle(2, 1, new Spinner(true, 1));
            robot.Move('F');
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(3, newPoint.XPoint);
            Assert.AreEqual(1, newPoint.YPoint);
        }
Ejemplo n.º 6
0
        public void TestHole()
        {
            var point = new Point(4, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            _holder.SetObstacle(4, 2, new Hole(3, 2));
            robot.Move('F');
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(3, newPoint.XPoint);
            Assert.AreEqual(2, newPoint.YPoint);
        }
Ejemplo n.º 7
0
        public void RobotDoNotMove_RockOrUnkownOrBorder()
        {
            //Test rock in Front
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            //rock at (9,9) , Do not move Front
            grid.Topography[9, 9] = new Rock()
            {
                ObsPosition = new int[] { 9, 9 }
            };
            rob.Move('F');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'N');

            //Test Unknown on Left
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            //Unknown at (8,8) , Do not move to Left
            grid.Topography[8, 8] = new Unknown()
            {
                ObsPosition = new int[] { 8, 8 }
            };
            rob.Move('L');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'N');


            //Test On the border
            //robot at (19,18) 'N'
            //Out of bouds on Move to Right : Do Not Move
            rob = new SimpleRobot(1, 19, 18, 'N', grid);
            rob.Move('R');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 19);
            Assert.AreEqual(newPoint[1], 18);
            Assert.AreEqual(rob.GetDirection(), 'N');

            //robot at (19,19) 'N'
            //Move Front / Left / Right Do not move
            rob = new SimpleRobot(1, 19, 19, 'N', grid);
            rob.Move('F');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 19);
            Assert.AreEqual(newPoint[1], 19);
            Assert.AreEqual(rob.GetDirection(), 'N');
        }
Ejemplo n.º 8
0
        public void TestRock()
        {
            var point = new Point(0, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            //put a rock at 0,2, try to move forward 3,  make sure we stay at 0,1
            _holder.SetObstacle(0, 2, _rock);
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(0, newPoint.XPoint);
            Assert.AreEqual(1, newPoint.YPoint);
        }
Ejemplo n.º 9
0
        public void TestYBoundryMax()
        {
            var point = new Point(0, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            //move F 5 times, make sure we stay at 0,4
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(0, newPoint.XPoint);
            Assert.AreEqual(4, newPoint.YPoint);
        }
Ejemplo n.º 10
0
        public void TestXBountryMax()
        {
            var point = new Point(0, 0);
            var robot = new SimpleRobot(point, 0, _holder, 5, 5);

            //try to move right from 0,0 5 times: make sure we stay at 4,0
            robot.Move('R');
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            robot.Move('F');
            var newPoint = robot.GetLocation();

            Assert.AreEqual(4, newPoint.XPoint);
            Assert.AreEqual(0, newPoint.YPoint);
        }
Ejemplo n.º 11
0
        public void RobotMoveTo_Path()
        {
            //Test Path in Front
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            //Path at (9,9) , Move Front to (9,9)
            grid.Topography[9, 9] = new Path()
            {
                ObsPosition = new int[] { 9, 9 }
            };
            rob.Move('F');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 9);
            Assert.AreEqual(rob.GetDirection(), 'N');
        }
Ejemplo n.º 12
0
        public void RobotMoveTo_Hole()
        {
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            //hole at (9,9) connected to (7,7)
            grid.Topography[9, 9] = new Hole()
            {
                ObsPosition = new int[] { 9, 9 },
                endPosition = new int[] { 7, 7 }
            };
            rob.Move('F');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 7);
            Assert.AreEqual(newPoint[1], 7);
            Assert.AreEqual(rob.GetDirection(), 'N');
        }
Ejemplo n.º 13
0
        public void RobotDoNotMove_AnotherRobotPosition()
        {
            //robot1 at (9,8) 'N'
            //Robot1 can not move Right since Robot2 is present there
            rob1 = new SimpleRobot(1, 9, 8, 'N', grid);
            rob2 = new SimpleRobot(2, 9, 9, 'N', grid);
            grid.RobotsInGrid = new List <SimpleRobot>
            {
                rob1,
                rob2
            };

            rob1.Move('F');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'N');
        }
Ejemplo n.º 14
0
        public void RobotMoveTo_Spinner()
        {
            //robot at (9,8) 'N'
            rob = new SimpleRobot(1, 9, 8, 'N', grid);
            //move to spinner at (9,9) with spinAngle 90 , changes Direction to 'E'
            grid.Topography[9, 9] = new Spinner()
            {
                ObsPosition = new int[] { 9, 9 },
                spinAngle   = 90
            };
            rob.Move('F');
            var newPoint = rob.GetLocation();

            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 9);
            Assert.AreEqual(rob.GetDirection(), 'E');
            //move Right to spinner at (9,8) with spinAngle 90 , changes Direction From 'E' to 'S'
            grid.Topography[9, 8] = new Spinner()
            {
                ObsPosition = new int[] { 9, 8 },
                spinAngle   = 90
            };
            rob.Move('R');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 9);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'S');
            //move Right to spinner at (8,8) with spinAngle 90 , changes Direction From 'S' to 'W'
            grid.Topography[8, 8] = new Spinner()
            {
                ObsPosition = new int[] { 8, 8 },
                spinAngle   = 90
            };
            rob.Move('R');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 8);
            Assert.AreEqual(newPoint[1], 8);
            Assert.AreEqual(rob.GetDirection(), 'W');
            //move Right to spinner at (8,9) with spinAngle 90 , changes Direction From 'W' to 'N'
            grid.Topography[8, 9] = new Spinner()
            {
                ObsPosition = new int[] { 8, 9 },
                spinAngle   = 90
            };
            rob.Move('R');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 8);
            Assert.AreEqual(newPoint[1], 9);
            Assert.AreEqual(rob.GetDirection(), 'N');
            //move Left to spinner at (7,9) with spinAngle 270 , changes Direction From 'N' to 'W'
            grid.Topography[7, 9] = new Spinner()
            {
                ObsPosition = new int[] { 7, 9 },
                spinAngle   = 270
            };
            rob.Move('L');
            newPoint = rob.GetLocation();
            Assert.AreEqual(newPoint[0], 7);
            Assert.AreEqual(newPoint[1], 9);
            Assert.AreEqual(rob.GetDirection(), 'W');
        }