Exemplo n.º 1
0
        public void FindLastNode()
        {
            string[] words =
            { "the", "fox", "jumps", "over", "jumps", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest = new CircularDoubleLinkedListCollection <string>(words);

            ArrayCRUD.LinkedListNode <string> foundNode = listTest.FindLast("jumps");
            Assert.Equal(listTest.Last.Previous.Previous.Value, foundNode.Value);
        }
Exemplo n.º 2
0
        public void AddItemAfterNodeArgumentNullException()
        {
            string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest = new CircularDoubleLinkedListCollection <string>(words);

            ArrayCRUD.LinkedListNode <string> node = null;
            Action act       = () => listTest.AddAfter(node, "old");
            var    exception = Assert.Throws <ArgumentNullException>(act);

            Assert.Equal("node", exception.ParamName);
        }
Exemplo n.º 3
0
        public void AddItemAfterNode()
        {
            string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest = new CircularDoubleLinkedListCollection <string>(words);

            ArrayCRUD.LinkedListNode <string> first = listTest.First;
            listTest.AddAfter(first, "old");
            ArrayCRUD.LinkedListNode <string> addedNode = listTest.First.Next;
            Assert.Contains("old", listTest);
            Assert.Equal("old", addedNode.Value);
        }
Exemplo n.º 4
0
        public void AddLastNode()
        {
            string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest = new CircularDoubleLinkedListCollection <string>(words);

            ArrayCRUD.LinkedListNode <string> addedNode = new ArrayCRUD.LinkedListNode <string>("last added node");
            listTest.AddLast(addedNode);
            Assert.Equal("last added node", listTest.Last.Value);
            Assert.Equal("the", listTest.Last.Next.Value);
            Assert.Equal("last added node", listTest.First.Previous.Value);
        }
Exemplo n.º 5
0
        public void AddNodeBeforeNode()
        {
            string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest = new CircularDoubleLinkedListCollection <string>(words);

            ArrayCRUD.LinkedListNode <string> second    = listTest.First.Next;
            ArrayCRUD.LinkedListNode <string> addedNode = new ArrayCRUD.LinkedListNode <string>("nice");
            listTest.AddBefore(second, addedNode);
            ArrayCRUD.LinkedListNode <string> newAddedNode = listTest.First.Next;
            Assert.Contains("nice", listTest);
            Assert.Equal("nice", newAddedNode.Value);
        }
Exemplo n.º 6
0
        public void AddNodeAfterNodeInvalidOperationException()
        {
            string[] anotherListElements =
            { "crazy", "lazy" };
            string[] words =
            { "the", "fox", "jumps", "over", "the", "dog" };
            CircularDoubleLinkedListCollection <string> listTest    = new CircularDoubleLinkedListCollection <string>(words);
            CircularDoubleLinkedListCollection <string> anotherList = new CircularDoubleLinkedListCollection <string>(anotherListElements);

            ArrayCRUD.LinkedListNode <string> addedNode = anotherList.First;
            Action act       = () => listTest.AddAfter(listTest.First, addedNode);
            var    exception = Assert.Throws <InvalidOperationException>(act);

            Assert.Equal("node belongs to another list", exception.Message);
        }