Esempio n. 1
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"));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string commands = "'F','B','L','R', or 'Q' to quit";
            Console.WriteLine("Hello Rover\r");
            Console.WriteLine("Enter 'Q' to quit.\n");
            Console.WriteLine(string.Format("Accepted commands are: {0}\n", commands));
            Console.WriteLine("Please enter Rover's first command: \r");
            string keyInput = Console.ReadLine();

            //init rover
            Rover rover = new Rover();

            rover.PositionHeading = "N";
            rover.PositionX = 0;
            rover.PositionY = 0;

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

            while (keyInput != "q" && keyInput != "Q")
            {
                char[] cmds = keyInput.ToCharArray();
                string outputMessage = "";
                while (!rover.ObstacleFound)
                {
                    foreach (char c in cmds)
                    {
                        if (!rover.acceptedCommands.Contains(c.ToString()))
                        {
                            Console.WriteLine(string.Format("Invalid command recieved will ingore command: {0}", c));
                        }
                        else
                        {
                            outputMessage = rover.Command_Parser(c.ToString());
                        }
                    }
                    break;
                }
                rover.ObstacleFound = false;
                Console.WriteLine(outputMessage + "\n");
                Console.WriteLine(string.Format("\rRover ready for command ({0}):", commands));
                keyInput = Console.ReadLine();

            }

            Console.WriteLine("\nEXIT");
        }
Esempio n. 3
0
        public void Test_Rover_Drives_East_One_Space()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            rover.PositionX = 1;
            rover.PositionY = 0;
            rover.LandscapeWidth = 3;
            rover.LandscapeHeight = 3;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(false);

            rover.Command_Receiver("F");

            Assert.AreEqual(2, rover.PositionX);
        }
        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());
        }
Esempio n. 5
0
        public void Test_Rover_Drives_North_One_Space()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "N";
            rover.PositionX = 0;
            rover.PositionY = 0;

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

            rover.Command_Receiver("f");
            //rover.Drive_Forward();
            Assert.AreEqual(1, rover.PositionY);
        }
        public void Test_Confirm_Grid_Has_Obstacles()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            rover.PositionY = 0;
            rover.PositionX = 0;

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

            foreach (Coordinates c in rover.gridCoordinates)
            {
                if (c.containsObstacle)
                {
                    containsObstacle = true;
                }
            }

            Assert.AreEqual(true, containsObstacle);
        }
Esempio n. 7
0
        public void Test_Rover_Reverses_East_One_Space()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "W";
            rover.PositionX = 0;
            rover.PositionY = 0;

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

            rover.Command_Receiver("B");

            Assert.AreEqual(1, rover.PositionX);
        }
Esempio n. 8
0
        public void Test_Rovers_Position_From_Multiple_Drive_And_Turn_Commands()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "W";
            rover.PositionY = 0;
            rover.PositionX = 3;

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

            string[] commands = new string[] { "F", "F","R", "F", "F" };

            foreach (string s in commands)
            {
                rover.Command_Receiver(s);
            }

            Assert.AreEqual(2, rover.PositionY);
            Assert.AreEqual(1, rover.PositionX);
        }
Esempio n. 9
0
        public void Test_Wrapping_On_3_X_3_Grid()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            rover.PositionY = 0;
            rover.PositionX = 0;

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

            string[] commands = new string[] { "F", "F", "F", "F" };

            foreach (string s in commands)
            {
                rover.Command_Receiver(s);
                //rover.Drive_Forward();
            }

            Assert.AreEqual(0, rover.PositionY);
            Assert.AreEqual(1, rover.PositionX);
        }
Esempio n. 10
0
        public void Test_Rovers_Position_From_Multiple_Reverse_Commands()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "N";
            rover.PositionY = 1;
            rover.PositionX = 1;

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

            string[] commands = new string[] { "B", "B", "B", "L", "F" };

            foreach (string s in commands)
            {
                rover.Command_Receiver(s);
            }

            Assert.AreEqual(1, rover.PositionY);
            Assert.AreEqual(0, rover.PositionX);
        }