public void TestRemoveHead1()
        {
            DLList myDLL = new DLList();

            myDLL.removeHead();
            Assert.AreEqual(myDLL.head, null);
        }
예제 #2
0
        public void Testremovehead()
        {
            string[]   str  = new string[30];
            int        i    = 0;
            FileStream f    = new FileStream("C:/Users/edgu1/Desktop/222525.txt", FileMode.Open, FileAccess.Read);
            DLList     pDLL = new DLList();
            string     line;

            try
            {
                StreamReader m_streamReader = new StreamReader(f);
                //StreamReader read txt
                m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                //read from head to tail by lines
                while ((line = m_streamReader.ReadLine()) != null)
                {
                    DLLNode d = new DLLNode(line);
                    pDLL.addToTail(d);
                    str[i] = line;
                    i++;
                }
                m_streamReader.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("errors" + e.ToString());
            }
            pDLL.removeHead();
            ////////////////////////
            string[] str2 = new string[20];
            int      j    = 0;
            DLLNode  head = pDLL.head;

            while (head.next != null)
            {
                str2[j] = head.str;
                j++;
                head = head.next;
            }
            Console.WriteLine(head.str);
            str2[j] = head.str;


            /// /////////////////////////////////////
            bool match1 = false;

            for (int k = 0; k < j; k++)
            {
                if (str[k + 1] == str2[k])
                {
                    match1 = true;
                }
                else
                {
                    match1 = false; break;
                }
            }
            Assert.AreEqual(true, match1);
        }
예제 #3
0
        public void Testremovehead3()
        {
            string[]   str  = new string[30];
            int        i    = 0;
            FileStream f    = new FileStream("C:/Users/edgu1/Desktop/222525.txt", FileMode.Open, FileAccess.Read);
            DLList     pDLL = new DLList();
            string     line;

            try
            {
                StreamReader m_streamReader = new StreamReader(f);
                //StreamReader read txt
                m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                //read from head to tail by lines
                while ((line = m_streamReader.ReadLine()) != null)
                {
                    str[i] = line;
                    i++;
                }
                m_streamReader.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("errors" + e.ToString());
            }
            pDLL = Program.initialArr("C:/Users/edgu1/Desktop/222525.txt");
            pDLL.removeHead();
            ////////////////////////
            string[] str2 = new string[20];
            int      j    = 0;
            DLLNode  head = pDLL.head;

            while (head.next != null)
            {
                str2[j] = head.str;
                j++;
                head = head.next;
            }

            str2[j] = head.str;


            /// /////////////////////////////////////
            string dd = null;

            if (i != j)
            {
                if (str[0] != str2[0])
                {
                    dd = str2[0];
                }
            }
            Assert.AreEqual("20", dd);
        }
예제 #4
0
        public void testRemoveHead2()
        {
            DLLNode node = new DLLNode(12);

            DLList list = new DLList();

            list.addToHead(node);
            list.removeHead();

            Assert.AreEqual(list.total(), 0);
            Assert.IsNull(list.head);
        }
        public void TestRemoveHead3()
        {
            DLList  myDLL = new DLList();
            DLLNode p     = new DLLNode(1);

            myDLL.addToHead(p);

            myDLL.removeHead();

            // When removing head (1) from DLL (1) new head & tail should be null
            Assert.AreEqual(myDLL.head, null);
            Assert.AreEqual(myDLL.tail, null);
        }
예제 #6
0
        public void testRemoveHead1()
        {
            DLLNode node1 = new DLLNode(12);
            DLLNode node2 = new DLLNode(5);
            DLLNode node3 = new DLLNode(7);

            DLList list = new DLList();

            list.addToHead(node1);
            list.addToHead(node2);
            list.addToHead(node3);
            list.removeHead();

            Assert.AreEqual(list.total(), 2);
            Assert.AreEqual(node2, list.head);
        }
        public void TestRemoveHead2()
        {
            DLList  myDLL = new DLList();
            DLLNode p     = new DLLNode(1);

            myDLL.addToHead(p);
            DLLNode q = new DLLNode(2);

            myDLL.addToHead(q);
            DLLNode r = new DLLNode(3);

            myDLL.addToHead(r);

            myDLL.removeHead();

            // When removing head (3) from DLL (3,2,1) new head should be 2
            Assert.AreEqual(myDLL.head.num, 2);
        }