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 Find_FindNotExistNodeWithSpecificValueType_NullNodeReturned()
        {
            // Arrange
            LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2, 3, 4, 5);
            // Act
            NodeWithLink <int> found = list.Find(0);

            // Assert
            Assert.Null(found);
        }
        public void Find_FindNotExistNodeWithSpecificValue_NullNodeReturned()
        {
            // Arrange
            NodeWithLink <T>[]     sequence = CreateSequenceOfFiveNodes();
            LoopSingleLinkList <T> list     = new LoopSingleLinkList <T>(sequence);
            T notExistValue = CreateSampleNode().Value;
            // Act
            NodeWithLink <T> found = list.Find(notExistValue);

            // Assert
            Assert.Null(found);
        }
        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 Find_FindNotExistNodeWithSpecificReferenceType_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.Find(temp);

            // Assert
            Assert.Null(found);
        }
示例#6
0
        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 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();
        }