コード例 #1
0
        public void UnitRb_Remove1()
        {
            var rb0 = new RankedBag <int>();
            var rb  = new RankedBag <int> {
                Capacity = 4
            };

            foreach (int ii in new int[] { 3, 5, 5, 7, 7, 7, 9 })
            {
                rb.Add(ii);
            }

            bool rem0 = rb0.Remove(0);

            Assert.IsFalse(rem0);

            bool rem2 = rb.Remove(2);

            Assert.IsFalse(rem2);

            bool rem7 = rb.Remove(7);

            Assert.IsTrue(rem7);
            Assert.AreEqual(4, rb.Count);

            bool rem5 = rb.Remove(5);

            Assert.IsTrue(rem5);
            Assert.AreEqual(2, rb.Count);

            bool rem10 = rb.Remove(10);

            Assert.IsFalse(rem10);
        }
コード例 #2
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);
        }
コード例 #3
0
        static void Main()
        {
            bag = new RankedBag <int>()
            {
                Capacity = 6
            };

            Console.WriteLine("Using Add (x), create tree of order 6:");
            for (int ii = 1; ii <= 6; ++ii)
            {
                bag.Add(3);
            }
            for (int ii = 1; ii <= 13; ++ii)
            {
                bag.Add(5);
            }
            for (int ii = 1; ii <= 7; ++ii)
            {
                bag.Add(7);
            }
            for (int ii = 1; ii <= 5; ++ii)
            {
                bag.Add(9);
            }
            WriteInfo();

            Console.WriteLine("Remove (5, 10):");
            bag.Remove(5, 13);
            WriteInfo();

            bag.Clear();
            Console.WriteLine("Using Add (x, n), create tree of order 6:");
            bag.Add(3, 6);
            bag.Add(5, 13);
            bag.Add(7, 7);
            bag.Add(9, 5);
            WriteInfo();
        }
コード例 #4
0
        public void CrashRbq_DistinctHotUpdate()
        {
            var rb = new RankedBag <int> {
                Capacity = 4
            };

            foreach (int ii in new int[] { 1, 1, 3, 5, 7, 9 })
            {
                rb.Add(ii);
            }
            int n = 0;

#if TEST_BCL
            foreach (var x in Enumerable.Distinct(rb))
#else
            foreach (var x in rb.Distinct())
#endif
            { if (++n == 2)
              {
                  rb.Remove(3);
              }
            }
        }
コード例 #5
0
        public void StressRbRemove()
        {
#if STRESS
            int m = 2, n = 50, x1 = 0, x2 = n;
#else
            int m = 2, n = 22, x1 = 15, x2 = x1;
#endif

            for (int x = x1; x <= x2; ++x)
            {
                var rb = new RankedBag <int>()
                {
                    Capacity = 4
                };
                var ex = new System.Collections.Generic.List <int>();

                for (int i = n; i >= 0; --i)
                {
                    rb.Add(i, m);
                    if (i != x)
                    {
                        ex.Insert(0, i); ex.Insert(0, i);
                    }
                }

                rb.Remove(x);
                var isOk = System.Linq.Enumerable.SequenceEqual(ex, rb);
                if (!isOk)
                {
                }

                Assert.IsTrue(System.Linq.Enumerable.SequenceEqual(ex, rb));
#if DEBUG
                rb.SanityCheck();
#endif
            }
        }
コード例 #6
0
        public void UnitRb_Remove2()
        {
            var rb0 = new RankedBag <int>();
            var rb1 = new RankedBag <int> {
                Capacity = 4
            };
            var rb2 = new RankedBag <int> {
                Capacity = 4
            };
            var rb3 = new RankedBag <int> {
                Capacity = 5
            };

            foreach (int ii in new int[] { 3, 5, 5, 7, 7, 7, 9 })
            {
                rb1.Add(ii);
            }

            foreach (int ii in new int[] { 3, 3, 3, 5, 5, 5, 7, 7, 7, 9 })
            {
                rb2.Add(ii);
            }

            for (int ii = 0; ii < 41; ++ii)
            {
                rb3.Add(ii / 5);
            }

            var rem0 = rb0.Remove(0, 1);

            Assert.AreEqual(0, rem0);

            var rem2 = rb1.Remove(2, 2);

            Assert.AreEqual(0, rem2);

            var rem70 = rb1.Remove(7, 0);

            Assert.AreEqual(0, rem70);

            var rem7 = rb1.Remove(7, 1);

            Assert.AreEqual(1, rem7);
            Assert.AreEqual(6, rb1.Count);

            var rem5 = rb1.Remove(5, 3);

            Assert.AreEqual(2, rem5);
            Assert.AreEqual(4, rb1.Count);

            var rem9 = rb1.Remove(10);

            Assert.IsFalse(rem9);

            var rem53 = rb2.Remove(5, 3);

            Assert.AreEqual(3, rem53);

            var rem33 = rb2.Remove(3, 3);

            Assert.AreEqual(3, rem33);

            var rem99 = rb2.Remove(9, 9);

            Assert.AreEqual(1, rem99);

            Assert.AreEqual(3, rb2.Count);

            var rem35 = rb3.Remove(3, 9);

            Assert.AreEqual(5, rem35);
            Assert.AreEqual(36, rb3.Count);
            Assert.IsFalse(rb3.Contains(3));

            var rem65 = rb3.Remove(6, Int32.MaxValue);

            Assert.AreEqual(5, rem65);
            Assert.AreEqual(31, rb3.Count);
            Assert.IsFalse(rb3.Contains(6));
        }
コード例 #7
0
        public void CrashRb_Remove2_Argument()
        {
            var rb = new RankedBag <int>();

            rb.Remove(1, -1);
        }