public virtual void TestRandom()
        {
            for (int i = 0; i < 10000; i++)
            {
                int initSz = Random().Next(20);
                int num = Random().Next(30);
                int maxVal = (Random().NextBoolean() ? Random().Next(50) : Random().Next(int.MaxValue)) + 1;

                HashSet<int> a = new HashSet<int>(/*initSz*/);
                SentinelIntSet b = new SentinelIntSet(initSz, -1);

                for (int j = 0; j < num; j++)
                {
                    int val = Random().Next(maxVal);
                    bool exists = !a.Add(val);
                    bool existsB = b.Exists(val);
                    Assert.AreEqual(exists, existsB);
                    int slot = b.Find(val);
                    Assert.AreEqual(exists, slot >= 0);
                    b.Put(val);

                    Assert.AreEqual(a.Count, b.Size());
                }
            }
        }
Esempio n. 2
0
        public virtual void TestRandom()
        {
            for (int i = 0; i < 10000; i++)
            {
                int initSz = Random().Next(20);
                int num    = Random().Next(30);
                int maxVal = (Random().NextBoolean() ? Random().Next(50) : Random().Next(int.MaxValue)) + 1;

                HashSet <int>  a = new HashSet <int>(/*initSz*/);
                SentinelIntSet b = new SentinelIntSet(initSz, -1);

                for (int j = 0; j < num; j++)
                {
                    int  val     = Random().Next(maxVal);
                    bool exists  = !a.Add(val);
                    bool existsB = b.Exists(val);
                    Assert.AreEqual(exists, existsB);
                    int slot = b.Find(val);
                    Assert.AreEqual(exists, slot >= 0);
                    b.Put(val);

                    Assert.AreEqual(a.Count, b.Size());
                }
            }
        }
 public virtual void Test()
 {
     SentinelIntSet set = new SentinelIntSet(10, -1);
     Assert.IsFalse(set.Exists(50));
     set.Put(50);
     Assert.IsTrue(set.Exists(50));
     Assert.AreEqual(1, set.Size());
     Assert.AreEqual(-11, set.Find(10));
     Assert.AreEqual(1, set.Size());
     set.Clear();
     Assert.AreEqual(0, set.Size());
     Assert.AreEqual(50, set.Hash(50));
     //force a rehash
     for (int i = 0; i < 20; i++)
     {
         set.Put(i);
     }
     Assert.AreEqual(20, set.Size());
     Assert.AreEqual(24, set.RehashCount);
 }
Esempio n. 4
0
        public virtual void Test()
        {
            SentinelIntSet set = new SentinelIntSet(10, -1);

            Assert.IsFalse(set.Exists(50));
            set.Put(50);
            Assert.IsTrue(set.Exists(50));
            Assert.AreEqual(1, set.Size());
            Assert.AreEqual(-11, set.Find(10));
            Assert.AreEqual(1, set.Size());
            set.Clear();
            Assert.AreEqual(0, set.Size());
            Assert.AreEqual(50, set.Hash(50));
            //force a rehash
            for (int i = 0; i < 20; i++)
            {
                set.Put(i);
            }
            Assert.AreEqual(20, set.Size());
            Assert.AreEqual(24, set.RehashCount);
        }