コード例 #1
0
        static void TestClear()
        {
            MyDictionary <int, string> testDict = new MyDictionary <int, string>();

            Console.WriteLine("Testing Clear Function...");
            Console.WriteLine();
            testDict.Add(1, "A"); Console.WriteLine("Adding: 1-A");
            testDict.Add(43, "B"); Console.WriteLine("Adding: 43-B");
            testDict.Add(7, "C"); Console.WriteLine("Adding: 7-C");
            testDict.Add(9, "L"); Console.WriteLine("Adding: 9-C");
            testDict.Add(50, "K"); Console.WriteLine("Adding: 50-K");
            testDict.Add(10, "P"); Console.WriteLine("Adding: 10-P");
            testDict.Add(8, "L"); Console.WriteLine("Adding: 8-l");
            testDict.Add(2, "K"); Console.WriteLine("Adding: 2-K");
            testDict.Add(90, "R"); Console.WriteLine("Adding: 90-R");
            testDict.Clear(); Console.WriteLine("Clearing dictionary...");
            Debug.Assert(testDict.underlyingArray.Length == 7); Debug.Assert(testDict.Count == 0); Debug.Assert(!testDict.ContainsKey(10));
            Console.WriteLine("All Keys: " + string.Join(",", testDict.Keys.ToArray()));
            Console.WriteLine("All Values: " + string.Join(",", testDict.Values.ToArray()));
            Console.WriteLine("Clear Test Suceeded");
            Console.WriteLine();
        }
コード例 #2
0
        static void TestExpandArray()
        {
            MyDictionary <int, string> testDict = new MyDictionary <int, string>();

            Console.WriteLine("Testing ExpandArray Function...");
            Console.WriteLine();
            testDict.Add(1, "A"); Console.WriteLine("Adding: 1-A");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(43, "B"); Console.WriteLine("Adding: 43-B");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(7, "C"); Console.WriteLine("Adding: 7-C");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(9, "L"); Console.WriteLine("Adding: 9-C");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(50, "K"); Console.WriteLine("Adding: 50-K");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(10, "P"); Console.WriteLine("Adding: 10-P");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(8, "L"); Console.WriteLine("Adding: 8-K");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(2, "K"); Console.WriteLine("Adding: 2-K");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            testDict.Add(90, "R"); Console.WriteLine("Adding: 90-R");
            Console.WriteLine("Dictionary's underlying array length: " + testDict.underlyingArray.Length);
            Console.WriteLine("Dictionary's load capacity: " + testDict.loadCapacity);
            Console.WriteLine("All Keys: " + string.Join(",", testDict.Keys.ToArray()));
            Console.WriteLine("All Values: " + string.Join(",", testDict.Values.ToArray()));
            Console.WriteLine("Expanding Array Test Suceeded");
            Console.WriteLine();
        }
コード例 #3
0
        static void TestRemove()
        {
            MyDictionary <int, string> testDict = new MyDictionary <int, string>();

            Console.WriteLine("Testing Remove Function...");
            Console.WriteLine();
            testDict.Add(1, "A"); Console.WriteLine("Adding: 1-A");
            testDict.Add(43, "B"); Console.WriteLine("Adding: 43-B");
            testDict.Add(7, "C"); Console.WriteLine("Adding: 7-C");
            testDict.Add(9, "L"); Console.WriteLine("Adding: 9-C");
            testDict.Add(50, "K"); Console.WriteLine("Adding: 50-K");
            testDict.Add(10, "P"); Console.WriteLine("Adding: 10-P");
            testDict.Add(8, "L"); Console.WriteLine("Adding: 8-L");
            testDict.Add(2, "K"); Console.WriteLine("Adding: 2-K");
            testDict.Add(90, "R"); Console.WriteLine("Adding: 90-R");
            Debug.Assert(testDict.Remove(1)); Console.WriteLine("Removing: 1-A");
            Debug.Assert(testDict.Remove(50)); Console.WriteLine("Removing: 50-K");
            Debug.Assert(testDict.Remove(new KeyValuePair <int, string>(90, "R"))); Console.WriteLine("Removing: 90-R");
            Debug.Assert(!testDict.ContainsKey(1) && !testDict.ContainsKey(50) && !testDict.ContainsKey(90)); Debug.Assert(testDict.Count == 6);
            Console.WriteLine("All Keys: " + string.Join(",", testDict.Keys.ToArray()));
            Console.WriteLine("All Values: " + string.Join(",", testDict.Values.ToArray()));
            Console.WriteLine("Remove Test Suceeded");
            Console.WriteLine();
        }