コード例 #1
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));
            }
        }
コード例 #2
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"));
        }
コード例 #3
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"));
        }
コード例 #4
0
ファイル: HashtableTests.cs プロジェクト: benpye/corefx
        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));
            }
        }
コード例 #5
0
ファイル: HashtableTests.cs プロジェクト: Corillian/corefx
        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"));
        }
コード例 #6
0
ファイル: HashtableTests.cs プロジェクト: Corillian/corefx
        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"));
        }