Exemplo n.º 1
0
        public void OrderedListRandomisedTest()
        {
            Random rnd           = new Random();
            int    numOfElements = rnd.Next(100, 1000);

            var list = new OrderedLinkedList();

            //add in the numbers to the list
            for (int i = 0; i < numOfElements; i++)
            {
                list.Add(rnd.Next(1, 10000));
            }

            //now, check them for orderedness
            int iterations  = 1;
            var currentNode = list.Head();
            var nextNode    = list.GetNext();

            while (currentNode.Next != null)
            {
                nextNode = list.GetNext();

                if ((int)currentNode.Data > (int)nextNode.Data)
                {
                    Assert.Fail();
                }

                iterations++;
                currentNode = list.GetCurrentNode();
            }

            Assert.AreEqual(numOfElements, iterations + 1);
        }
Exemplo n.º 2
0
        public void OrderedTestAddInOrder()
        {
            var list = new OrderedLinkedList();

            list.Add(5);

            var headNode = list.Head();

            Assert.IsNotNull(headNode);
            Assert.AreEqual(5, headNode.Data);
            var currentNode = list.GetNext();

            Assert.AreEqual(currentNode, headNode);

            list.Add(7);
            headNode = list.Head();
            Assert.IsNotNull(headNode);
            Assert.AreEqual(5, headNode.Data);
            currentNode = list.GetNext();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(7, currentNode.Data);

            list.Add(9);
            headNode = list.Head();
            Assert.IsNotNull(headNode);
            Assert.AreEqual(5, headNode.Data);
            currentNode = list.GetNext();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(7, currentNode.Data);
            currentNode = list.GetNext();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(9, currentNode.Data);

            //remove Node test
            currentNode = list.Head();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(5, currentNode.Data);
            currentNode = list.GetNext();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(7, currentNode.Data);
            list.RemoveCurrentNode();
            currentNode = list.GetCurrentNode();
            Assert.IsNotNull(currentNode);
            Assert.AreEqual(9, currentNode.Data);
            currentNode = list.Head();
            Assert.AreEqual(5, currentNode.Data);
            currentNode = list.GetNext();
            Assert.AreEqual(9, currentNode.Data);
        }