示例#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());
        }
示例#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);
        }
示例#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));
        }
示例#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());
        }
示例#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));
        }
示例#6
0
        public void Enumeration_ReturnsSelf()
        {
            var node = LinkedListNode <char> .Create("A");

            Debug.Assert(node != null);

            TestHelper.AssertSequence(node,
                                      node);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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());
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#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));
        }
示例#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);
        }
示例#26
0
        public void Create_ReturnsNull_ForEmptySequence()
        {
            var head = LinkedListNode <int> .Create(new int[] { });

            Assert.IsNull(head);
        }