Пример #1
0
 public static void Ctor_HashCodeProvider_Comparer_NullInputs(bool nullProvider, bool nullComparer)
 {
     var hash = new ComparableHashtable(
         nullProvider ? null : CaseInsensitiveHashCodeProvider.DefaultInvariant,
         nullComparer ? null : StringComparer.OrdinalIgnoreCase);
     VerifyHashtable(hash, null, hash.EqualityComparer);
 }
Пример #2
0
        public void Ctor_IDictionary_IEqualityComparer()
        {
            RemoteInvoke(() =>
            {
                // No exception
                var hash1 = new ComparableHashtable(new Hashtable(), null);
                Assert.Equal(0, hash1.Count);

                hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(), null), null), null), null), null);
                Assert.Equal(0, hash1.Count);

                // Null comparer
                Hashtable hash2 = Helpers.CreateIntHashtable(100);
                hash1           = new ComparableHashtable(hash2, null);
                VerifyHashtable(hash1, hash2, null);

                // Custom comparer
                hash2 = Helpers.CreateIntHashtable(100);
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash1 = new ComparableHashtable(hash2, comparer);
                VerifyHashtable(hash1, hash2, comparer);

                return(SuccessExitCode);
            }).Dispose();
        }
Пример #3
0
        public static void Ctor_IDictionary_Int_IEqualityComparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), 1f, null);

            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(
                                                              new Hashtable(new Hashtable(new Hashtable(), 1f, null), 1f, null), 1f, null), 1f, null), 1f, null);
            Assert.Equal(0, hash1.Count);

            // Null comparer
            Hashtable hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2, 1f, null);
            VerifyHashtable(hash1, hash2, null);

            hash2 = Helpers.CreateIntHashtable(100);
            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash1 = new ComparableHashtable(hash2, 1f, comparer);
                VerifyHashtable(hash1, hash2, comparer);
            });
        }
Пример #4
0
 public static void Ctor_HashCodeProvider_Comparer()
 {
     var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
     VerifyHashtable(hash, null, hash.EqualityComparer);
     Assert.Same(CaseInsensitiveHashCodeProvider.DefaultInvariant, hash.HashCodeProvider);
     Assert.Same(StringComparer.OrdinalIgnoreCase, hash.Comparer);
 }
Пример #5
0
        public void Ctor_HashCodeProvider_Comparer_NullInputs(bool nullProvider, bool nullComparer)
        {
            var hash = new ComparableHashtable(
                nullProvider ? null : CaseInsensitiveHashCodeProvider.DefaultInvariant,
                nullComparer ? null : StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash, null, hash.EqualityComparer);
        }
Пример #6
0
        public void Ctor_HashCodeProvider_Comparer()
        {
            var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash, null, hash.EqualityComparer);
            Assert.Same(CaseInsensitiveHashCodeProvider.DefaultInvariant, hash.HashCodeProvider);
            Assert.Same(StringComparer.OrdinalIgnoreCase, hash.Comparer);
        }
Пример #7
0
        public void HashCodeProvider_Comparer_IncompatibleGetSet_Throws()
        {
            var hash = new ComparableHashtable(StringComparer.CurrentCulture);

            AssertExtensions.Throws <ArgumentException>(null, () => hash.HashCodeProvider);
            AssertExtensions.Throws <ArgumentException>(null, () => hash.Comparer);

            AssertExtensions.Throws <ArgumentException>(null, () => hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant);
            AssertExtensions.Throws <ArgumentException>(null, () => hash.Comparer         = StringComparer.OrdinalIgnoreCase);
        }
Пример #8
0
        public void Ctor_Int()
        {
            var hash = new ComparableHashtable(0);

            VerifyHashtable(hash, null);

            hash = new ComparableHashtable(10);
            VerifyHashtable(hash, null);

            hash = new ComparableHashtable(100);
            VerifyHashtable(hash, null);
        }
Пример #9
0
        public void Ctor_IEqualityComparer()
        {
            // Null comparer
            var hash = new ComparableHashtable((IEqualityComparer)null);

            VerifyHashtable(hash, null, null);

            // Custom comparer
            IEqualityComparer comparer = StringComparer.CurrentCulture;

            hash = new ComparableHashtable(comparer);
            VerifyHashtable(hash, null, comparer);
        }
