public virtual void TestCheck()
        {
            Random rnd = Random;

            ISet<object> jdk = Collections.NewSetFromMap<object, bool?>(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 = Collections.NewSetFromMap<object, bool?>(new IdentityHashMap<object, bool?>());
            foreach (object o in us)
            {
                collected.Add(o);
            }

            assertEquals(collected, jdk);
        }
Exemple #2
0
        public virtual void TestCheck()
        {
            Random rnd = Random;

            ISet <object> jdk = new JCG.HashSet <object>(IdentityEqualityComparer <object> .Default);

            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 = new JCG.HashSet <object>(IdentityEqualityComparer <object> .Default);

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

            // LUCENENET: We have 2 J2N hashsets, so no need to use aggressive mode
            assertEquals(collected, jdk, aggressive: false);
        }