Exemple #1
0
        public static char TestRemove()
        {
            char   result          = 'q';
            string strRemoved      = "";
            string test            = "Remove() Test";
            string testDescription = "This test randomly selects a number from the list and calls Remove(). The method will remove the first occurence of the selected number by replacing it with the last number and shortening the list.";

            UnorderedArrayList list = new UnorderedArrayList();

            list.InsertValues(initializeList());

            int num                = GetRandomNumber();
            int valueSelected      = list.GetValueAtLocation(num);
            int locationOfSelected = list.GetFirstPositionOfValue(valueSelected);

            int[] allLocationsOfSelected = { locationOfSelected };
            int   valueAtEnd             = list.GetValueAtLocation(list.GetLength() - 1);

            strRemoved = locationOfSelected.ToString();

            list.Remove(valueSelected);

            ReportRemoveTestsToConsole(test, testDescription, valueSelected.ToString(), allLocationsOfSelected, list);

            Console.Write("\nPress 'r' to Repeat, 'c' to Continue, or 'q' to Quit: ");

            result = Convert.ToChar(Console.ReadKey().KeyChar);

            if (result == 'r')
            {
                TestRemove();
            }

            return(result);
        }