Esempio n. 1
0
        public virtual void TestCheck()
        {
            Random        rnd = Random();
            ISet <object> jdk = CollectionsHelper.NewSetFromMap(new IdentityHashMap <object, bool?>());

            RamUsageEstimator.IdentityHashSet <object> us = new RamUsageEstimator.IdentityHashSet <object>();

            int max       = 100000;
            int threshold = 256;

            for (int i = 0; i < max; i++)
            {
                // some of these will be interned and some will not so there will be collisions.
                int?v = rnd.Next(threshold);

                bool e1 = jdk.Contains(v);
                bool e2 = us.Contains(v);
                Assert.AreEqual(e1, e2);

                e1 = jdk.Add(v);
                e2 = us.Add(v);
                Assert.AreEqual(e1, e2);
            }

            ISet <object> collected = CollectionsHelper.NewSetFromMap(new IdentityHashMap <object, bool?>());

            foreach (object o in us)
            {
                collected.Add(o);
            }

            Assert.AreEqual(collected, jdk);
        }