Пример #1
0
        public void SimpleLinkedListTest()
        {
            SimpleLinkedList node = new SimpleLinkedList();

            node.Add(5);
            node.Add(6);
            node.Add(12);

            //get the head Node from the Linked List
            SimpleLinkedList.Node currentNode;
            currentNode = node.GetCurrentNode();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(5, currentNode.Data);

            //get the next Node from the Linked List
            var nextNode = node.GetNext();

            currentNode = nextNode;
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(6, currentNode.Data);

            //get the following node
            nextNode    = node.GetNext();
            currentNode = nextNode;
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(12, currentNode.Data);

            nextNode    = node.GetNext();
            currentNode = nextNode;
            Assert.IsNotNull(currentNode);

            //test removing node from list
            currentNode = node.Head();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(5, currentNode.Data);

            currentNode = node.GetNext();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(6, currentNode.Data);
            node.RemoveCurrentNode();
            currentNode = node.GetCurrentNode();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(12, currentNode.Data);

            //remove head from list
            currentNode = node.Head();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(5, currentNode.Data);
            node.RemoveCurrentNode();
            currentNode = node.GetCurrentNode();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(12, currentNode.Data);
        }