Exemple #1
0
        public void Add_ClearRepeatedly()
        {
            const int Iterations = 2;
            const int Count      = 2;

            var hash = new HashtableEx();

            for (int i = 0; i < Iterations; i++)
            {
                for (int j = 0; j < Count; j++)
                {
                    string key   = "Key: i=" + i + ", j=" + j;
                    string value = "Value: i=" + i + ", j=" + j;
                    hash.Add(key, value);
                }

                Assert.AreEqual(Count, hash.Count);
                hash.Clear();
            }
        }
Exemple #2
0
        private static void VerifyHashtable(ComparableHashtable hash1, HashtableEx hash2, IEqualityComparer ikc)
        {
            if (hash2 == null)
            {
                Assert.AreEqual(0, hash1.Count);
            }
            else
            {
                // Make sure that construtor imports all keys and values
                Assert.AreEqual(hash2.Count, hash1.Count);
                for (int i = 0; i < 100; i++)
                {
                    Assert.IsTrue(hash1.ContainsKey(i));
                    Assert.IsTrue(hash1.ContainsValue(i));
                }

                // Make sure the new and old hashtables are not linked
                hash2.Clear();
                for (int i = 0; i < 100; i++)
                {
                    Assert.IsTrue(hash1.ContainsKey(i));
                    Assert.IsTrue(hash1.ContainsValue(i));
                }
            }

            Assert.AreEqual(ikc, hash1.EqualityComparer);

            Assert.IsFalse(hash1.IsFixedSize);
            Assert.IsFalse(hash1.IsReadOnly);
            Assert.IsFalse(hash1.IsSynchronized);

            // Make sure we can add to the hashtable
            int count = hash1.Count;

            for (int i = count; i < count + 100; i++)
            {
                hash1.Add(i, i);
                Assert.IsTrue(hash1.ContainsKey(i));
                Assert.IsTrue(hash1.ContainsValue(i));
            }
        }
 internal void Clear()
 => _entries.Clear();