public void Should_RemoveValue_False() { //arrange var node1 = new MyDoublyLinkedListNode <int>(2); var node2 = new MyDoublyLinkedListNode <int>(4); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(5); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); //act var result = list.Remove(6); //assert result.ShouldBeEquivalentTo(false); list.Count.ShouldBeEquivalentTo(4); list.Head.ShouldBeEquivalentTo(node1); list.Head.Next.ShouldBeEquivalentTo(node2); list.Head.Next.Next.ShouldBeEquivalentTo(node3); list.Head.Next.Next.Next.ShouldBeEquivalentTo(node4); }
public void Should_RemoveNode_RemoveFirst() { //arrange var node1 = new MyDoublyLinkedListNode <int>(2); var node2 = new MyDoublyLinkedListNode <int>(4); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(5); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); //act list.Remove(node1); //assert list.Count.ShouldBeEquivalentTo(3); list.Head.ShouldBeEquivalentTo(node2); list.Head.Next.ShouldBeEquivalentTo(node3); list.Head.Next.Next.ShouldBeEquivalentTo(node4); }
public void Should_RemoveNode_Throw_If_Empty() { //arrange var list = new MyDoublyLinkedList <int>(); //act Action act = () => list.Remove(null); //assert act.ShouldThrow <ArgumentNullException>(); }
public void Should_RemoveNode_Length_One() { //arrange var node = new MyDoublyLinkedListNode <int>(2); var list = new MyDoublyLinkedList <int>(node); //act list.Remove(node); //assert list.Count.ShouldBeEquivalentTo(0); list.Head.ShouldBeEquivalentTo(list.Tail); list.Head.Should().BeNull(); }
private void ArrangeAndActUponLinkedLists(LinkedList <int> originalLinkedList, MyDoublyLinkedList <int> myLinkedList) { LinkedListNode <int> fiveHundredListNode = new LinkedListNode <int>(500); LinkedListNode <int> tenListNode = new LinkedListNode <int>(10); LinkedListNode <int> last = new LinkedListNode <int>(666); MyLinkedListNode <int> myFiveHundredListNode = new MyLinkedListNode <int>(500); MyLinkedListNode <int> myTenListNode = new MyLinkedListNode <int>(10); MyLinkedListNode <int> myLast = new MyLinkedListNode <int>(666); originalLinkedList.AddFirst(tenListNode); originalLinkedList.AddBefore(tenListNode, 9); originalLinkedList.AddAfter(tenListNode, fiveHundredListNode); originalLinkedList.AddLast(last); originalLinkedList.Remove(10); originalLinkedList.AddAfter(last, 777); originalLinkedList.Remove(fiveHundredListNode); originalLinkedList.RemoveFirst(); originalLinkedList.RemoveLast(); originalLinkedList.Clear(); originalLinkedList.AddLast(5); originalLinkedList.RemoveFirst(); myLinkedList.AddFirst(myTenListNode); myLinkedList.AddBefore(myTenListNode, 9); myLinkedList.AddAfter(myTenListNode, myFiveHundredListNode); myLinkedList.AddLast(myLast); myLinkedList.Remove(10); myLinkedList.AddAfter(myLast, 777); myLinkedList.Remove(myFiveHundredListNode); myLinkedList.RemoveFirst(); myLinkedList.RemoveLast(); myLinkedList.Clear(); myLinkedList.AddLast(5); myLinkedList.RemoveFirst(); }
public void Should_RemoveNode_Throw_If_Node_Is_Not_Contained() { //arrange var node1 = new MyDoublyLinkedListNode <int>(2); var node2 = new MyDoublyLinkedListNode <int>(4); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(5); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); //act Action act = () => list.Remove(new MyDoublyLinkedListNode <int>(2)); //assert act.ShouldThrow <InvalidOperationException>(); }