Esempio n. 1
0
        public void AddAtDifferentPlacesTest()
        {
            var myLinkedList = new MyDoublyLinkedList();

            myLinkedList.AddAtHead(7);
            myLinkedList.AddAtHead(2);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtHead(1);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtIndex(3, 0);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.DeleteAtIndex(2);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtHead(6);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtTail(4);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.Get(4).Should().Be(4);
            myLinkedList.AddAtHead(4);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtIndex(5, 0);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtHead(6);
            ValidateDoublyLinkedList(myLinkedList);
        }
Esempio n. 2
0
        public static void AddAtHeadDeleteAt0Test()
        {
            var myLinkedList = new MyDoublyLinkedList();

            myLinkedList.AddAtHead(1);
            myLinkedList.DeleteAtIndex(0);

            myLinkedList.Value.Should().Be(-1);
            myLinkedList.Next.Should().BeNull();
            myLinkedList.Prev.Should().BeNull();
        }
Esempio n. 3
0
        public void AddAtHeadAtTailAtIndexTest()
        {
            var myLinkedList = new MyDoublyLinkedList();

            myLinkedList.AddAtHead(1);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtTail(3);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtIndex(1, 2); // linked list becomes 1->2->3
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.Get(1).Should().Be(2); // return 2
            myLinkedList.DeleteAtIndex(1);      // now the linked list is 1->3
            myLinkedList.Get(1).Should().Be(3); // return 3
        }
Esempio n. 4
0
        public void DeleteAtIndex0Test()
        {
            var myLinkedList = new MyDoublyLinkedList();

            myLinkedList.AddAtHead(1);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtTail(3);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.AddAtIndex(1, 2);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.Get(1).Should().Be(2);
            myLinkedList.DeleteAtIndex(0);
            ValidateDoublyLinkedList(myLinkedList);

            myLinkedList.Get(0).Should().Be(2);
        }