public static void checkReferenceTypeWithNull() { Console.WriteLine("Проверка reference type c null\n"); var list = new LoopSingleLinkList <Person>(); try { list.AddLast(new Person("Serhii", "Yanchuk", "*****@*****.**")); Person serhii = null; list.AddLast(serhii); list.AddLast(new Person("Serhii", "Yanchuk", "*****@*****.**")); list.AddLast(new Person("Serhii", "Yanchuk", "*****@*****.**")); } catch (Exception ex) { Console.WriteLine($"Исключение: {ex.Message}"); Console.WriteLine($"Метод: {ex.TargetSite}"); Console.WriteLine($"Трассировка стека: {ex.StackTrace}"); } Console.WriteLine($"First: {list.First?.Value} \nLast: {list.Last?.Value}"); Console.WriteLine($"Длина: {list.Length}"); ShowList(list); NodeWithLink <Person> node = list.Find(null); Console.WriteLine($"\nНайден null value: {node != null}"); list.Remove(null); Console.WriteLine("\nУдалено узел с null value"); ShowList(list); }
public static void SaveList <T>(object sender) { LoopSingleLinkList <T> collection = sender as LoopSingleLinkList <T>; try { using (StreamWriter sw = new StreamWriter(sender.GetHashCode().ToString() + ".txt", false, System.Text.Encoding.Default)) { if (collection.First != null) // список пуст { NodeWithLink <T> currentNode = collection.First; do { if (currentNode.Value != null) // значение в узле равно null { sw.WriteLine(currentNode.Value); } currentNode = currentNode.Next; } while (currentNode != collection.First); // перебор циклического списка } } } catch (Exception ex) { Console.WriteLine($"Исключение: {ex.Message}"); Console.WriteLine($"Метод: {ex.TargetSite}"); Console.WriteLine($"Трассировка стека: {ex.StackTrace}"); } }
public void AddFirst_NullNodeAddFirstInList_ArgumentNullExceptionReturned() { // Arrange LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(); NodeWithLink <T> first = null; // Act // Assert Assert.Throws <ArgumentNullException>(() => list.AddFirst(first)); }
public void FindLast_FindLastNotExistNodeWithSpecificValueType_NullNodeReturned() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2, 3, 4, 5); // Act NodeWithLink <int> found = list.FindLast(0); // Assert Assert.Null(found); }
public void AddFirst_NodeAddFirstInList_LengthUp1() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(); NodeWithLink <int> first = new NodeWithLink <int>(1); // Act list.AddFirst(first); // Assert Assert.Equal(1, list.Length); }
public void AddFirst_NodeAddFirstInList_LengthUp1() { // Arrange LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(); NodeWithLink <T> first = CreateSampleNode(); // Act list.AddFirst(first); // Assert Assert.Equal(1, list.Length); }
public void AddLast_NodeWithValueTypeElementAddLastInEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(); NodeWithLink <int> last = new NodeWithLink <int>(1); // Act list.AddLast(last); // Assert Assert.Same(last, list.First); Assert.Same(last, list.Last); }
protected override NodeWithLink <EquatableMock>[] CreateSequenceOfFiveNodes() { NodeWithLink <EquatableMock> node1 = new NodeWithLink <EquatableMock>(new EquatableMock(1)); NodeWithLink <EquatableMock> node2 = new NodeWithLink <EquatableMock>(new EquatableMock(2)); NodeWithLink <EquatableMock> node3 = new NodeWithLink <EquatableMock>(new EquatableMock(3)); NodeWithLink <EquatableMock> node4 = new NodeWithLink <EquatableMock>(new EquatableMock(4)); NodeWithLink <EquatableMock> node5 = new NodeWithLink <EquatableMock>(new EquatableMock(5)); return(new NodeWithLink <EquatableMock>[5] { node1, node2, node3, node4, node5 }); }
public void AddFirst_NodeWithReferenceTypeElementAddFirstInEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(); NodeWithLink <Person> first = new NodeWithLink <Person>(new Person("s1", "y1")); // Act list.AddFirst(first); // Assert Assert.Same(first, list.First); Assert.Same(first, list.Last); }
public void Find_FindExistNodeWithSpecificValue_NotNullNodeReturned() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); T existValue = sequence[1].Value; // Act NodeWithLink <T> found = list.Find(existValue); // Assert Assert.NotNull(found); }
public void AddAfter_AddAfterWithAnyNullArgumentsNode_ArgumentNullExceptionReturned() { // Arrange NodeWithLink <T> node1 = CreateSampleNode(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(node1); NodeWithLink <T> node2 = null; // Act // Assert Assert.Throws <ArgumentNullException>(() => list.AddAfter(node1, node2)); Assert.Throws <ArgumentNullException>(() => list.AddAfter(node2, node1)); }
public void AddLast_NodeAddLastInEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(); NodeWithLink <T> last = CreateSampleNode(); // Act list.AddLast(last); // Assert Assert.Same(last, list.First); Assert.Same(last, list.Last); }
protected override NodeWithLink <int>[] CreateSequenceOfFiveNodes() { NodeWithLink <int> node1 = new NodeWithLink <int>(1); NodeWithLink <int> node2 = new NodeWithLink <int>(2); NodeWithLink <int> node3 = new NodeWithLink <int>(3); NodeWithLink <int> node4 = new NodeWithLink <int>(4); NodeWithLink <int> node5 = new NodeWithLink <int>(5); return(new NodeWithLink <int>[5] { node1, node2, node3, node4, node5 }); }
public void FindLast_FindLastNotExistNodeWithSpecificValue_NullNodeReturned() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); T notExistValue = CreateSampleNode().Value; // Act NodeWithLink <T> found = list.FindLast(notExistValue); // Assert Assert.Null(found); }
public void AddAfter_NodeAddAfterInList_LengthUp1() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); NodeWithLink <T> node1 = sequence[0]; NodeWithLink <T> node0 = CreateSampleNode(); // Act list.AddAfter(node1, node0); // Assert Assert.Equal(sequence.Length + 1, list.Length); }
public void Find_FindExistNodeWithNullValue_NotNullNodeReturned() { // Arrange NodeWithLink <Person> node1 = new NodeWithLink <Person>(new Person("s1", "y1")); NodeWithLink <Person> node2 = new NodeWithLink <Person>(null); NodeWithLink <Person> node3 = new NodeWithLink <Person>(new Person("s3", "y3")); LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(node1, node2, node3); // Act NodeWithLink <Person> found = list.Find(null); // Assert Assert.NotNull(found); }
public void Remove_RemoveExistNodeFromListWithOneNode_TrueReturned() { // Arrange NodeWithLink <T> first = CreateSampleNode(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(first); // Act bool isDeleted = list.Remove(first.Value); // Assert Assert.True(isDeleted); Assert.Null(list.First); Assert.Null(list.Last); }
public void AddLast_NodeWithReferenceTypeElementAddLastInNotEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(new Person("s1", "y1"), new Person("s2", "y2")); NodeWithLink <Person> last = list.Last; NodeWithLink <Person> newLast = new NodeWithLink <Person>(new Person("s3", "y3")); // Act list.AddLast(newLast); // Assert Assert.Same(newLast, list.Last); Assert.Same(newLast, last.Next); Assert.Same(list.First, newLast?.Next); }
public void Find_FindExistNodeWithNullValue_NotNullNodeReturned() { // Arrange NodeWithLink <EquatableMock>[] sequence = CreateSequenceOfFiveNodes(); EquatableMock existValue = null; LoopSingleLinkList <EquatableMock> list = new LoopSingleLinkList <EquatableMock>(sequence); list.AddLast(existValue); // Act NodeWithLink <EquatableMock> found = list.Find(existValue); // Assert Assert.NotNull(found); }
public void AddFirst_NodeWithValueTypeElementAddFirstInNotEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2); NodeWithLink <int> first = list.First; NodeWithLink <int> newFirst = new NodeWithLink <int>(3); // Act list.AddFirst(newFirst); // Assert Assert.Same(newFirst, list.First); Assert.Same(newFirst, list.Last?.Next); Assert.Same(first, newFirst?.Next); }
public void Remove_RemoveExistMiddleNodeFromList_LengthDown1() { // Arrange NodeWithLink <int> node1 = new NodeWithLink <int>(1); NodeWithLink <int> node2 = new NodeWithLink <int>(2); NodeWithLink <int> node3 = new NodeWithLink <int>(3); NodeWithLink <int> node4 = new NodeWithLink <int>(4); LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(node1, node2, node3, node4); // Act list.Remove(3); // Assert Assert.Equal(3, list.Length); }
public void FindLast_FindLastNotExistNodeWithSpecificReferenceType_NullNodeReturned() { // Arrange NodeWithLink <Person> node1 = new NodeWithLink <Person>(new Person("s1", "y1")); NodeWithLink <Person> node2 = new NodeWithLink <Person>(new Person("s2", "y2")); NodeWithLink <Person> node3 = new NodeWithLink <Person>(new Person("s3", "y3")); LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(node1, node2, node3); Person temp = new Person("s4", "y4"); // Act NodeWithLink <Person> found = list.FindLast(temp); // Assert Assert.Null(found); }
public void AddAfter_NodeAddAfterInList_LengthUp1() { // Arrange NodeWithLink <int> node1 = new NodeWithLink <int>(1); NodeWithLink <int> node2 = new NodeWithLink <int>(2); NodeWithLink <int> node3 = new NodeWithLink <int>(3); LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(node1, node2, node3); NodeWithLink <int> node4 = new NodeWithLink <int>(4); // Act list.AddAfter(node1, node4); // Assert Assert.Equal(4, list.Length); }
public void Remove_RemoveExistNodeWithNullValueFromListWithOneNode_TrueReturned() { // Arrange NodeWithLink <EquatableMock> node0 = new NodeWithLink <EquatableMock>(null); LoopSingleLinkList <EquatableMock> list = new LoopSingleLinkList <EquatableMock>(node0); EquatableMock removeValue = null; // Act bool isDeleted = list.Remove(removeValue); // Assert Assert.True(isDeleted); Assert.Null(list.First); Assert.Null(list.Last); }
public void Remove_RemoveExistMiddleNodeFromList_LengthDown1() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); NodeWithLink <T> node1 = sequence[0]; NodeWithLink <T> node2 = sequence[1]; NodeWithLink <T> node3 = sequence[2]; LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); T removeValue = node2.Value; // Act list.Remove(removeValue); // Assert Assert.Equal(sequence.Length - 1, list.Length); }
public void Remove_RemoveExistMiddleNodeFromListValueType_TrueReturned() { // Arrange NodeWithLink <int> node1 = new NodeWithLink <int>(1); NodeWithLink <int> node2 = new NodeWithLink <int>(2); NodeWithLink <int> node3 = new NodeWithLink <int>(3); NodeWithLink <int> node4 = new NodeWithLink <int>(4); LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(node1, node2, node3, node4); // Act bool isDeleted = list.Remove(3); // Assert Assert.True(isDeleted); Assert.Same(node4, node2?.Next); }
public void AddAfter_NodeWithReferenceTypeElementAddAfterSomeNodeInList_NodeAdded() { // Arrange NodeWithLink <Person> node1 = new NodeWithLink <Person>(new Person("s1", "y1")); NodeWithLink <Person> node2 = new NodeWithLink <Person>(new Person("s2", "y2")); NodeWithLink <Person> node3 = new NodeWithLink <Person>(new Person("s3", "y3")); LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(node1, node2, node3); NodeWithLink <Person> node4 = new NodeWithLink <Person>(new Person("s4", "y4")); // Act list.AddAfter(node1, node4); // Assert Assert.Same(node4, node1?.Next); Assert.Same(node2, node4?.Next); }
public void AddAfter_NodeAddAfterSomeNodeInMiddleInList_NodeAdded() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); NodeWithLink <T> node1 = sequence[0]; NodeWithLink <T> node2 = sequence[1]; NodeWithLink <T> node0 = CreateSampleNode(); // Act list.AddAfter(node1, node0); // Assert Assert.Same(node0, node1?.Next); Assert.Same(node2, node0?.Next); }
public void AddLast_NodeAddLastInNotEmptyList_NodeAdded() { // Arrange NodeWithLink <T>[] sequence = CreateSequenceOfFiveNodes(); LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(sequence); NodeWithLink <T> last = list.Last; NodeWithLink <T> newLast = CreateSampleNode(); // Act list.AddLast(newLast); // Assert Assert.Same(newLast, list.Last); Assert.Same(newLast, last.Next); Assert.Same(list.First, newLast?.Next); }
public void FindLast_FindLastExistNodeWithSpecificValueType_NotNullNodeReturned() { // Arrange NodeWithLink <int> node1 = new NodeWithLink <int>(1); NodeWithLink <int> node2 = new NodeWithLink <int>(2); NodeWithLink <int> node3 = new NodeWithLink <int>(3); NodeWithLink <int> node4 = new NodeWithLink <int>(3); NodeWithLink <int> node5 = new NodeWithLink <int>(4); LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(node1, node2, node3, node4, node5); // Act NodeWithLink <int> found = list.FindLast(3); // Assert Assert.Same(node4, found); }