static void TestContains() { MyDictionary <char, bool> testDict = new MyDictionary <char, bool>(); Console.WriteLine("Testing Contains Function..."); Console.WriteLine(); testDict.Add('A', true); Console.WriteLine("Adding: A-true"); testDict.Add('G', true); Console.WriteLine("Adding: G-true"); testDict.Add('L', false); Console.WriteLine("Adding: G-false"); testDict.Add('R', false); Console.WriteLine("Adding: R-false"); testDict.Add('Z', false); Console.WriteLine("Adding: Z-false"); testDict.Add('K', true); Console.WriteLine("Adding: K-true"); testDict.Add('D', false); Console.WriteLine("Adding: D-false"); testDict.Add('O', true); Console.WriteLine("Adding: O-true"); testDict.Add('P', false); Console.WriteLine("Adding: P-false"); Debug.Assert(testDict.ContainsKey('A')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('A', true))); Console.WriteLine("Dictionary Contains: A-true"); Debug.Assert(testDict.ContainsKey('G')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('G', true))); Console.WriteLine("Dictionary Contains: G-true"); Debug.Assert(testDict.ContainsKey('L')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('L', false))); Console.WriteLine("Dictionary Contains: L-false"); Debug.Assert(testDict.ContainsKey('R')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('R', false))); Console.WriteLine("Dictionary Contains: R-false"); Debug.Assert(testDict.ContainsKey('Z')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('Z', false))); Console.WriteLine("Dictionary Contains: Z-false"); Debug.Assert(testDict.ContainsKey('K')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('K', true))); Console.WriteLine("Dictionary Contains: K-true"); Debug.Assert(testDict.ContainsKey('D')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('D', false))); Console.WriteLine("Dictionary Contains: D-false"); Debug.Assert(testDict.ContainsKey('O')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('O', true))); Console.WriteLine("Dictionary Contains: O-true"); Debug.Assert(testDict.ContainsKey('P')); Debug.Assert(testDict.Contains(new KeyValuePair <char, bool>('P', false))); Console.WriteLine("Dictionary Contains: P-false"); Debug.Assert(!testDict.ContainsKey('T')); Console.WriteLine("Dictionary Does Not Contain key T"); Debug.Assert(!testDict.Contains(new KeyValuePair <char, bool>('G', false))); Console.WriteLine("Dictionary Does not Contain Pair: G-false"); Console.WriteLine("All Keys: " + string.Join(",", testDict.Keys.ToArray())); Console.WriteLine("All Values: " + string.Join(",", testDict.Values.ToArray())); Console.WriteLine("Contains Test Suceeded"); Console.WriteLine(); }
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(); }
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(); }