Esempio n. 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);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Test getting the count for an empty array
        /// </summary>
        static void TestCountEmptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            Console.Write("TestCountEmptyLinkedList: ");
            if (list.Count == 0)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: 0 Actual: " + list.Count);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Test removing an item from an empty list
        /// </summary>
        static void TestRemoveFromEmptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            Console.Write("TestRemoveFromEmptyLinkedList: ");
            if (!list.Remove("Foxtrot"))
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: false Actual: true");
            }
        }
Esempio n. 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");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Test finding the item in an empty list
        /// </summary>
        static void TestFindInEmptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            Console.Write("TestFindInEmptyLinkedList: ");
            LinkedListNode <string> actualNode = list.Find("Foxtrot");

            if (actualNode == null)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: null Actual: " + actualNode.Value);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Test clearing an empty linked list
        /// </summary>
        static void TestClearEmptyLinkedList()
        {
            UnsortedLinkedList <string> list = new UnsortedLinkedList <string>();

            Console.Write("TestClearEmptyLinkedList: ");
            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);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Test adding an item to an empty linked list
        /// </summary>
        static void TestAddEmptyLinkedList()
        {
            LinkedList <string> list = new UnsortedLinkedList <string>();

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

            if (liststring.Equals("Foxtrot") &&
                list.Count == 1)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("FAILED!!! Expected: Foxtrot and 1 Actual: " +
                                  liststring + " and " + list.Count);
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }