public void Contains_ContainsNotExistNodeWithSpecificValue_FalseReturned()
        {
            // Arrange
            LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2, 3, 4, 5);
            // Act
            bool isFound = list.Contains(0);

            // Assert
            Assert.False(isFound);
        }
        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 void Contains_ContainsNotExistNodeWithSpecificValue_TrueReturned()
        {
            // Arrange
            NodeWithLink <T>[]     sequence = CreateSequenceOfFiveNodes();
            LoopSingleLinkList <T> list     = new LoopSingleLinkList <T>(sequence);
            T notExistValue = CreateSampleNode().Value;
            // Act
            bool isFound = list.Contains(notExistValue);

            // Assert
            Assert.False(isFound);
        }
示例#4
0
        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 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();
        }