public void Test_Get_Rover_Directional_Heading()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "N";
            string headingReturned;
            Navigation navigation = new Navigation(rover);
            headingReturned = navigation.GetDirectionalHeading();

            Assert.AreEqual("N", headingReturned);
        }
Beispiel #2
0
        public void Test_Rover_Turns_North()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "W";
            Navigation navigation = new Navigation(rover);

            rover.Command_Parser("R");

            Assert.AreEqual("N", navigation.GetDirectionalHeading());
        }
Beispiel #3
0
        public void Test_Rover_Left_Turn_West_()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "N";
            Navigation navigation = new Navigation(rover);

            rover.Command_Receiver("L");

            Assert.AreEqual("W", navigation.GetDirectionalHeading());
        }
Beispiel #4
0
        public void Test_For_Obstacle_Detection()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            Navigation navigation = new Navigation(rover);
            string headingIndex = navigation.GetDirectionalHeading();
            rover.PositionY = 0;
            rover.PositionX = 0;

            rover.LandscapeHeight = 5;
            rover.LandscapeWidth = 5;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(false);

            //set obstacle
            Coordinates crd = new Coordinates{

                 xCoordinate = 1,
                 yCoordinate =0
            };
            Coordinates coor = (from Coordinates in rover.gridCoordinates
                                where Coordinates.xCoordinate == 1 && Coordinates.yCoordinate == 0
                                select Coordinates).FirstOrDefault<Coordinates>();
            bool notNull = coor != null;
            int indexOf = -1;
            if(coor != null)
            {
                indexOf = rover.gridCoordinates.IndexOf(coor);
            }

            //int indexOf = rover.gridCoordinates.IndexOf(crd);
            bool hasIndex = indexOf > 0;
            if (hasIndex)
            {
                rover.gridCoordinates[indexOf].containsObstacle = true;
            }

            string rtnMessage = "";
            char[] cmds = ("f").ToCharArray();
            while (!rover.ReportObstacle)
            {
                foreach (char c in cmds)
                {
                    rtnMessage = rover.Command_Parser(c.ToString());
                }
                //break;
            }

            Assert.AreEqual(true, rtnMessage.Contains("Obst"));
        }
        public void Test_Check_Grid_Is_Creating_The_Correct_Number_Of_Spaces()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            Navigation navigation = new Navigation(rover);
            string headingIndex = navigation.GetDirectionalHeading();
            rover.PositionY = 0;
            rover.PositionX = 0;

            rover.LandscapeHeight = 5;
            rover.LandscapeWidth = 5;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(false);

            Assert.AreEqual(25, rover.gridCoordinates.Count());
        }
