Ejemplo n.º 1
0
        static void TestFindElement()
        {
            Console.WriteLine("find element test");

            var list = new LinkedList2();

            list.AddInTail(new Node(20));
            list.AddInTail(new Node(24));
            list.AddInTail(new Node(10));
            list.AddInTail(new Node(15));
            list.AddInTail(new Node(77));
            list.AddInTail(new Node(24));

            Console.WriteLine("find 20");
            var result = list.Find(20);

            Console.WriteLine("result " + result.value);

            Console.WriteLine("find 10");
            result = list.Find(10);
            Console.WriteLine("result " + result.value);

            Console.WriteLine("find 24");
            result = list.Find(24);
            Console.WriteLine("result " + result.value);

            Console.WriteLine(new string('=', 30));
        }
Ejemplo n.º 2
0
        public void FindInFilledList()
        {
            LinkedList2 list     = new LinkedList2();
            Node        testNode = new Node(12);

            list.AddInTail(new Node(10));
            list.AddInTail(new Node(11));
            list.AddInTail(testNode);
            Assert.IsTrue(list.Find(13) == null && list.Find(12) == testNode);
        }
Ejemplo n.º 3
0
        private void FindTest(int valueToFind, params Node[] nodes)
        {
            LinkedList2 list = GetLinkedList(nodes);

            Node expectedNode = nodes.FirstOrDefault(n => n.value == valueToFind);

            Assert.Same(expectedNode, list.Find(valueToFind));
        }
Ejemplo n.º 4
0
        public void Test_Find_WhenOneFoundItem()
        {
            var list  = new LinkedList2();
            var node1 = new Node(1);
            var node2 = new Node(2);

            list.AddInTail(node1);
            list.AddInTail(node2);
            var foundNode = list.Find(node2.value);

            Assert.AreEqual(node2, foundNode);
        }
        public void AddInHead_in_EmptyList()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInHead(new Node(21));

            int expected = 1;
            int actual   = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(testList.Find(21));
        }
        public void Remove_from_EmptyList()
        {
            LinkedList2 testList = new LinkedList2();
            int         expected = 0;

            testList.Remove(5);
            int actual = testList.Count();

            Assert.IsNull(testList.head);
            Assert.IsNull(testList.tail);
            Assert.AreEqual(expected, actual);
            Assert.IsNull(testList.Find(5));
        }
Ejemplo n.º 7
0
        public static void TestFind()
        {
            var testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            var found = testList.Find(2);

            Assert.AreSame(testList.head.next, found, "Test TestFind failed. List head.next not equal found");
            Assert.AreEqual(2, found.value, "Test TestFind failed. List found not equal 2");
            Assert.AreEqual(3, found.next.value, "Test TestFind failed. List found.next not equal 3");
            Assert.AreEqual(1, found.prev.value, "Test TestFind failed. List found.prev not equal 1");
        }
        public void Remove_from_Tail()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(0));
            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            int expected = 3;

            testList.Remove(3);
            int actual = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsNull(testList.Find(3));
        }
Ejemplo n.º 9
0
        public void Test_Find_WhenManyFoundItems()
        {
            var list      = new LinkedList2();
            var sameValue = 2;
            var node1     = new Node(1);
            var node2     = new Node(sameValue);
            var node3     = new Node(4);
            var node4     = new Node(sameValue);

            list.AddInTail(node1);
            list.AddInTail(node2);
            list.AddInTail(node3);
            list.AddInTail(node4);
            var foundNode = list.Find(sameValue);

            Assert.AreEqual(node2, foundNode);
        }
        public void AddNode_if_Target_non_Exists()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            int expected = 5;

            testList.InsertAfter(new Node(13), new Node(21));
            int actual = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsNull(testList.Find(21));
        }
        public void AddNode_in_Tail()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            int expected = 6;

            testList.InsertAfter(new Node(5), new Node(21));
            int actual = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsTrue(testList.Find(21).value == 21);
        }
        public void AddInHead_in_NotEmptyList()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            int expected = 6;

            testList.AddInHead(new Node(19));
            int actual = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(testList.Find(19));
        }
Ejemplo n.º 13
0
        public void FindInEmptyList()
        {
            LinkedList2 list = new LinkedList2();

            Assert.IsTrue(list.Find(0) == null);
        }