public void TestRemoveNode5()
        {
            DLList list = new DLList();

            DLLNode node1 = new DLLNode(5); //tail
            DLLNode node2 = new DLLNode(4);
            DLLNode node3 = new DLLNode(3);
            DLLNode node4 = new DLLNode(2);
            DLLNode node5 = new DLLNode(7); //head

            list.addToHead(node1);
            list.addToHead(node2);
            list.addToHead(node3);
            list.addToHead(node4);
            list.addToHead(node5);

            list.removeNode(node1);

            // there should only be 4 nodes left
            // value of 5 should not be present
            // head should be node 2
            Assert.AreEqual(list.total(), 4);
            Assert.IsNull(list.search(5));
            Assert.AreEqual(list.tail, node2);
        }
Exemple #2
0
        public void TestremoveNode2()
        {
            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());
            }

            string  sn      = "3";
            DLLNode delnode = new DLLNode(sn);
            DLLNode a       = pDLL.removeNode(delnode);

            Assert.AreEqual(16, a.number);
        }
        public void TestRemoveNode3()
        {
            DLList  list  = new DLList();
            DLLNode node1 = new DLLNode(5);

            list.removeNode(node1);
        }
Exemple #4
0
        public void TestremoveNode4()
        {
            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());
            }

            string  sn      = "3";
            DLLNode delnode = new DLLNode(sn);
            DLLNode a       = pDLL.removeNode(delnode);

            ////////////////////////
            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;
            /// /////////////////////////////////////
            string dd = null;

            for (int k = 0; k < i; k++)
            {
                if (str[k] != str2[k])
                {
                    dd = str2[k]; break;
                }
            }
            Assert.AreEqual("33", dd);
        }
Exemple #5
0
        public void testRemoveNode1()
        {
            DLList  list = new DLList();
            DLLNode node = new DLLNode(12);

            list.addToHead(node);
            list.removeNode(node);

            Assert.AreEqual(list.total(), 0);
            Assert.IsNull(list.head);
        }
        public void TestRemoveNode2()
        {
            DLList list = new DLList();

            DLLNode node1 = new DLLNode(5);

            list.addToHead(node1);

            list.removeNode(node1);

            Assert.AreEqual(list.total(), 0);
            Assert.IsNull(list.search(5));
        }
Exemple #7
0
        public void testRemoveNode4()
        {
            DLList  list  = new DLList();
            DLLNode node1 = new DLLNode(12);
            DLLNode node2 = new DLLNode(5);
            DLLNode node3 = new DLLNode(7);

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

            list.removeNode(node3);

            Assert.AreEqual(list.total(), 2);
            Assert.AreEqual(list.head, node2);
        }
        public void TestMethodRemoveNode4()
        {
            DLLNode p   = new DLLNode("3");
            DLList  dll = new DLList();

            dll.addToHead(p);
            p = new DLLNode("2");
            dll.addToHead(p);
            p = new DLLNode("1");
            dll.addToHead(p);
            //DLL order == 1,2,3
            dll.removeNode(dll.head.next.next);
            //"4" should not be found, and should return null
            Assert.AreEqual(true, (dll.head.str == "1" && dll.tail.str == "3"));
            Assert.AreEqual(true, (dll.head.next.str == "2" && dll.head.next.next.str == "3" && dll.tail.previous.str == "2" && dll.tail.previous.previous.str == "1"));
            Assert.AreEqual(true, (dll.head.previous == null && dll.tail.next == null));
        } //End of TestMethodRemoveNode4
        public void TestRemoveNode1()
        {
            DLList list = new DLList();

            DLLNode node1 = new DLLNode(5);
            DLLNode node2 = new DLLNode(4);
            DLLNode node3 = new DLLNode(3);
            DLLNode node4 = new DLLNode(2);
            DLLNode node5 = new DLLNode(7);

            list.addToHead(node1);
            list.addToHead(node2);
            list.addToHead(node3);
            list.addToHead(node4);
            list.addToHead(node5);

            list.removeNode(node3);

            // there should only be 4 nodes left and value
            // of 7 should not be present
            Assert.AreEqual(list.total(), 4);
            Assert.IsNull(list.search(3));
        }