public void AddAt(int[] data, int insert, int pos) { DoublyLinkedList <int> list = new DoublyLinkedList <int>(); for (int i = data.Length - 1; i >= 0; i--) { list.AddAt(0, data[i]); } var before = list.GetNodeAt(pos - 1); var after = list.GetNodeAt(pos); int count = list.Count; list.AddAt(pos, insert); if (before != null) { Assert.True(before.Next.item == insert); } if (after != null) { Assert.True(after.Previous.item == insert); } Assert.True(count != list.Count); }
public void InsertAt() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(122)); Assert.AreEqual(list.FindAtIndex(0).Value, 122); }
public void FindLastNode() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(12)); list.AddAt(0, new DoublyLinkedListNode <int>(13)); list.AddAt(0, new DoublyLinkedListNode <int>(14)); Assert.AreEqual(list.FindLastNode()?.Value, 1); }
public void List_ThrowsAnErrorIfAddingAnInvalidIndex() { var doubly = new DoublyLinkedList <int> { 100, 200, 300 }; doubly.AddAt(doubly.Size, 1000); Assert.Throws <IndexOutOfRangeException>(() => doubly.AddAt(6, 2000)); Assert.Throws <IndexOutOfRangeException>(() => doubly.AddAt(-1, 2000)); }
public void Count() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(2)); list.AddAt(0, new DoublyLinkedListNode <int>(3)); list.RemoveAt(0); list.AddAt(0, new DoublyLinkedListNode <int>(4)); Assert.AreEqual(list.Count(), 3); }
public void DeleteFirstNode() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(12)); list.AddAt(0, new DoublyLinkedListNode <int>(13)); list.AddAt(0, new DoublyLinkedListNode <int>(14)); list.RemoveFirstNode(); Assert.AreEqual(list.FindFirstNode()?.Value, 13); }
public void IsEmpty() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.AddAt(0, new DoublyLinkedListNode <int>(1)); list.RemoveAt(0); list.RemoveAt(0); list.RemoveAt(0); list.RemoveAt(0); Assert.AreEqual(list.IsEmpty(), true); }
public void AddAtTest(int idx, int val, int[] expected) { int[] array = new int[] { 0, 1, 2, 3 }; list = new DoublyLinkedList(array); if (idx < 0 || idx > array.Length - 1) { Assert.Throws <Exception>(() => list.AddAt(idx, val)); } else { list.AddAt(idx, val); int[] actual = list.ToArray(); Assert.AreEqual(expected, actual); } }
public void BatchTest() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); for (int i = 0; i < 10; i++) { list.AddLast(new DoublyLinkedListNode <int>(i)); } for (int i = 1; i < 10; i += 2) { list.AddAt(i, new DoublyLinkedListNode <int>(100 + i * i)); } int count = list.Count(); for (int i = 0; i < count; i++) { if (i > 0) { Debug.Write("-"); } Debug.Write(list.FindAtIndex(i).Value); } Assert.IsTrue(true); }
public void AddAtArrayTest(int[] original, int index, int[] values, int[] expected) { DoublyLinkedList sList = new DoublyLinkedList(original); sList.AddAt(index, values); Assert.AreEqual(expected, sList.ToArray()); }
public void List_AddsFirstIfListIsEmptyNoMatterTheIndex() { var doubly = new DoublyLinkedList <int>(); doubly.AddAt(100, 1000); Assert.Equal(1, doubly.Size); Assert.Equal(1000, doubly.HeadNode.Value); Assert.Equal(doubly.HeadNode, doubly.TailNode); }
public void List_CorrectlyAddsAtLastIndex() { var doubly = new DoublyLinkedList <int> { 100, 200, 300 }; doubly.AddAt(doubly.Size, 1000); Assert.Equal(1000, doubly.TailNode.Value); }
public void List_CorrectlyAddsAtIndexZero() { var doubly = new DoublyLinkedList <int> { 100, 200, 300 }; doubly.AddAt(0, 1000); Assert.Equal(1000, doubly.HeadNode.Value); }
public void List_CorrectlyAddsAtMidIndex() { var doubly = new DoublyLinkedList <int> { 100, 200, 300 }; doubly.AddAt(1, 1000); Assert.Equal(1000, doubly.GetAt(1).Value); }
public void AddMiddleException2Test() { var list = new DoublyLinkedList <string>(); Assert.Throws <ArgumentOutOfRangeException>( () => { list.AddAt(-1, "Alpha"); }); }
public void Should_Increment_Length() { var list = new DoublyLinkedList <int>(); list.Add(1); list.AddAt(1, 5); var actualElement = list.Length; actualElement.Should().Be(2); }
public void List_ReturnsAnArrayOfElements() { var doubly = new DoublyLinkedList <int> { 100, 200, 300 }; doubly.AddAt(doubly.Size, 1000); var arr = new[] { 100, 200, 300, 1000 }; Assert.Equal(arr, doubly.ToArray()); }
public void Should_Insert_Element_At_Specified_Position() { var list = new DoublyLinkedList <int>(); list.Add(1); list.Add(3); list.AddAt(1, 5); var actualElement = list.ElementAt(1); actualElement.Should().Be(5); }
public void Should_Insert_Element_At_The_End_Of_The_List() { var list = new DoublyLinkedList <int>(); list.Add(1); list.Add(6); list.AddAt(2, 8); var actualElement = list.ElementAt(2); actualElement.Should().Be(8); }
public void AddAtArrayTestExceptopn(int[] original, int index, int[] values) { DoublyLinkedList sList = new DoublyLinkedList(original); try { sList.AddAt(index, values); } catch (ArgumentException e) { return; } Assert.Fail(); }
public void AddMiddleTest() { var list = new DoublyLinkedList <string>(); list.AddBack("Alpha"); list.AddBack("Beta"); list.AddBack("Delta"); list.AddBack("Echo"); list.AddAt(2, "Charlie"); Assert.AreEqual(5, list.Count); Assert.AreEqual("Alpha", list.GetAt(0)); Assert.AreEqual("Beta", list.GetAt(1)); Assert.AreEqual("Charlie", list.GetAt(2)); Assert.AreEqual("Delta", list.GetAt(3)); Assert.AreEqual("Echo", list.GetAt(4)); }
public void Should_Increment_Length() { // Arrange var list = new DoublyLinkedList <int> { 1, }; // Act list.AddAt(1, 5); // Assert var actualElement = list.Length; actualElement.Should() .Be(2); }
public void Should_Insert_Element_At_Specified_Position() { // Arrange var list = new DoublyLinkedList <int> { 1, 3, }; // Act list.AddAt(1, 5); // Assert var actualElement = list.ElementAt(1); actualElement.Should() .Be(5); }
public void Should_Insert_Element_At_The_Beginning_Of_The_List() { // Arrange var list = new DoublyLinkedList <int> { 1, 6, }; // Act list.AddAt(0, 8); // Assert var actualElement = list.ElementAt(0); actualElement.Should() .Be(8); }
public void AddAt_WhenIndexIsOutOfRange_ShouldThrowOutOfRangeException(int index, int value) { // Arrange & Act & Assert Assert.Throws <IndexOutOfRangeException>(() => _list.AddAt(index, value)); }
public void AddAt_NegativeIndexShouldFail() { Assert.Throws <ArgumentException>("index", () => list.AddAt(10, -1)); }
public void AddAtTest(int id, int val, int[] expected) { dLList.AddAt(id, val); int[] actual = dLList.ToArray(); Assert.AreEqual(expected, actual); }