Example #1
0
        public void RemoveSpecificNodeDoesntExist()
        {
            LListSingle ll     = new LListSingle();
            Node        first  = new Node("First");
            Node        second = new Node("Second");
            Node        third  = new Node("Third");
            Node        fourth = new Node("Fourth");

            ll.Add(first);
            ll.Add(second);
            ll.Add(third);
            ll.Add(fourth);

            var removed = new Node("setup");

            try
            {
                removed = ll.RemoveNode("Bob");
            }
            catch
            {
                removed = null;
            }
            Assert.Null(removed);
        }
Example #2
0
        public void RemoveNodeFromFrontOfList()
        {
            LListSingle ll     = new LListSingle(new Node("first"));
            Node        second = new Node("second");
            Node        third  = new Node("Third");

            ll.Add(second);
            ll.Add(third);

            var removed = ll.Remove();

            Assert.Equal(third, removed);
        }
Example #3
0
        public void RemoveSpecificNodeFromFrontIfHead()
        {
            LListSingle ll     = new LListSingle();
            Node        first  = new Node("First");
            Node        second = new Node("Second");
            Node        third  = new Node("Third");

            ll.Add(first);
            ll.Add(second);
            ll.Add(third);

            var removed = ll.RemoveNode("Third");

            Assert.Equal(third, removed);
        }
Example #4
0
        public void AddNodeBeforeWhereSpecifiedNodeIsTrue(string value)
        {
            Node        firstNode  = new Node("First");
            Node        secondNode = new Node("Second");
            Node        thirdNode  = new Node("Third");
            LListSingle ll         = new LListSingle(firstNode);

            ll.Add(secondNode);
            ll.Add(thirdNode);

            Node newNode      = new Node(value);
            var  IsSuccessful = ll.AddNodeBefore(newNode, firstNode);

            Assert.True(IsSuccessful);
            Assert.Equal(secondNode.Next, newNode);
        }
Example #5
0
        public void AddNodeAfterWhereSpecifiedNodeIsFalse(string value)
        {
            Node        firstNode  = new Node("First");
            Node        secondNode = new Node("Second");
            Node        thirdNode  = new Node("Third");
            Node        randomNode = new Node("Nope");
            LListSingle ll         = new LListSingle(firstNode);

            ll.Add(secondNode);
            ll.Add(thirdNode);

            Node newNode      = new Node(value);
            var  IsSuccessful = ll.AddNodeAfter(newNode, randomNode);

            Assert.False(IsSuccessful);
        }
Example #6
0
        public void FindSpecificNodeIsFalse()
        {
            LListSingle ll     = new LListSingle();
            Node        first  = new Node("First");
            Node        second = new Node("Second");
            Node        third  = new Node("Third");
            Node        fourth = new Node("Fourth");

            ll.Add(first);
            ll.Add(second);
            ll.Add(third);
            ll.Add(fourth);

            var find = ll.Find("Bob");

            Assert.False(find);
        }
Example #7
0
        public void AddNodeMethodUpdatesHead(string value)
        {
            LListSingle ll      = new LListSingle();
            Node        newNode = new Node(value);

            Assert.Null(ll.Head);
            ll.Add(newNode);
            Assert.Equal(value, ll.Head.Value);
        }
Example #8
0
        public void RemoveSpecificNodeFromList()
        {
            LListSingle ll     = new LListSingle();
            Node        first  = new Node("First");
            Node        second = new Node("Second");
            Node        third  = new Node("Third");
            Node        fourth = new Node("Fourth");

            ll.Add(first);
            ll.Add(second);
            ll.Add(third);
            ll.Add(fourth);

            var removed = ll.RemoveNode("Third");

            Assert.Equal(third, removed);
            Assert.Equal(second, ll.Head.Next);
        }
Example #9
0
        public void FindTheMiddleOfATheList()
        {
            Node        first  = new Node("First");
            LListSingle ll     = new LListSingle();
            Node        second = new Node("Second");
            Node        third  = new Node("Third");
            Node        fourth = new Node("Fourth");
            Node        fifth  = new Node("Fifth");

            ll.Add(first);
            ll.Add(second);
            ll.Add(third);
            ll.Add(fourth);
            ll.Add(fifth);

            var middle = ll.MiddleOfList();

            Assert.Equal(third, middle);
        }