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 void AddLast_NullNodeAddLastInList_ArgumentNullExceptionReturned() { // Arrange LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(); NodeWithLink <T> last = null; // Act // Assert Assert.Throws <ArgumentNullException>(() => list.AddLast(last)); }
public void AddLast_NodeAddLastInList_LengthUp1() { // Arrange LoopSingleLinkList <T> list = new LoopSingleLinkList <T>(); NodeWithLink <T> first = CreateSampleNode(); // Act list.AddLast(first); // Assert Assert.Equal(1, list.Length); }
public void AddLast_NodeAddLastInList_LengthUp1() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(); NodeWithLink <int> first = new NodeWithLink <int>(1); // Act list.AddLast(first); // Assert Assert.Equal(1, list.Length); }
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); }
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); }
public void AddLast_NodeWithReferenceTypeElementAddLastInEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <Person> list = new LoopSingleLinkList <Person>(); NodeWithLink <Person> last = new NodeWithLink <Person>(new Person("s1", "y1")); // Act list.AddLast(last); // Assert Assert.Same(last, list.First); Assert.Same(last, 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 AddLast_NodeWithValueTypeElementAddLastInNotEmptyList_NodeAdded() { // Arrange LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2); NodeWithLink <int> last = list.Last; NodeWithLink <int> newLast = new NodeWithLink <int>(3); // Act list.AddLast(newLast); // Assert Assert.Same(newLast, list.Last); Assert.Same(newLast, last.Next); Assert.Same(list.First, newLast?.Next); }
public void Contains_ContainsExistNodeWithNullValue_TrueReturned() { // Arrange NodeWithLink <EquatableMock>[] sequence = CreateSequenceOfFiveNodes(); EquatableMock existValue = null; LoopSingleLinkList <EquatableMock> list = new LoopSingleLinkList <EquatableMock>(sequence); list.AddLast(existValue); // Act bool isFound = list.Contains(existValue); // Assert Assert.True(isFound); }
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 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_FindLastExistNodeWithNullValue_NotNullNodeReturned() { // Arrange NodeWithLink <EquatableMock>[] sequence = CreateSequenceOfFiveNodes(); NodeWithLink <EquatableMock> existValue = new NodeWithLink <EquatableMock>(null); LoopSingleLinkList <EquatableMock> list = new LoopSingleLinkList <EquatableMock>(sequence); list.AddFirst(existValue.Value); list.AddLast(existValue); // Act NodeWithLink <EquatableMock> found = list.FindLast(existValue.Value); // Assert Assert.Same(existValue, found); }
public static void checkValueType() { Console.WriteLine("Проверка value type\n"); var list = new LoopSingleLinkList <int>(); list.Save += SaveList <int>; try { list.AddFirst(3); list.AddFirst(2); list.AddFirst(new NodeWithLink <int>(1)); list.AddLast(4); NodeWithLink <int> node = list.Find(3); list.AddAfter(node, 5); } catch (Exception ex) { Console.WriteLine($"Исключение: {ex.Message}"); Console.WriteLine($"Метод: {ex.TargetSite}"); Console.WriteLine($"Трассировка стека: {ex.StackTrace}"); } Console.WriteLine($"First: {list.First?.Value} Last: {list.Last?.Value}"); Console.WriteLine($"Есть 5: {list.Contains(5)} \nЕсть 6: {list.Contains(6)}"); Console.WriteLine($"Длина: {list.Length}"); //var a = list.First; //a.Next = null; ShowList(list); Console.WriteLine($"\nУдалено 1: {list.Remove(1)} \nFirst: {list.First?.Value} Last: {list.Last?.Value} Длина: {list.Length}"); ShowList(list); Console.WriteLine($"\nУдалено 4: {list.Remove(4)} \nFirst: {list.First?.Value} Last: {list.Last?.Value} Длина: {list.Length}"); ShowList(list); Console.WriteLine($"\nУдалено 10: {list.Remove(10)}"); ShowList(list); list.Clear(); }
public static void checkReferenceType() { Console.WriteLine("Проверка reference type\n"); var list = new LoopSingleLinkList <Person>(); list.Save += SaveList <Person>; try { list.AddFirst(new Person("Serhii", "Yanchuk", "*****@*****.**")); list.AddFirst(new Person("Serhii", "Yanchuk", "*****@*****.**")); list.AddFirst(new NodeWithLink <Person>(new Person("Serhii", "Yanchuk", "*****@*****.**"))); list.AddLast(new Person("Serhii", "Yanchuk", "*****@*****.**")); NodeWithLink <Person> node = list.Find(new Person("Serhii", "Yanchuk", "*****@*****.**")); list.AddAfter(node, 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($"Есть 5: {list.Contains(new Person("Serhii", "Yanchuk", "*****@*****.**"))} \nЕсть 6: {list.Contains(new Person("Serhii", "Yanchuk", "*****@*****.**"))}"); Console.WriteLine($"Длина: {list.Length}"); ShowList(list); Console.WriteLine($"\nУдалено 1: {list.Remove(new Person("Serhii", "Yanchuk", "*****@*****.**"))} \nFirst: {list.First?.Value} \nLast: {list.Last?.Value} Длина: {list.Length}"); ShowList(list); Console.WriteLine($"\nУдалено 4: {list.Remove(new Person("Serhii", "Yanchuk", "*****@*****.**"))} \nFirst: {list.First?.Value} \nLast: {list.Last?.Value} Длина: {list.Length}"); ShowList(list); Console.WriteLine($"\nУдалено 10: {list.Remove(new Person("Serhii", "Yanchuk", "*****@*****.**"))}"); ShowList(list); list.Clear(); }