Пример #1
0
        public virtual void SetUp()
        {
            float maxF         = LightWeightHashSet.DefaultMaxLoadFactor;
            float minF         = LightWeightHashSet.DefautMinLoadFactor;
            int   initCapacity = LightWeightHashSet.MinimumCapacity;

            rand = new Random(Time.Now());
            list.Clear();
            for (int i = 0; i < Num; i++)
            {
                list.AddItem(rand.Next());
            }
            set = new LightWeightHashSet <int>(initCapacity, maxF, minF);
        }
Пример #2
0
        public virtual void TestGetElement()
        {
            LightWeightHashSet <TestLightWeightHashSet.TestObject> objSet = new LightWeightHashSet
                                                                            <TestLightWeightHashSet.TestObject>();

            TestLightWeightHashSet.TestObject objA = new TestLightWeightHashSet.TestObject("object A"
                                                                                           );
            TestLightWeightHashSet.TestObject equalToObjA = new TestLightWeightHashSet.TestObject
                                                                ("object A");
            TestLightWeightHashSet.TestObject objB = new TestLightWeightHashSet.TestObject("object B"
                                                                                           );
            objSet.AddItem(objA);
            objSet.AddItem(objB);
            NUnit.Framework.Assert.AreSame(objA, objSet.GetElement(objA));
            NUnit.Framework.Assert.AreSame(objA, objSet.GetElement(equalToObjA));
            NUnit.Framework.Assert.AreSame(objB, objSet.GetElement(objB));
            NUnit.Framework.Assert.IsNull(objSet.GetElement(new TestLightWeightHashSet.TestObject
                                                                ("not in set")));
        }
Пример #3
0
        public virtual void TestCapacity()
        {
            Log.Info("Test capacity");
            float maxF = LightWeightHashSet.DefaultMaxLoadFactor;
            float minF = LightWeightHashSet.DefautMinLoadFactor;

            // capacity lower than min_capacity
            set = new LightWeightHashSet <int>(1, maxF, minF);
            NUnit.Framework.Assert.AreEqual(LightWeightHashSet.MinimumCapacity, set.GetCapacity
                                                ());
            // capacity not a power of two
            set = new LightWeightHashSet <int>(30, maxF, minF);
            NUnit.Framework.Assert.AreEqual(Math.Max(LightWeightHashSet.MinimumCapacity, 32),
                                            set.GetCapacity());
            // capacity valid
            set = new LightWeightHashSet <int>(64, maxF, minF);
            NUnit.Framework.Assert.AreEqual(Math.Max(LightWeightHashSet.MinimumCapacity, 64),
                                            set.GetCapacity());
            // add NUM elements
            Sharpen.Collections.AddAll(set, list);
            int expCap = LightWeightHashSet.MinimumCapacity;

            while (expCap < Num && maxF * expCap < Num)
            {
                expCap <<= 1;
            }
            NUnit.Framework.Assert.AreEqual(expCap, set.GetCapacity());
            // see if the set shrinks if we remove elements by removing
            set.Clear();
            Sharpen.Collections.AddAll(set, list);
            int toRemove = set.Count - (int)(set.GetCapacity() * minF) + 1;

            for (int i = 0; i < toRemove; i++)
            {
                set.Remove(list[i]);
            }
            NUnit.Framework.Assert.AreEqual(Math.Max(LightWeightHashSet.MinimumCapacity, expCap
                                                     / 2), set.GetCapacity());
            Log.Info("Test capacity - DONE");
        }
Пример #4
0
 internal LinkedSetIterator(LightWeightHashSet <T> _enclosing)
 {
     this._enclosing = _enclosing;
 }