예제 #1
0
        public void FindNodeTest()
        {
            string[] data = { "", "abcde", "3", "4", "5", "0" };

            BiDirectionalList <string> aList = new BiDirectionalList <string>(data);
            BiDirectionalList <string> bList = aList.Clone();
            SingleLinkedList <string>  list1 = new SingleLinkedList <string>(data);
            SingleLinkedList <string>  list2 = aList.Clone();

            Assert.AreEqual(list1.ToString(), list2.ToString());
            Assert.AreEqual(list1.FindNode("3").Value, "3");

            string[] array   = aList.ToArray();
            string   ssArray = aList.ToString();

            Assert.AreEqual(String.Join(", ", array), String.Join(", ", bList.ToString()));
            Assert.AreEqual(String.Join(", ", array), String.Join(", ", data));
            Assert.AreEqual(String.Join(", ", array), ssArray);

            Node <string> node1 = aList.FindNode("abcde");

            Assert.AreEqual(aList.FindNode(node1).Value, "abcde");
            Assert.AreEqual(aList.FindNode("3").Value, "3");
            Assert.AreEqual(aList.FindNode(3).Value, "4");
            Assert.AreEqual(aList.FindNode(2).Value, aList.FindNode(-4).Value);
            Assert.AreEqual(aList.FindNode(5).Value, aList.FindNode(-1).Value);
            Assert.AreNotEqual(aList.FindNode(0).Value, "0");
            Assert.IsNotNull(aList.FindNode(-6));
            Assert.IsNull(aList.FindNode(6));
            Assert.IsNull(aList.FindNodeBackward(6));
            Assert.IsNull(aList.FindNode(-7));

            Node <string> node2 = new Node <string>("abc");

            Assert.IsNull(aList.FindNode(node2));

            Node <string> node3 = aList.InsertNode(node2.Value, 2);

            Assert.AreEqual(node2, node3);
            Assert.IsNotNull(node3);
            Assert.IsNotNull(aList.AddNode(node2, aList.Last));
            Assert.AreEqual(node2, aList.Last);

            Node <string> node4 = aList.FindNodeBackward(4);

            Assert.AreEqual(node4.Value, "3");

            Node <string> node5 = aList.FindNodeBackward(5);
            Node <string> test5 = aList.FindNode(aList.Count - 5 - 1);

            Assert.AreEqual(node5.Value, test5.Value);

            aList.InsertNode(node1, node1);
            Assert.AreEqual(node1.Value, aList.Head.Next.Value);
        }
예제 #2
0
        public void ReverseTest2()
        {
            string test1 = "test1";
            string test6 = "test6";

            BiDirectionalList <object> oldList = new BiDirectionalList <object>(
                "", "abcde", new Node <object>('3'), 4, 5.0
                );

            oldList.AddNode(test6);

            BiDirectionalList <string> strList1 = new BiDirectionalList <string>("", "abcde", "3", "4", "5.0");
            BiDirectionalList <string> strList2 = strList1.Clone();

            BiDirectionalList <object> newList = oldList.Clone();
            string comp1 = oldList.ToString();
            string comp2 = newList.ToString();

            Assert.AreEqual(comp1, comp2);

            newList.Reverse();
            Assert.IsFalse(this.CompareReversedList(oldList, newList));
            Assert.IsTrue(this.CompareReversedList(oldList, newList, true));

            Assert.IsFalse(strList1.Equals(strList2));
            Assert.IsTrue(strList1.Equals(strList2, true));

            Node <object> node1 = newList.InsertNode(test1);

            Assert.AreEqual(newList.Head, node1);

            Node <object> node5 = newList.DeleteNode(-1);

            Assert.IsNull(newList.FindNode(node5));

            Node <object> node6 = newList.AddNode(test6);

            Assert.AreEqual(newList.Last, node6);
        }