Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //var list2 = new LoopSingleLinkList<int>();
            //NodeWithLink<int> n = null;
            //var list2 = new LoopSingleLinkList<int>(1, 2, 3);
            //ShowList(list2);

            checkValueType();
            Console.WriteLine("\n");
            checkReferenceType();
            Console.WriteLine("\n");
            checkReferenceTypeWithNull();
            Console.WriteLine("\n");

            Console.WriteLine("Пустая коллекция:");
            var list = new LoopSingleLinkList <int>();

            ShowList(list);

            Console.WriteLine("\n");
            Console.WriteLine("Коллекция с одного элемента:");
            list.AddFirst(1);
            ShowList(list);

            Console.ReadKey();
        }
        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 AddFirst_NodeAddFirstInList_LengthUp1()
        {
            // Arrange
            LoopSingleLinkList <T> list  = new LoopSingleLinkList <T>();
            NodeWithLink <T>       first = CreateSampleNode();

            // Act
            list.AddFirst(first);
            // Assert
            Assert.Equal(1, list.Length);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
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();
        }
        public void AddFirst_NodeAddFirstInEmptyList_NodeAdded()
        {
            // Arrange
            LoopSingleLinkList <T> list  = new LoopSingleLinkList <T>();
            NodeWithLink <T>       first = CreateSampleNode();

            // Act
            list.AddFirst(first);
            // Assert
            Assert.Same(first, list.First);
            Assert.Same(first, list.Last);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void AddFirst_NodeWithValueTypeElementAddFirstInEmptyList_NodeAdded()
        {
            // Arrange
            LoopSingleLinkList <int> list  = new LoopSingleLinkList <int>();
            NodeWithLink <int>       first = new NodeWithLink <int>(1);

            // Act
            list.AddFirst(first);
            // Assert
            Assert.Same(first, list.First);
            Assert.Same(first, list.Last);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        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 AddFirst_NodeAddFirstInNotEmptyList_NodeAdded()
        {
            // Arrange
            NodeWithLink <T>[]     sequence = CreateSequenceOfFiveNodes();
            LoopSingleLinkList <T> list     = new LoopSingleLinkList <T>(sequence);
            NodeWithLink <T>       first    = list.First;
            NodeWithLink <T>       newFirst = CreateSampleNode();

            // Act
            list.AddFirst(newFirst);
            // Assert
            Assert.Same(newFirst, list.First);
            Assert.Same(newFirst, list.Last?.Next);
            Assert.Same(first, newFirst?.Next);
        }
Exemplo n.º 12
0
        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);
        }