System.Collections.Tests.SortedListTests.Ctor_IDictionary C# (CSharp) Method

Ctor_IDictionary() private method

private Ctor_IDictionary ( int count, bool sorted ) : void
count int
sorted bool
return void
        public static void Ctor_IDictionary(int count, bool sorted)
        {
            var hashtable = new Hashtable();
            if (sorted)
            {
                // Create a hashtable in the correctly sorted order
                for (int i = 0; i < count; i++)
                {
                    hashtable.Add("Key_" + i.ToString("D2"), "Value_" + i.ToString("D2"));
                }
            }
            else
            {
                // Create a hashtable in the wrong order and make sure it is sorted
                for (int i = count - 1; i >= 0; i--)
                {
                    hashtable.Add("Key_" + i.ToString("D2"), "Value_" + i.ToString("D2"));
                }
            }

            var sortList = new SortedList(hashtable);

            Assert.Equal(count, sortList.Count);
            Assert.True(sortList.Capacity >= sortList.Count);

            for (int i = 0; i < count; i++)
            {
                string key = "Key_" + i.ToString("D2");
                string value = "Value_" + i.ToString("D2");

                Assert.Equal(sortList.GetByIndex(i), value);
                Assert.Equal(hashtable[key], sortList[key]);
            }

            Assert.False(sortList.IsFixedSize);
            Assert.False(sortList.IsReadOnly);
            Assert.False(sortList.IsSynchronized);
        }
SortedListTests