Example #1
0
        public void InsertItemsAtIndex()
        {
            AddToEmpty(10);

            // Insert 10 items at the front of the list
            for (int i = 20; i >= 11; i--)
            {
                testList.Insert(0, i);
            }

            Assert.AreEqual(20, testList.Count);

            // Verify the first 10 items are the inserted items
            int         iTest      = 11;
            IEnumerator enumerator = testList.GetEnumerator();

            while (iTest <= 20)
            {
                enumerator.MoveNext();
                int iList = (int)enumerator.Current;
                Assert.AreEqual(iTest, iList);
                iTest++;
            }

            // Verify that the last 10 items are the ones that were added originally
            iTest      = 10;
            enumerator = new ReverseEnumerator <int>(testList);
            while (iTest >= 1)
            {
                enumerator.MoveNext();
                int iList = (int)enumerator.Current;
                Assert.AreEqual(iTest, iList);
                iTest--;
            }
        }
Example #2
0
        public IEnumerable <T> Reverse()
        {
            ReverseEnumerator e = new ReverseEnumerator(this);

            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }
Example #3
0
        public void ReverseEnumeratorTest()
        {
            Assert.IsTrue(testList.Empty);
            AddToEmpty(10);

            int i       = 10;
            var reverse = new ReverseEnumerator <int>(testList);

            while (reverse.MoveNext())
            {
                Assert.AreEqual(i, reverse.Current);
                i--;
            }

            while (reverse.MovePrevious())
            {
                i++;
                Assert.AreEqual(i, reverse.Current);
            }

            Assert.AreEqual(10, i);  // Ran through all the scenarios
        }
Example #4
0
        public void AddItems()
        {
            AddToEmpty(10);

            // Verify the Forward Iterator
            int iTest = 1;

            foreach (int iList in testList)
            {
                Assert.AreEqual(iList, iTest);
                iTest++;
            }

            // Verify the Reverse Iterator
            iTest = 10;
            IEnumerator enumerator = new ReverseEnumerator <int>(testList);

            while (enumerator.MoveNext())
            {
                int iList = (int)enumerator.Current;
                Assert.AreEqual(iTest, iList);
                iTest--;
            }
        }