Пример #10
0
        public static void TestCtor_IDictionary_LoadFactor()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), 1f);
            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(), 1f), 1f), 1f), 1f), 1f);
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = Helpers.CreateIntHashtable(100);
            hash1 = new ComparableHashtable(hash2, 1f);

            VerifyHashtable(hash1, hash2, null);
        }
Пример #11
0
        public void Ctor_Int_Int_IEqualityComparer(int capacity, float loadFactor)
        {
            // Null comparer
            var hash = new ComparableHashtable(capacity, loadFactor, null);

            VerifyHashtable(hash, null, null);
            Assert.Null(hash.EqualityComparer);

            // Custom compare
            IEqualityComparer comparer = StringComparer.CurrentCulture;

            hash = new ComparableHashtable(capacity, loadFactor, comparer);
            VerifyHashtable(hash, null, comparer);
        }
Пример #12
0
        public static void TestCtor_IEqualityComparer()
        {
            // Null comparer
            var hash = new ComparableHashtable((IEqualityComparer)null);
            VerifyHashtable(hash, null, null);

            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(comparer);
                VerifyHashtable(hash, null, comparer);
            });
        }
Пример #13
0
        public static void Ctor_IDictionary_HashCodeProvider_Comparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable())))), CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = Helpers.CreateIntHashtable(100);
            hash1 = new ComparableHashtable(hash2, CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash1, hash2, hash1.EqualityComparer);
        }
Пример #14
0
        public void Ctor_IDictionary()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable());

            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable());
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2);
            VerifyHashtable(hash1, hash2);
        }
Пример #15
0
        public static void Ctor_IEqualityComparer()
        {
            // Null comparer
            var hash = new ComparableHashtable((IEqualityComparer)null);

            VerifyHashtable(hash, null, null);

            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(comparer);
                VerifyHashtable(hash, null, comparer);
            });
        }
Пример #16
0
        public void Ctor_IDictionary()
        {
            // No exception
            var hash1 = new ComparableHashtable(new HashtableEx());

            Assert.AreEqual(0, hash1.Count);

            hash1 = new ComparableHashtable(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx())))));
            Assert.AreEqual(0, hash1.Count);

            HashtableEx hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2);

            VerifyHashtable(hash1, hash2, null);
        }
Пример #17
0
        public void Ctor_IDictionary_HashCodeProvider_Comparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable())))), CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2, CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash1, hash2, hash1.EqualityComparer);
        }
Пример #18
0
        public void Ctor_IEqualityComparer()
        {
            RemoteInvoke(() =>
            {
                // Null comparer
                var hash = new ComparableHashtable((IEqualityComparer)null);
                VerifyHashtable(hash, null, null);

                // Custom comparer
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(comparer);
                VerifyHashtable(hash, null, comparer);

                return(SuccessExitCode);
            }).Dispose();
        }
Пример #19
0
        public static void Ctor_Int_Int_IEqualityComparer(int capacity, float loadFactor)
        {
            // Null comparer
            var hash = new ComparableHashtable(capacity, loadFactor, null);

            VerifyHashtable(hash, null, null);
            Assert.Null(hash.EqualityComparer);

            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(capacity, loadFactor, comparer);
                VerifyHashtable(hash, null, comparer);
            });
        }
Пример #20
0
        public void Ctor_IDictionary_Int_HashCodeProvider_Comparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), 1f);

            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(), 1f), 1f), 1f), 1f), 1f);
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2, 1f);

            VerifyHashtable(hash1, hash2, null);
        }
Пример #21
0
        public void Ctor_IDictionary_Int()
        {
            // No exception
            var hash1 = new ComparableHashtable(new HashtableEx(), 1f, StringComparer.OrdinalIgnoreCase);

            Assert.AreEqual(0, hash1.Count);

            hash1 = new ComparableHashtable(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(), 1f), 1f), 1f), 1f), 1f,
                                            StringComparer.OrdinalIgnoreCase);
            Assert.AreEqual(0, hash1.Count);

            HashtableEx hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2, 1f, StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash1, hash2, hash1.EqualityComparer);
        }
