コード例 #1
0
        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);
        }
コード例 #2
0
        public void Remove_RemoveNotExistNodeFromList_TrueReturned()
        {
            // Arrange
            LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1, 2, 3, 4);
            // Act
            bool isDeleted = list.Remove(0);

            // Assert
            Assert.False(isDeleted);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void Remove_RemoveNotExistNodeFromList_FalseReturned()
        {
            // Arrange
            NodeWithLink <T>[]     sequence = CreateSequenceOfFiveNodes();
            LoopSingleLinkList <T> list     = new LoopSingleLinkList <T>(sequence);
            T removeValue = CreateSampleNode().Value;
            // Act
            bool isDeleted = list.Remove(removeValue);

            // Assert
            Assert.False(isDeleted);
        }
コード例 #5
0
        public void Remove_RemoveExistNodeFromListWithOneNode_TrueReturned()
        {
            // Arrange
            LoopSingleLinkList <int> list = new LoopSingleLinkList <int>(1);
            // Act
            bool isDeleted = list.Remove(1);

            // Assert
            Assert.True(isDeleted);
            Assert.Null(list.First);
            Assert.Null(list.Last);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void Remove_RemoveLastNodeFromList_TrueReturned()
        {
            // Arrange
            NodeWithLink <T>[]     sequence = CreateSequenceOfFiveNodes();
            NodeWithLink <T>       node4    = sequence[sequence.Length - 2];
            NodeWithLink <T>       node5    = sequence[sequence.Length - 1];
            LoopSingleLinkList <T> list     = new LoopSingleLinkList <T>(sequence);
            T removeValue = node5.Value;
            // Act
            bool isDeleted = list.Remove(removeValue);

            // Assert
            Assert.True(isDeleted);
            Assert.Same(node4, list.Last);
            Assert.Same(list.First, node4?.Next);
        }
コード例 #13
0
        public void Remove_RemoveExistMiddleNodeFromListValueType_TrueReturned()
        {
            // 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
            bool isDeleted = list.Remove(removeValue);

            // Assert
            Assert.True(isDeleted);
            Assert.Same(node3, node1?.Next);
        }
コード例 #14
0
        public void Remove_RemoveExistMiddleNodeFromListReferenceType_TrueReturned()
        {
            // 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"));
            NodeWithLink <Person>       node4 = new NodeWithLink <Person>(new Person("s4", "y4"));
            LoopSingleLinkList <Person> list  = new LoopSingleLinkList <Person>(node1, node2, node3, node4);
            Person temp = new Person("s3", "y3");
            // Act
            bool isDeleted = list.Remove(temp);

            // Assert
            Assert.True(isDeleted);
            Assert.Same(node4, node2?.Next);
        }
コード例 #15
0
        public void Remove_RemoveFirstNodeFromList_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(1);

            // Assert
            Assert.True(isDeleted);
            Assert.Same(node2, list.First);
            Assert.Same(node2, list.Last?.Next);
        }
コード例 #16
0
        public void Remove_RemoveExistMiddleNodeWithNullValueFromList_TrueReturned()
        {
            // Arrange
            NodeWithLink <EquatableMock>[] sequence = CreateSequenceOfFiveNodes();
            NodeWithLink <EquatableMock>   node1    = sequence[0];
            NodeWithLink <EquatableMock>   node3    = sequence[2];
            NodeWithLink <EquatableMock>   node2    = new NodeWithLink <EquatableMock>(null);

            sequence[1] = node2;
            LoopSingleLinkList <EquatableMock> list = new LoopSingleLinkList <EquatableMock>(sequence);
            EquatableMock removeValue = node2.Value;
            // Act
            bool isDeleted = list.Remove(removeValue);

            // Assert
            Assert.True(isDeleted);
            Assert.Same(node3, node1?.Next);
        }