예제 #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);
 }