Пример #22
0
        public void Ctor_Int_IEqualityComparer(int capacity)
        {
            RemoteInvoke((rcapacity) =>
            {
                int.TryParse(rcapacity, out int capacityint);

                // Null comparer
                var hash = new ComparableHashtable(capacityint, null);
                VerifyHashtable(hash, null, null);

                // Custom comparer
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(capacityint, comparer);
                VerifyHashtable(hash, null, comparer);
                return(SuccessExitCode);
            }, capacity.ToString()).Dispose();
        }
Пример #23
0
        public void HashCodeProvider_Comparer_CompatibleGetSet_Success()
        {
            var hash = new ComparableHashtable();

            Assert.Null(hash.HashCodeProvider);
            Assert.Null(hash.Comparer);

            hash = new ComparableHashtable();
            hash.HashCodeProvider = null;
            hash.Comparer         = null;

            hash                  = new ComparableHashtable();
            hash.Comparer         = null;
            hash.HashCodeProvider = null;

            hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
            hash.Comparer         = StringComparer.OrdinalIgnoreCase;
        }
Пример #24
0
        public void Ctor_Int_Int_GenerateNewPrime()
        {
            // The ctor for Hashtable performs the following calculation:
            // rawSize = capacity / (loadFactor * 0.72)
            // If rawSize is > 3, then it calls HashHelpers.GetPrime(rawSize) to generate a prime.
            // Then, if the rawSize > 7,199,369 (the largest number in a list of known primes), we have to generate a prime programatically
            // This test makes sure this works.
            int   capacity   = 8000000;
            float loadFactor = 0.1f / 0.72f;

            try
            {
                var hash = new ComparableHashtable(capacity, loadFactor);
            }
            catch (OutOfMemoryException)
            {
                // On memory constrained devices, we can get an OutOfMemoryException, which we can safely ignore.
            }
        }
Пример #25
0
        public void Comparer_Set_ImpactsSearch()
        {
            var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            hash.Add("test", "test");

            // Should be able to find with the same and different casing
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));

            // Changing the comparer, should only be able to find the matching case
            hash.Comparer = StringComparer.Ordinal;
            Assert.True(hash.ContainsKey("test"));
            Assert.False(hash.ContainsKey("TEST"));

            // Changing it back, should be able to find both again
            hash.Comparer = StringComparer.OrdinalIgnoreCase;
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));
        }
Пример #26
0
        public void Ctor_Int_Int_IEqualityComparer(int capacity, float loadFactor)
        {
            RemoteInvoke((rcapacity, rloadFactor) =>
            {
                int.TryParse(rcapacity, out int capacityint);
                float.TryParse(rloadFactor, out float loadFactorFloat);

                // Null comparer
                var hash = new ComparableHashtable(capacityint, loadFactorFloat, null);
                VerifyHashtable(hash, null, null);
                Assert.Null(hash.EqualityComparer);

                // Custom compare
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(capacityint, loadFactorFloat, comparer);
                VerifyHashtable(hash, null, comparer);

                return(SuccessExitCode);
            }, capacity.ToString(), loadFactor.ToString()).Dispose();
        }
Пример #27
0
        private static void VerifyHashtable(ComparableHashtable hash1, Hashtable hash2, IEqualityComparer ikc)
        {
            if (hash2 == null)
            {
                Assert.Equal(0, hash1.Count);
            }
            else
            {
                // Make sure that construtor imports all keys and values
                Assert.Equal(hash2.Count, hash1.Count);
                for (int i = 0; i < 100; i++)
                {
                    Assert.True(hash1.ContainsKey(i));
                    Assert.True(hash1.ContainsValue(i));
                }

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

            Assert.Equal(ikc, hash1.EqualityComparer);

            Assert.False(hash1.IsFixedSize);
            Assert.False(hash1.IsReadOnly);
            Assert.False(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.True(hash1.ContainsKey(i));
                Assert.True(hash1.ContainsValue(i));
            }
        }
Пример #28
0
        public void Ctor_IDictionary_IEqualityComparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new HashtableEx(), null);

            Assert.AreEqual(0, hash1.Count);

            hash1 = new ComparableHashtable(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(), null), null), null), null), null);
            Assert.AreEqual(0, hash1.Count);

            // Null comparer
            HashtableEx hash2 = Helpers.CreateIntHashtable(100);

            hash1 = new ComparableHashtable(hash2, null);
            VerifyHashtable(hash1, hash2, null);

            // Custom comparer
            hash2 = Helpers.CreateIntHashtable(100);
            IEqualityComparer comparer = StringComparer.CurrentCulture;

            hash1 = new ComparableHashtable(hash2, comparer);
            VerifyHashtable(hash1, hash2, comparer);
        }
