public void Search_Success()
        {
            var head = new MockLinkedNode <int>(20)
            {
                Next = new MockLinkedNode <int>(10)
            };

            head.Next.Next = new MockLinkedNode <int>(12)
            {
            };
            head.Next.Next.Next = new MockLinkedNode <int>(6);

            var list   = new MockLinkedList <int>(head);
            var result = list.Search(20);

            Assert.IsNotNull(result);
            Assert.AreEqual(20, result.Value);

            result = list.Search(12);
            Assert.IsNotNull(result);
            Assert.AreEqual(12, result.Value);
        }
        public void Length()
        {
            var list = new MockLinkedList <int>();

            Assert.AreEqual(0, list.Count());

            var head = new MockLinkedNode <int>(10);

            list = new MockLinkedList <int>(head);
            Assert.AreEqual(1, list.Count());

            head.Next = new MockLinkedNode <int>(2);
            list      = new MockLinkedList <int>(head);
            Assert.AreEqual(2, list.Count());

            head.Next.Next = new MockLinkedNode <int>(20);
            list           = new MockLinkedList <int>(head);
            Assert.AreEqual(3, list.Count());

            head.Next.Next.Next = new MockLinkedNode <int>(3);
            list = new MockLinkedList <int>(head);
            Assert.AreEqual(4, list.Count());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="head">Head/starting node of the list. </param>
 public MockLinkedList(MockLinkedNode <T1> head)
 {
     _head = head;
 }