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); }
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); }
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); }
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); }
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); }
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); }