Пример #29
0
        public void HashCodeProvider_Set_ImpactsSearch()
        {
            var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            hash.Add("test", "test");

            // Should be able to find with the same and different casing
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));

            // Changing the hash code provider, we shouldn't be able to find either
            hash.HashCodeProvider = new FixedHashCodeProvider
            {
                FixedHashCode = CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode("test") + 1
            };
            Assert.False(hash.ContainsKey("test"));
            Assert.False(hash.ContainsKey("TEST"));

            // Changing it back, should be able to find both again
            hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));
        }
Пример #30
0
 public static void Ctor_Int_Int_HashCodeProvider_Comparer(int capacity, float loadFactor)
 {
     var hash = new ComparableHashtable(capacity, loadFactor, CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
     VerifyHashtable(hash, null, hash.EqualityComparer);
 }
Пример #31
0
        public static void HashCodeProvider_Set_ImpactsSearch()
        {
            var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
            hash.Add("test", "test");

            // Should be able to find with the same and different casing
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));

            // Changing the hash code provider, we shouldn't be able to find either
            hash.HashCodeProvider = new FixedHashCodeProvider
            {
                FixedHashCode = CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode("test") + 1
            };
            Assert.False(hash.ContainsKey("test"));
            Assert.False(hash.ContainsKey("TEST"));

            // Changing it back, should be able to find both again
            hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));
        }
Пример #32
0
        public static void HashCodeProvider_Comparer_CompatibleGetSet_Success()
        {
            var hash = new ComparableHashtable();
            Assert.Null(hash.HashCodeProvider);
            Assert.Null(hash.Comparer);

            hash = new ComparableHashtable();
            hash.HashCodeProvider = null;
            hash.Comparer = null;

            hash = new ComparableHashtable();
            hash.Comparer = null;
            hash.HashCodeProvider = null;

            hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
            hash.Comparer = StringComparer.OrdinalIgnoreCase;
        }
Пример #33
0
        public static void HashCodeProvider_Comparer_IncompatibleGetSet_Throws()
        {
            var hash = new ComparableHashtable(StringComparer.CurrentCulture);

            Assert.Throws<ArgumentException>(() => hash.HashCodeProvider);
            Assert.Throws<ArgumentException>(() => hash.Comparer);

            Assert.Throws<ArgumentException>(() => hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant);
            Assert.Throws<ArgumentException>(() => hash.Comparer = StringComparer.OrdinalIgnoreCase);
        }
Пример #34
0
        public static void TestCtor_Capacity_LoadFactor_IEqualityComparer(int capacity, float loadFactor)
        {
            // Null comparer
            var hash = new ComparableHashtable(capacity, loadFactor, null);
            VerifyHashtable(hash, null, null);
            Assert.Null(hash.EqualityComparer);

            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash = new ComparableHashtable(capacity, loadFactor, comparer);
                VerifyHashtable(hash, null, comparer);
            });
        }
Пример #35
0
        public static void Comparer_Set_ImpactsSearch()
        {
            var hash = new ComparableHashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);
            hash.Add("test", "test");

            // Should be able to find with the same and different casing
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));

            // Changing the comparer, should only be able to find the matching case
            hash.Comparer = StringComparer.Ordinal;
            Assert.True(hash.ContainsKey("test"));
            Assert.False(hash.ContainsKey("TEST"));

            // Changing it back, should be able to find both again
            hash.Comparer = StringComparer.OrdinalIgnoreCase;
            Assert.True(hash.ContainsKey("test"));
            Assert.True(hash.ContainsKey("TEST"));
        }
Пример #36
0
 public static void TestCtor_Empty()
 {
     var hash = new ComparableHashtable();
     VerifyHashtable(hash, null, null);
 }
Пример #37
0
 public static void TestCtor_Capacity_LoadFactor(int capacity, float loadFactor)
 {
     var hash = new ComparableHashtable(capacity, loadFactor);
     VerifyHashtable(hash, null, null);
 }
