示例#1
0
        public void UnitRb_oReset()
        {
            var rb = new RankedBag <int> {
                Capacity = 4
            };
            var ia = new int[] { 1, 2, 2, 5, 8, 8, 9 };

            foreach (var x in ia)
            {
                rb.Add(x);
            }

            var etor = rb.GetEnumerator();

            int ix1 = 0;

            while (etor.MoveNext())
            {
                Assert.AreEqual(ia[ix1], etor.Current);
                ++ix1;
            }
            Assert.AreEqual(ia.Length, ix1);

            ((System.Collections.IEnumerator)etor).Reset();

            int ix2 = 0;

            while (etor.MoveNext())
            {
                Assert.AreEqual(ia[ix2], etor.Current);
                ++ix2;
            }
            Assert.AreEqual(ia.Length, ix2);
        }
示例#2
0
        public void UnitRb_GetEnumerator()
        {
            var rb = new RankedBag <int> {
                Capacity = 4
            };

            for (int ii = 0; ii < 10; ++ii)
            {
                rb.Add(ii);
            }

            var etor = rb.GetEnumerator();

            int ix = 0;

            while (etor.MoveNext())
            {
                int    gActual = etor.Current;
                object oActual = ((System.Collections.IEnumerator)etor).Current;
                Assert.AreEqual(ix, gActual);
                Assert.AreEqual(ix, oActual);
                ++ix;
            }
            Assert.AreEqual(10, ix);

            int gActualEnd = etor.Current;

            Assert.AreEqual(default(int), gActualEnd);

            bool isValid = etor.MoveNext();

            Assert.IsFalse(isValid);
        }
示例#3
0
        public void UnitRb_EtorCurrentHotUpdate()
        {
            var rb1 = new RankedBag <int> {
                2
            };
            var etor1 = rb1.GetEnumerator();

            Assert.AreEqual(default(int), etor1.Current);
            bool ok1 = etor1.MoveNext();

            Assert.IsTrue(ok1);
            Assert.AreEqual(2, etor1.Current);
            rb1.Remove(2);
            Assert.AreEqual(2, etor1.Current);

            var rb2 = new RankedBag <string> {
                "BB"
            };
            var etor2 = rb2.GetEnumerator();

            Assert.AreEqual(default(string), etor2.Current);
            bool ok2 = etor2.MoveNext();

            Assert.AreEqual("BB", etor2.Current);
            rb2.Clear();
            Assert.AreEqual("BB", etor2.Current);
        }
示例#4
0
        public void CrashRb_EtorOverflow_InvalidOperation()
        {
            var rb = new RankedBag <int> {
                Capacity = 4
            };

            for (int ii = 0; ii < 10; ++ii)
            {
                rb.Add(ii);
            }

            var etor = rb.GetEnumerator();

            while (etor.MoveNext())
            {
            }

            var val = ((System.Collections.IEnumerator)etor).Current;
        }