Beispiel #6
0
        public void Drive_Forward()
        {
            Navigation _navigation = new Navigation(_rover);
            try
            {
                switch (_navigation.GetDirectionalHeading())
                {
                    case "N":
                        int testCoordinate_N = _rover.PositionY + 1;
                        if (testCoordinate_N > _rover._landscapeHeight)
                        {
                            testCoordinate_N = 0;
                        }
                        if (_navigation.IsDestinationFreeFromObstacle(_rover.PositionX, testCoordinate_N))
                        {
                            _rover.PositionY++;
                        }
                        if (_rover.PositionY > _rover._landscapeHeight)
                        {
                            _rover.PositionY = 0;
                        }
                        break;
                    case "E":
                        int testCoordinate_E = _rover.PositionX + 1;
                        if (testCoordinate_E > _rover._landscapeWidth)
                        {
                            testCoordinate_E = 0;
                        }
                        if (_navigation.IsDestinationFreeFromObstacle(testCoordinate_E, _rover.PositionY))
                        {
                            _rover.PositionX++;
                        }
                        if (_rover.PositionX > _rover._landscapeWidth)
                        {
                            _rover.PositionX = 0;
                        }
                        break;
                    case "S":
                        int testCoordinate_S = _rover.PositionY - 1;
                        if (testCoordinate_S < 0)
                        {
                            testCoordinate_S = _rover._landscapeHeight;
                        }
                        if (_navigation.IsDestinationFreeFromObstacle(_rover.PositionX, testCoordinate_S))
                        {
                            _rover.PositionY--;
                        }
                        if (_rover.PositionY < 0)
                        {
                            _rover.PositionY = _rover._landscapeHeight;
                        }
                        break;
                    case "W":
                        int testCoordinate_W = _rover.PositionX - 1;
                        if (testCoordinate_W < 0)
                        {
                            testCoordinate_W = _rover._landscapeWidth;
                        }
                        if (_navigation.IsDestinationFreeFromObstacle(testCoordinate_W, _rover.PositionY))
                        {
                            _rover.PositionX--;
                        }
                        if (_rover.PositionX < 0)
                        {
                            _rover.PositionX = _rover._landscapeWidth;
                        }
                        break;
                    default:

                        break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Drive_Forward error", ex);
            }
        }
Beispiel #7
0
 public void Drive_Reverse()
 {
     Navigation _navigation = new Navigation(_rover);
     switch (_navigation.GetDirectionalHeading())
     {
         case "N":
             int testCoordinate_N = _rover.PositionY - 1;
             if (testCoordinate_N < 0)
             {
                 testCoordinate_N = _rover._landscapeHeight;
             }
             if (_navigation.IsDestinationFreeFromObstacle(_rover.PositionX, testCoordinate_N))
             {
                 _rover.PositionY--;
             }
             if (_rover.PositionY < 0)
             {
                 _rover.PositionY = _rover._landscapeHeight;
             }
             break;
         case "E":
             int testCoordinate_E = _rover.PositionX - 1;
             if (testCoordinate_E < 0)
             {
                 testCoordinate_E = _rover._landscapeWidth;
             }
             if (_navigation.IsDestinationFreeFromObstacle(testCoordinate_E, _rover.PositionY))
             {
                 _rover.PositionX--;
             }
             if (_rover.PositionX < 0)
             {
                 _rover.PositionX = _rover._landscapeWidth;
             }
             break;
         case "S":
             int testCoordinate_S = _rover.PositionY + 1;
             if (testCoordinate_S > _rover._landscapeHeight)
             {
                 testCoordinate_S = 0;
             }
             if (_navigation.IsDestinationFreeFromObstacle(_rover._position_X, testCoordinate_S))
             {
                 _rover._position_Y++;
             }
             if (_rover._position_Y > _rover._landscapeHeight)
             {
                 _rover._position_Y = 0;
             }
             break;
         case "W":
             int testCoordinate_W = _rover._position_X + 1;
             if (testCoordinate_W > _rover._landscapeWidth)
             {
                 testCoordinate_W = 0;
             }
             if (_navigation.IsDestinationFreeFromObstacle(testCoordinate_W, _rover.PositionY))
             {
                 _rover.PositionX++;
             }
             if (_rover.PositionX > _rover._landscapeWidth)
             {
                 _rover.PositionX = 0;
             }
             break;
         default:
             //todo throw exception
             break;
     }
 }
Beispiel #8
0
        public string Command_Parser(string command)
        {
            try
            {
                Command_Receiver(command);

            }
            catch
            {
                //return error message
                return ReturnMessage;

            }
            //return coordinates and heading
            if(ObstacleFound)
            {
                ReportObstacle = true;
                return ReturnMessage;
            }
            Navigation navigation = new Navigation(this);
            return string.Format("Rover's current position is: coordinate({0},{1}), heading {2}", PositionX, PositionY, navigation.GetDirectionalHeading());
        }
Beispiel #9
0
        public void Test_Rover_Turns_South()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            Navigation navigation = new Navigation(rover);

            rover.Command_Receiver("R");

            Assert.AreEqual("S", navigation.GetDirectionalHeading());
        }