public void Should_Add_Before_Throw_Does_Not_Have_Node() { //arrange var node1 = new MyDoublyLinkedListNode <int>(1); var node2 = new MyDoublyLinkedListNode <int>(2); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(4); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); var node5 = new MyDoublyLinkedListNode <int>(5); //act Action act = () => list.AddBefore(new MyDoublyLinkedListNode <int>(6), node5); //assert act.ShouldThrow <InvalidOperationException>(); }
public void Should_Add_Before() { //arrange var node1 = new MyDoublyLinkedListNode <int>(1); var node2 = new MyDoublyLinkedListNode <int>(2); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(4); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); var node5 = new MyDoublyLinkedListNode <int>(5); //act list.AddBefore(node3, node5); //assert list.Count.ShouldBeEquivalentTo(5); list.Head.ShouldBeEquivalentTo(node1); list.Tail.ShouldBeEquivalentTo(node4); list.Head.Next.ShouldBeEquivalentTo(node2); list.Head.Next.Next.ShouldBeEquivalentTo(node5); list.Head.Next.Next.Next.ShouldBeEquivalentTo(node3); list.Head.Next.Next.Next.Next.ShouldBeEquivalentTo(node4); }
public void Should_Add_Before_Throw_If_Null() { //arrange var list = new MyDoublyLinkedList <int>(); //act Action act = () => list.AddBefore(null, null); //assert act.ShouldThrow <ArgumentNullException>(); }
public void Should_Add_Before_Check_Head() { //arrange var node1 = new MyDoublyLinkedListNode <int>(1); var list = new MyDoublyLinkedList <int>(node1); var node2 = new MyDoublyLinkedListNode <int>(2); //act list.AddBefore(node1, node2); //assert list.Count.ShouldBeEquivalentTo(2); list.Head.ShouldBeEquivalentTo(node2); list.Tail.ShouldBeEquivalentTo(node1); list.Head.Next.ShouldBeEquivalentTo(node1); }
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(); }