Exemplo n.º 1
0
        public void AddInEmptyList()
        {
            LinkedList2 list = new LinkedList2();
            Node        node = new Node(10);

            list.AddInHead(node);
            Assert.IsTrue(list.head == node && list.tail == node);
        }
        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));
        }
Exemplo n.º 3
0
        private void AddInHeadTest(Node nodeToInsert, params Node[] nodes)
        {
            LinkedList2 list = GetLinkedList(nodes);

            Node expectedHead = nodeToInsert;
            Node expectedTail = nodes.LastOrDefault() ?? nodeToInsert;

            list.AddInHead(nodeToInsert);

            Assert.Same(expectedHead, list.head);
            Assert.Same(expectedTail, list.tail);

            CheckPrevAndNextCorrectness(list, nodes.Length + 1);
        }
        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));
        }
        public void AddNodeTest()
        {
            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));
            testList.AddInTail(new Node(6));
            testList.AddInHead(new Node(7));
            int expected = 8;

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

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

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            testList.AddInTail(new Node(4));
            testList.AddInHead(new Node(4));
            int expected = 7;
            int actual   = testList.Count();


            List <Node> resultsList = testList.FindAll(4);

            Assert.AreEqual(expected, actual);
            Assert.IsTrue(testList.FindAll(4).Count == 5);
        }