Esempio n. 1
0
        public void GetKnotNode_ReturnsNull_IfTheListIsNotKnotted_3()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2, 3 });

            Debug.Assert(head != null);

            Assert.IsNull(head.GetKnotNode());
        }
Esempio n. 2
0
        public void Create_ReturnsOneValidNode_ForSequenceOfOne()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Assert.NotNull(head);
            Assert.AreEqual(1, head.Value);
            Assert.IsNull(head.Next);
        }
Esempio n. 3
0
        public void GetIntersectionNode_ReturnsFirstNode_IfSelfChecking_1()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            Assert.AreSame(head, head.GetIntersectionNode(head));
        }
Esempio n. 4
0
        public void GetKnotNode_ReturnsHead_IfKnot()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);
            head.Next = head;

            Assert.AreSame(head, head.GetKnotNode());
        }
Esempio n. 5
0
        public void GetIntersectionNode_ReturnsMiddleNode_IfSelfChecking_ByMiddle()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2, 3 });

            Debug.Assert(head != null);
            Debug.Assert(head.Next != null);

            Assert.AreSame(head.Next, head.GetIntersectionNode(head.Next));
        }
Esempio n. 6
0
        public void Enumeration_ReturnsSelf()
        {
            var node = LinkedListNode <char> .Create("A");

            Debug.Assert(node != null);

            TestHelper.AssertSequence(node,
                                      node);
        }
Esempio n. 7
0
        public void Create_ReturnsTwoValidNodes_ForSequenceOfTwo()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Assert.NotNull(head);
            Assert.AreEqual(1, head.Value);
            Assert.IsNotNull(head.Next);
            Assert.AreEqual(2, head.Next.Value);
        }
Esempio n. 8
0
        public void GetLength_ReturnsOne_ForSingleNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            var result = head.GetLength();

            Assert.AreEqual(1, result);
        }
Esempio n. 9
0
        public void GetLength_ReturnsTwo_ForTwoNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);

            var result = head.GetLength();

            Assert.AreEqual(2, result);
        }
Esempio n. 10
0
        public void GetTailNode_ReturnsFirstNode_ForSingleNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            var tail = head.GetTailNode();

            Assert.AreSame(head, tail);
        }
Esempio n. 11
0
        public void TryGetMiddleAndTailNodes_ReturnsTwo_ForTwoNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);

            var result = head.TryGetMiddleAndTailNodes(out _, out _);

            Assert.AreEqual(2, result);
        }
Esempio n. 12
0
        public void GetTailNode_ReturnsSecondNode_ForTwoNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);

            var tail = head.GetTailNode();

            Assert.AreSame(head.Next, tail);
        }
Esempio n. 13
0
        public void TryGetMiddleAndTailNodes_ReturnsSecondNode_AsTail_ForTwoNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);

            head.TryGetMiddleAndTailNodes(out _, out var tail);

            Assert.AreSame(head.Next, tail);
        }
Esempio n. 14
0
        public void TryGetMiddleAndTailNodes_ReturnsSecondNode_AsMiddle_ForThreeNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2, 3 });

            Debug.Assert(head != null);

            head.TryGetMiddleAndTailNodes(out var middle, out _);

            Assert.AreSame(head.Next, middle);
        }
Esempio n. 15
0
        public void TryGetMiddleAndTailNodes_ReturnsFirstNode_AsTail_ForSingleNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            head.TryGetMiddleAndTailNodes(out _, out var tail);

            Assert.AreSame(head, tail);
        }
Esempio n. 16
0
        public void GetMiddleNode_ReturnsSecondNode_ForThreeNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2, 3 });

            Debug.Assert(head != null);

            var result = head.GetMiddleNode();

            Assert.AreSame(head.Next, result);
        }
Esempio n. 17
0
        public void GetMiddleNode_ReturnsFirstNode_ForTwoNodeList()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);

            var result = head.GetMiddleNode();

            Assert.AreSame(head, result);
        }
Esempio n. 18
0
        public void Reverse_DoesNothing_ForSingleNode()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            var newHead = head.Reverse();

            Assert.AreSame(head, newHead);
            Assert.IsNull(newHead.Next);
        }
Esempio n. 19
0
        public void GetKnotNode_ReturnsSecond_IfKnot()
        {
            var head = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(head != null);
            Debug.Assert(head.Next != null);

            head.Next.Next = head;

            Assert.That(head.Next == head.GetKnotNode());
        }
Esempio n. 20
0
        public void TryGetMiddleAndTailNodes_ReturnsMinusOne_ForSingleKnottedNode()
        {
            var head = LinkedListNode <int> .Create(new[] { 1 });

            Debug.Assert(head != null);

            head.Next = head;

            var len = head.TryGetMiddleAndTailNodes(out _, out _);

            Assert.AreEqual(-1, len);
        }
Esempio n. 21
0
        public void GetIntersectionNode_ReturnsTheProperNode_3()
        {
            var list1 = LinkedListNode <int> .Create(new[] { 1, 2, 3, 4, 5 });

            Debug.Assert(list1 != null);

            var list2 = LinkedListNode <int> .Create(new[] { 6 });

            Debug.Assert(list2 != null);

            list2.Next = list1.GetTailNode();

            Assert.IsTrue(list1.GetIntersectionNode(list2) == list2.Next);
        }
Esempio n. 22
0
        public void Enumeration_ReturnsSequence()
        {
            var head = LinkedListNode <char> .Create("ALEX");

            Debug.Assert(head != null);
            Debug.Assert(head.Next != null);
            Debug.Assert(head.Next.Next != null);

            TestHelper.AssertSequence(head,
                                      head,
                                      head.Next,
                                      head.Next.Next,
                                      head.Next.Next.Next);
        }
Esempio n. 23
0
        public void GetIntersectionNode_ReturnsTheProperNode_1()
        {
            var list1 = LinkedListNode <int> .Create(new[] { 1, 2, 3, 4, 5 });

            Debug.Assert(list1 != null);

            var list2 = LinkedListNode <int> .Create(new[] { 12 });

            Debug.Assert(list2 != null);

            list2.Next = list1.Next;

            Assert.AreSame(list1.Next, list2.GetIntersectionNode(list1));
        }
Esempio n. 24
0
        public void GetIntersectionNode_ReturnsTheProperNode_2()
        {
            var list1 = LinkedListNode <int> .Create(new[] { 1, 2, 3, 4, 5 });

            Debug.Assert(list1 != null);

            var list2 = LinkedListNode <int> .Create(new[] { 11, 12, 13, 14, 15, 16 });

            Debug.Assert(list2 != null);

            list2.GetTailNode().Next = list1.GetMiddleNode();

            Assert.AreSame(list1.GetMiddleNode(), list2.GetIntersectionNode(list1));
        }
Esempio n. 25
0
        public void Reverse_Reverses_AListOfTwo()
        {
            var e1 = LinkedListNode <int> .Create(new[] { 1, 2 });

            Debug.Assert(e1 != null);
            var e2 = e1.Next;

            Debug.Assert(e2 != null);

            var newHead = e1.Reverse();

            Assert.AreSame(e2, newHead);
            Assert.AreSame(e2.Next, e1);
            Assert.IsNull(e1.Next);
        }
Esempio n. 26
0
        public void Create_ReturnsNull_ForEmptySequence()
        {
            var head = LinkedListNode <int> .Create(new int[] { });

            Assert.IsNull(head);
        }