Пример #1
0
        /// <summary>
        /// Test finding the item at the back of the alinked list
        /// </summary>
        static void TestFindAtBackOfLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            list.Add("Foxtrot");
            list.Add("Echo");
            list.Add("Delta");
            Console.Write("TestFindAtBackOfLinkedList: ");
            LinkedListNode <string> actualNode = list.Find("Delta");

            if (actualNode != null &&
                actualNode.Value.Equals("Delta"))
            {
                Console.WriteLine("Passed");
            }
            else
            {
                if (actualNode == null)
                {
                    Console.WriteLine("FAILED!!! Expected: Delta Actual: null");
                }
                else
                {
                    Console.WriteLine("FAILED!!! Expected: Delta Actual: " +
                                      actualNode.Value);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Test adding an item to a nonempty linked list
        /// </summary>
        static void TestAddNonemptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            list.Add("Foxtrot");
            list.Add("Echo");
            Console.Write("TestAddNonemptyLinkedList: ");
            string liststring = list.ToString();

            if (liststring.Equals("Echo,Foxtrot") &&
                list.Count == 2)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: Echo,Foxtrot and 2 Actual: " +
                                  liststring + " and " + list.Count);
            }
        }
Пример #3
0
        /// <summary>
        /// Test removing an item from the interior of the list
        /// </summary>
        static void TestRemoveItemFromInteriorOfLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            list.Add("Foxtrot");
            list.Add("Echo");
            list.Add("Delta");
            Console.Write("TestRemoveItemInteriorOfLinkedList: ");
            bool   removed    = list.Remove("Echo");
            string listString = list.ToString();

            if (removed &&
                listString.Equals("Delta,Foxtrot") &&
                list.Count == 2)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: Delta,Foxtrot and 2 Actual: " +
                                  listString + " and " + list.Count);
            }
        }
Пример #4
0
        /// <summary>
        /// Test removing an item not in the list
        /// </summary>
        static void TestRemoveItemNotInLinkedList()
        {
            UnsortedLinkedList <string> array = new UnsortedLinkedList <string>();

            array.Add("Foxtrot");
            Console.Write("TestRemoveItemNotInLinkedList: ");
            if (!array.Remove("Golf"))
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: false Actual: true");
            }
        }
Пример #5
0
        /// <summary>
        /// Test clearing a non-empty linked list
        /// </summary>
        static void TestClearNonemptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            list.Add("Foxtrot");
            list.Add("Echo");
            list.Add("Delta");
            list.Add("Charlie");
            list.Add("Bravo");
            list.Add("Alpha");
            Console.Write("TestClearNonemptyLinkedList: ");
            list.Clear();
            if (list.Count == 0 &&
                list.Head == null)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: 0 and null Actual: " +
                                  list.Count + " and " + list.Head);
            }
        }