コード例 #1
0
        public void TestRemoveTail1()
        {
            DLList myDLL = new DLList();

            myDLL.removeTail();
            Assert.AreEqual(myDLL.tail, null);
        }
コード例 #2
0
        public void Testremovetail()
        {
            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.addToHead(d);
                    str[i] = line;
                    i++;
                }
                m_streamReader.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("errors" + e.ToString());
            }
            pDLL.removeTail();
            ////////////////////////
            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 = 1; k < i; k++)
            {
                if (str[k] == str2[j])
                {
                    match1 = true; j--;
                }
                else
                {
                    match1 = false; break;
                }
            }
            Assert.AreEqual(true, match1);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: MichaelAldous/DLLTesting
        public void TestMethodRemoveTail4()
        {
            DLLNode p   = new DLLNode("1");
            DLList  dll = new DLList();

            dll.addToHead(p);
            dll.removeTail();
            //Before removal, list should be 1
            //After, head and tail should point to null
            Assert.AreEqual(true, (dll.head == null && dll.tail == null));
        }//End of TestMethodRemoveTail4
コード例 #4
0
        public void testRemoveTail2()
        {
            DLList  list = new DLList();
            DLLNode node = new DLLNode(5);

            list.addToTail(node);

            list.removeTail();

            Assert.AreEqual(list.total(), 0);
            Assert.AreEqual(list.tail, null);
        }
コード例 #5
0
        public void Testremovetail3()
        {
            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.removeTail();
            ////////////////////////
            string[] str2 = new string[20];
            int      j    = 0;
            DLLNode  tail = pDLL.tail;

            while (tail.previous != null)
            {
                str2[j] = tail.str;
                j++;
                tail = tail.previous;
            }
            str2[j] = tail.str;
            /// /////////////////////////////////////

            string dd = null;

            if (i != j)
            {
                if (str[i] != str2[0])
                {
                    dd = str2[0];
                }
            }
            Assert.AreEqual("6", dd);
        }
コード例 #6
0
        public void TestRemoveTail3()
        {
            DLList  myDLL = new DLList();
            DLLNode p     = new DLLNode(1);

            myDLL.addToHead(p);

            myDLL.removeTail();

            // When removing tail (1) from DLL (1) new head & tail should be null
            Assert.AreEqual(myDLL.head, null);
            Assert.AreEqual(myDLL.tail, null);
        }
コード例 #7
0
ファイル: UnitTest1.cs プロジェクト: MichaelAldous/DLLTesting
        public void TestMethodRemoveTail3()
        {
            DLLNode p   = new DLLNode("1");
            DLList  dll = new DLList();

            dll.addToHead(p);
            p = new DLLNode("2");
            dll.addToHead(p);
            p = new DLLNode("3");
            dll.addToHead(p);
            dll.removeTail();
            //Before removal, order should be 3,2,1
            //After, should be null <- 3 <- 2 <- null
            Assert.AreEqual(true, (dll.tail.next == null && dll.tail.str == "1" && dll.tail.previous.str == "2" && dll.tail.previous.previous == null));
        }//End of TestMethodRemoveTail3
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: MichaelAldous/DLLTesting
        public void TestMethodRemovTail1()
        {
            DLLNode p   = new DLLNode("1");
            DLList  dll = new DLList();

            dll.addToHead(p);
            p = new DLLNode("2");
            dll.addToHead(p);
            p = new DLLNode("3");
            dll.addToHead(p);
            dll.removeTail();
            //Before removal, order should be 3,2,1
            //After, should be 3,2, with head.previous null, and tail.next null
            Assert.AreEqual(true, (dll.head.str == "3" && dll.tail.str == "2"));
            Assert.AreEqual(true, (dll.head.previous == null && dll.tail.next == null));
        }//End of TestMethodRemovTail1
コード例 #9
0
        public void testRemoveTail1()
        {
            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.removeTail();

            Assert.AreEqual(list.total(), 2);
            Assert.AreEqual(node2, list.tail);
        }
コード例 #10
0
        public void TestRemoveTail2()
        {
            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.removeTail();

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