public List <string> CheckNextLinks(DoublyLinkedList.DoublyLinkedList testList) { List <string> actual = new List <string>(); foreach (string item in testList) { actual.Add(item); } return(actual); }
public void AddAtWrongIndex_IndexOutOfRangeException() { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("4"); testList.AddToTail("5"); Assert.ThrowsException <IndexOutOfRangeException>( () => testList.AddAtIndex("3", 7)); }
public void GetTheOnlyFirstElement_TheElementIsGotten() { string expected = "1"; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); string actual = testList.FirstElement(); Xunit.Assert.Equal(expected, actual); }
public void DeleteAtIndex_IndexOutOfRangeException(int index) { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("3"); testList.AddToTail("4"); testList.AddToTail("5"); Xunit.Assert.Throws <IndexOutOfRangeException>( () => testList.DeleteAtIndex(index)); }
public List <string> CheckPreviousLinks(DoublyLinkedList.DoublyLinkedList testList) { List <string> actual = new List <string>(); Node item = testList.Tail; while (item != null) { actual.Add(item.Value); item = item.Previous; } return(actual); }
public void DeleteTheOnlyExistedElement_TheListIsEmpty() { List <string> expected = new List <string> { }; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.DeleteAtIndex(1); List <string> actual = CheckNextLinks(testList); CollectionAssert.AreEqual(expected, actual); }
public void GetTheLastElement_TheRightElementIsGotten() { string expected = "5"; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("3"); testList.AddToTail("4"); testList.AddToTail("5"); string actual = testList.LastElement(); Xunit.Assert.Equal(expected, actual); }
public void AddElementsToHead_ElementsAreAddedInRightOrder_FromTail() { List <string> expected = new List <string> { "1", "2", "3" }; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToHead("1"); testList.AddToHead("2"); testList.AddToHead("3"); List <string> actual = CheckPreviousLinks(testList); CollectionAssert.AreEqual(expected, actual); }
public void AddOneElementToTheMiddle_ElementsAreInRightOrder_FromTail() { List <string> expected = new List <string> { "5", "4", "3", "2", "1" }; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("4"); testList.AddToTail("5"); testList.AddAtIndex("3", 3); List <string> actual = CheckPreviousLinks(testList); CollectionAssert.AreEqual(expected, actual); }
public void DeleteOneMiddleElement_ElementIsDeletedCorrectly_FromTail() { List <string> expected = new List <string> { "5", "4", "2", "1" }; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("3"); testList.AddToTail("4"); testList.AddToTail("5"); testList.DeleteAtIndex(3); List <string> actual = CheckPreviousLinks(testList); CollectionAssert.AreEqual(expected, actual); }
public void DeleteOneMiddleAndOneLastElements_ElementsAreDeletedCorrectly_FromHead() { List <string> expected = new List <string> { "1", "2", "4" }; DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("3"); testList.AddToTail("4"); testList.AddToTail("5"); testList.DeleteAtIndex(3); testList.DeleteAtIndex(4); List <string> actual = CheckNextLinks(testList); CollectionAssert.AreEqual(expected, actual); }
public void DeleteAtIndex_TheRightElementIsDeleted(int value1) { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); testList.AddToTail("1"); testList.AddToTail("2"); testList.AddToTail("3"); testList.AddToTail("4"); testList.AddToTail("5"); List <string> expected = new List <string> { "1", "2", "3", "4", "5" }; testList.DeleteAtIndex(value1); expected.RemoveAt(value1 - 1); List <string> actualNextLinks = CheckNextLinks(testList); List <string> actualPreviousLinks = CheckPreviousLinks(testList); CollectionAssert.AreEqual(actualNextLinks, expected); expected.Reverse(); CollectionAssert.AreEqual(actualPreviousLinks, expected); }
public void GetTheLastElementInEmptyList_OutOfRangeException() { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); Xunit.Assert.Throws <IndexOutOfRangeException>( () => testList.LastElement()); }
public void GetTheFirstElementInEmptyList_OutOfRangeException() { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); Assert.ThrowsException <IndexOutOfRangeException>( () => testList.FirstElement()); }
public void DeleteInEmptyList_IndexOutOfRangeExeption() { DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList(); Assert.ThrowsException <IndexOutOfRangeException>( () => testList.DeleteAtIndex(1)); }