static void Main()
    {
        var list = new DoublyLinkedListExpanded <int>();

        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");

        list.AddLast(5);
        list.AddFirst(3);
        list.AddFirst(2);
        list.AddLast(10);
        Console.WriteLine("Count = {0}", list.Count);

        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");

        list.RemoveFirst();
        list.RemoveLast();
        list.RemoveFirst();

        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");

        list.RemoveLast();

        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");
        Console.WriteLine("2---------2--------2");
        list.AddLast(1);
        list.AddLast(2);
        list.AddLast(3);
        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");
        list[0] = 5;
        list[1] = 6;
        list[2] = 7;
        list.AddLast(8);
        list.AddLast(9);
        list.AddLast(10);
        list.ForEach(Console.WriteLine);
        Console.WriteLine("--------------------");
        list.InsertAt(20, 3);
        list.ForEach(Console.WriteLine);
        Console.WriteLine("3---------3--------3");
        Console.WriteLine(list.RemoveAt(4));
        Console.WriteLine("--------------------");
        list.ForEach(Console.WriteLine);
        Console.WriteLine("4---------4--------4");
        list.Clear();
        Console.WriteLine("--------------------");
        list.AddLast(8);
        list.AddLast(9);
        list.AddLast(10);
    }
Пример #2
0
        public void DLLe_Access_And_Change_DLLe_elemenets_like_array()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <string>();

            // Act
            list.AddFirst("10");
            list.AddFirst("20");
            list.AddFirst("30");

            // Assert
            Assert.AreEqual("10", list[2]);
            Assert.AreEqual("30", list[0]);
        }
Пример #3
0
        public void DLLe_Access_Like_Array_Before_Zero_ShouldThrowException()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            // Act
            list.AddFirst(5);
            var element = list[-1];
        }
Пример #4
0
        public void DLLe_AddFirst_SeveralElements_ShouldAddElementsCorrectly()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            // Act
            list.AddFirst(10);
            list.AddFirst(5);
            list.AddFirst(3);

            // Assert
            Assert.AreEqual(3, list.Count);

            var items = new List <int>();

            list.ForEach(items.Add);
            CollectionAssert.AreEqual(items, new List <int>()
            {
                3, 5, 10
            });
        }
Пример #5
0
        public void DLLe_RemoveLast_SeveralElements_ShouldRemoveElementsCorrectly()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            list.AddFirst(10);
            list.AddFirst(9);
            list.AddFirst(8);

            // Act
            var element = list.RemoveLast();

            // Assert
            Assert.AreEqual(10, element);
            Assert.AreEqual(2, list.Count);

            var items = new List <int>();

            list.ForEach(items.Add);
            CollectionAssert.AreEqual(items, new List <int>()
            {
                8, 9
            });
        }
Пример #6
0
        public void DLLe_AddFirst_EmptyList_ShouldAddElement()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            // Act
            list.AddFirst(5);

            // Assert
            Assert.AreEqual(1, list.Count);

            var items = new List <int>();

            list.ForEach(items.Add);
            CollectionAssert.AreEqual(items, new List <int>()
            {
                5
            });
        }
Пример #7
0
        public void DLLe_Insert_Element_Inside()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            // Act
            list.AddFirst(0);
            list.InsertAt(1, 0);
            list.InsertAt(2, 1);

            // Assert
            var items = new List <int>();

            list.ForEach(items.Add);
            CollectionAssert.AreEqual(items, new List <int>()
            {
                1, 2, 0
            });
        }
Пример #8
0
        public void DLLe_RemoveLast_OneElement_ShouldMakeListEmpty()
        {
            // Arrange
            var list = new DoublyLinkedListExpanded <int>();

            list.AddFirst(5);

            // Act
            var element = list.RemoveLast();

            // Assert
            Assert.AreEqual(5, element);
            Assert.AreEqual(0, list.Count);

            var items = new List <int>();

            list.ForEach(items.Add);
            CollectionAssert.AreEqual(items, new List <int>()
            {
            });
        }