Пример #38
0
        public void Ctor_Int_Int(int capacity, float loadFactor)
        {
            var hash = new ComparableHashtable(capacity, loadFactor);

            VerifyHashtable(hash, null, null);
        }
Пример #39
0
        public void Ctor_Int_Int_HashCodeProvider_Comparer(int capacity, float loadFactor)
        {
            var hash = new ComparableHashtable(capacity, loadFactor, CaseInsensitiveHashCodeProvider.DefaultInvariant, StringComparer.OrdinalIgnoreCase);

            VerifyHashtable(hash, null, hash.EqualityComparer);
        }
Пример #40
0
        public static void TestCtor_IDictionary_LoadFactor_IEqualityComparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), 1f, null);
            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(
                new Hashtable(new Hashtable(new Hashtable(), 1f, null), 1f, null), 1f, null), 1f, null), 1f, null);
            Assert.Equal(0, hash1.Count);

            // Null comparer
            Hashtable hash2 = Helpers.CreateIntHashtable(100);
            hash1 = new ComparableHashtable(hash2, 1f, null);
            VerifyHashtable(hash1, hash2, null);

            hash2 = Helpers.CreateIntHashtable(100);
            // Custom comparer
            Helpers.PerformActionOnCustomCulture(() =>
            {
                IEqualityComparer comparer = StringComparer.CurrentCulture;
                hash1 = new ComparableHashtable(hash2, 1f, comparer);
                VerifyHashtable(hash1, hash2, comparer);
            });
        }
Пример #41
0
        public void Ctor_Empty()
        {
            var hash = new ComparableHashtable();

            VerifyHashtable(hash, null, null);
        }
Пример #42
0
        public void Ctor_Int(int capacity)
        {
            var hash = new ComparableHashtable(capacity);

            VerifyHashtable(hash, null, null);
        }
Пример #43
0
        public static void Ctor_IDictionary_Int_HashCodeProvider_Comparer()
        {
            // No exception
            var hash1 = new ComparableHashtable(new Hashtable(), 1f);
            Assert.Equal(0, hash1.Count);

            hash1 = new ComparableHashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(), 1f), 1f), 1f), 1f), 1f);
            Assert.Equal(0, hash1.Count);

            Hashtable hash2 = Helpers.CreateIntHashtable(100);
            hash1 = new ComparableHashtable(hash2, 1f);

            VerifyHashtable(hash1, hash2, null);
        }
Пример #44
0
        private static void VerifyHashtable(ComparableHashtable hash1, Hashtable hash2, IEqualityComparer ikc)
        {
            if (hash2 == null)
            {
                Assert.Equal(0, hash1.Count);
            }
            else
            {
                // Make sure that construtor imports all keys and values
                Assert.Equal(hash2.Count, hash1.Count);
                for (int i = 0; i < 100; i++)
                {
                    Assert.True(hash1.ContainsKey(i));
                    Assert.True(hash1.ContainsValue(i));
                }

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

            Assert.Equal(ikc, hash1.EqualityComparer);

            Assert.False(hash1.IsFixedSize);
            Assert.False(hash1.IsReadOnly);
            Assert.False(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.True(hash1.ContainsKey(i));
                Assert.True(hash1.ContainsValue(i));
            }
        }
Пример #45
0
 public static void TestCtor_Capacity_LoadFactor_GenerateNewPrime()
 {
     // The ctor for Hashtable performs the following calculation:
     // rawSize = capacity / (loadFactor * 0.72)
     // If rawSize is > 3, then it calls HashHelpers.GetPrime(rawSize) to generate a prime.
     // Then, if the rawSize > 7,199,369 (the largest number in a list of known primes), we have to generate a prime programatically
     // This test makes sure this works.
     int capacity = 8000000;
     float loadFactor = 0.1f / 0.72f;
     try
     {
         var hash = new ComparableHashtable(capacity, loadFactor);
     }
     catch (OutOfMemoryException)
     {
         // On memory constrained devices, we can get an OutOfMemoryException, which we can safely ignore.
     }
 }
Пример #46
0
 public static void TestCtor_Capacity(int capacity)
 {
     var hash = new ComparableHashtable(capacity);
     VerifyHashtable(hash, null, null);
 }