public static void TestSet_New_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.OnValidateThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); // Throw OnSet dictBase = new OnMethodCalledDictionary(); dictBase.OnSetThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); // Throw OnSetComplete dictBase = new OnMethodCalledDictionary(); dictBase.OnSetCompleteThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); }
public static void Set_Existing_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); // Throw OnSet dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnSetThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); // Throw OnSetComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnSetCompleteThrow = true; Assert.Throws <Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); }
public static void Clear_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; dictBase.Clear(); Assert.Equal(0, dictBase.Count); // Throw OnClear dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnClearThrow = true; Assert.Throws <Exception>(() => dictBase.Clear()); Assert.Equal(1, dictBase.Count); // Throw OnClearComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnClearCompleteThrow = true; Assert.Throws <Exception>(() => dictBase.Clear()); Assert.Equal(0, dictBase.Count); }
public static void TestRemove_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; Assert.Throws <Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); // Throw OnRemove dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnRemoveThrow = true; Assert.Throws <Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); // Throw OnRemoveComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnRemoveCompleteThrow = true; Assert.Throws <Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); }
public override bool Equals(object obj) { FooKey foo = obj as FooKey; if (foo == null) { return(false); } return(foo.IntValue == IntValue && foo.StringValue == StringValue); }
public string this[FooKey key] { get { return((string)Dictionary[key]); } set { Dictionary[key] = value; } }
public static void Values() { MyDictionary dictBase = CreateDictionary(100); ICollection values = dictBase.Values; Assert.Equal(dictBase.Count, values.Count); foreach (FooValue value in values) { FooKey key = CreateKey(value.IntValue); Assert.Equal(value, dictBase[key]); } }
public static void Add_Called() { var f = new FooKey(0, "0"); var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, "hello"); Assert.True(dictBase.OnValidateCalled); Assert.True(dictBase.OnInsertCalled); Assert.True(dictBase.OnInsertCompleteCalled); Assert.True(dictBase.Contains(f)); }
public static void Clear_Called() { var f = new FooKey(0, "0"); var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.Clear(); Assert.True(dictBase.OnClearCalled); Assert.True(dictBase.OnClearCompleteCalled); Assert.Equal(0, dictBase.Count); }
public static void Remove() { MyDictionary dictBase = CreateDictionary(100); for (int i = 0; i < 100; i++) { FooKey key = CreateKey(i); dictBase.Remove(key); Assert.False(dictBase.Contains(key)); } Assert.Equal(0, dictBase.Count); dictBase.Remove(new FooKey()); // Doesn't exist, but doesn't throw }
public static void Remove_Called() { var f = new FooKey(0, "0"); var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateCalled = false; dictBase.Remove(f); Assert.True(dictBase.OnValidateCalled); Assert.True(dictBase.OnRemoveCalled); Assert.True(dictBase.OnRemoveCompleteCalled); Assert.False(dictBase.Contains(f)); }
public static void TestSet_New_Called() { var f = new FooKey(1, "1"); var dictBase = new OnMethodCalledDictionary(); dictBase.OnValidateCalled = false; dictBase[f] = "hello"; Assert.True(dictBase.OnValidateCalled); Assert.True(dictBase.OnSetCalled); Assert.True(dictBase.OnSetCompleteCalled); Assert.Equal(1, dictBase.Count); Assert.Equal("hello", dictBase[f]); }
public static void Set_Existing_Called() { var f = new FooKey(1, "1"); var dictBase = new OnMethodCalledDictionary(); dictBase.Add(new FooKey(), ""); dictBase.OnValidateCalled = false; dictBase[f] = "hello"; Assert.True(dictBase.OnValidateCalled); Assert.True(dictBase.OnSetCalled); Assert.True(dictBase.OnSetCompleteCalled); Assert.Equal("hello", dictBase[f]); }
public static void Item_Set() { MyDictionary dictBase = CreateDictionary(100); for (int i = 0; i < dictBase.Count; i++) { FooKey key = CreateKey(i); FooValue value = CreateValue(dictBase.Count - i - 1); dictBase[key] = value; Assert.Equal(value, dictBase[key]); } FooKey nonExistentKey = CreateKey(101); dictBase[nonExistentKey] = null; Assert.Equal(101, dictBase.Count); // Should add a key/value pair if the key Assert.Null(dictBase[nonExistentKey]); }
public Int32 CompareTo(Object obj) { if (!(obj is FooKey)) { throw new ArgumentException("obj must be type FooKey"); } FooKey temp = (FooKey)obj; if (temp.IValue > _iValue) { return(-1); } else if (temp.IValue < _iValue) { return(1); } else { return(0); } }
public static void Add() { var dictBase = new MyDictionary(); for (int i = 0; i < 100; i++) { FooKey key = CreateKey(i); dictBase.Add(key, CreateValue(i)); Assert.True(dictBase.Contains(key)); } Assert.Equal(100, dictBase.Count); for (int i = 0; i < dictBase.Count; i++) { Assert.Equal(CreateValue(i), dictBase[CreateKey(i)]); } FooKey nullKey = CreateKey(101); dictBase.Add(nullKey, null); Assert.Null(dictBase[nullKey]); }
public void Add(FooKey key, string value) => Dictionary.Add(key, value);
public void Remove(FooKey f) { ((IDictionary)Dictionary).Remove(f); }
public void Add(FooKey key, FooValue value) => Dictionary.Add(key, value);
public void Add(FooKey fk1, FooValue f2) { Dictionary.Add(fk1, f2); }
public static void TestSet_New_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.OnValidateThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); // Throw OnSet dictBase = new OnMethodCalledDictionary(); dictBase.OnSetThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); // Throw OnSetComplete dictBase = new OnMethodCalledDictionary(); dictBase.OnSetCompleteThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal(0, dictBase.Count); }
public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyDictionaryBase mycol1; MyDictionaryBase mycol2; FooKey fk1; FooValue fv1; FooKey[] arrFK1; FooValue[] arrFV1; IDictionaryEnumerator enu1; Int32 iCount; DictionaryEntry[] arrDicEnt1; DictionaryEntry dicEnt1; Object obj1; // ICollection icol1; try { do { ///////////////////////// START TESTS //////////////////////////// //[]DictionaryBase implements IDictionary (which means both ICollection and IEnumerator as well :-() //To test this class, we will implement our own strongly typed DictionaryBase and call its methods iCountTestcases++; //[] Count property iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } //[]CopyTo iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } arrDicEnt1 = new DictionaryEntry[100]; mycol1.CopyTo(arrDicEnt1, 0); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i].Key; arrFV1[i] = (FooValue)arrDicEnt1[i].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned"); } } //Argument checking iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } arrDicEnt1 = new DictionaryEntry[100]; try { mycol1.CopyTo(arrDicEnt1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrDicEnt1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } arrDicEnt1 = new DictionaryEntry[200]; mycol1.CopyTo(arrDicEnt1, 100); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key; arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned"); } } //[]GetEnumerator iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } enu1 = mycol1.GetEnumerator(); //Calling current should throw here try { //Calling current should throw here dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Key should throw here try { //Calling current should throw here fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Value should throw here try { //Calling current should throw here fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while (enu1.MoveNext()) { dicEnt1 = (DictionaryEntry)enu1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; fk1 = (FooKey)enu1.Key; if (fk1 != arrFK1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } fv1 = (FooValue)enu1.Value; if (fv1 != arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { //Calling current should throw here dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Key should throw here try { //Calling current should throw here fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Value should throw here try { //Calling current should throw here fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[] IEnumerable.GetEnumerator iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } IEnumerator iEnumerator1 = ((IEnumerable)mycol1).GetEnumerator(); //Calling current should throw here try { //Calling current should throw here dicEnt1 = (DictionaryEntry)iEnumerator1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while (iEnumerator1.MoveNext()) { dicEnt1 = (DictionaryEntry)iEnumerator1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; if (mycol1[arrFK1[iCount]] != arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { //Calling current should throw here dicEnt1 = (DictionaryEntry)iEnumerator1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[]IsSynchronized iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized); } //[]SyncRoot iCountTestcases++; mycol1 = new MyDictionaryBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } //End of ICollection and IEnumerator methods //Now to IDictionary methods //[]Add, this, Contains, Remove, Clear iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } for (int i = 0; i < 100; i++) { if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new FooKey(i, i.ToString())); if ((mycol1.Count != (99 - i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if ((mycol1.Contains(new FooKey(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } //[]Rest of the IList methods: this-set, IsFixedSize, IsReadOnly, Keys, Values iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); } if (mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } for (int i = 0, j = 100; i < 100; i++, j--) { mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString()); } for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString())) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); mycol1.Add(new FooKey(), new FooValue()); /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return(true); } else { Console.WriteLine("Fail! iCountErrors==" + iCountErrors); return(false); } }
public Boolean Contains(FooKey f) { return ((IDictionary)Dictionary).Contains(f); }
public Boolean Contains(FooKey f) { return(((IDictionary)Dictionary).Contains(f)); }
public FooValue this[FooKey f1] { get { return((FooValue)Dictionary[f1]); } set { Dictionary[f1] = value; } }
public void Remove(FooKey key) => Dictionary.Remove(key);
public FooValue this[FooKey key] { get { return((FooValue)Dictionary[key]); } set { Dictionary[key] = value; } }
public int CompareTo(object obj) { FooKey temp = (FooKey)obj; return(IntValue.CompareTo(temp.IntValue)); }
public bool Contains(FooKey key) { return(Dictionary.Contains(key)); }
public bool Contains(FooKey key) => Dictionary.Contains(key);
public static void TestRemove_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; Assert.Throws<Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); // Throw OnRemove dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnRemoveThrow = true; Assert.Throws<Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); // Throw OnRemoveComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnRemoveCompleteThrow = true; Assert.Throws<Exception>(() => dictBase.Remove(f)); Assert.Equal(1, dictBase.Count); }
public FooValue this[FooKey f1] { get { return (FooValue)Dictionary[f1]; } set { Dictionary[f1] = value; } }
public static void Clear_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; dictBase.Clear(); Assert.Equal(0, dictBase.Count); // Throw OnClear dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnClearThrow = true; Assert.Throws<Exception>(() => dictBase.Clear()); Assert.Equal(1, dictBase.Count); // Throw OnClearComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnClearCompleteThrow = true; Assert.Throws<Exception>(() => dictBase.Clear()); Assert.Equal(0, dictBase.Count); }
public static void Set_Existing_Throws_Called() { var f = new FooKey(0, "0"); // Throw OnValidate var dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnValidateThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); // Throw OnSet dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnSetThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); // Throw OnSetComplete dictBase = new OnMethodCalledDictionary(); dictBase.Add(f, ""); dictBase.OnSetCompleteThrow = true; Assert.Throws<Exception>(() => dictBase[f] = "hello"); Assert.Equal("", dictBase[f]); }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; MyDictionaryBase mycol1; MyDictionaryBase mycol2; FooKey fk1; FooValue fv1; FooKey[] arrFK1; FooValue[] arrFV1; IDictionaryEnumerator enu1; Int32 iCount; DictionaryEntry[] arrDicEnt1; DictionaryEntry dicEnt1; Object obj1; try { do { iCountTestcases++; iCountTestcases++; strLoc = "Loc_001oo"; mycol1 = new MyDictionaryBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } iCountTestcases++; strLoc = "Loc_002oo"; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } arrDicEnt1 = new DictionaryEntry[100]; mycol1.CopyTo(arrDicEnt1, 0); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i].Key; arrFV1[i] = (FooValue)arrDicEnt1[i].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } arrDicEnt1 = new DictionaryEntry[100]; try { mycol1.CopyTo(arrDicEnt1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrDicEnt1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } arrDicEnt1 = new DictionaryEntry[200]; mycol1.CopyTo(arrDicEnt1, 100); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key; arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } enu1 = mycol1.GetEnumerator(); try { dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while (enu1.MoveNext()) { dicEnt1 = (DictionaryEntry)enu1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; fk1 = (FooKey)enu1.Key; if (fk1 != arrFK1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } fv1 = (FooValue)enu1.Value; if (fv1 != arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } strLoc = "Loc_004oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized); } iCountTestcases++; strLoc = "Loc_005oo"; mycol1 = new MyDictionaryBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } for (int i = 0; i < 100; i++) { if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new FooKey(i, i.ToString())); if ((mycol1.Count != (99 - i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if ((mycol1.Contains(new FooKey(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); } if (mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); } for (int i = 0, j = 100; i < 100; i++, j--) { mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString()); } for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString())) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); mycol1.Add(new FooKey(), new FooValue()); } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public FooValue this[FooKey key] { get { return (FooValue)Dictionary[key]; } set { Dictionary[key] = value; } }
public bool Contains(FooKey key) { return Dictionary.Contains(key); }
public string this[FooKey key] { get { return (string)Dictionary[key]; } set { Dictionary[key] = value; } }
public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyDictionaryBase mycol1; MyDictionaryBase mycol2; FooKey fk1; FooValue fv1; FooKey[] arrFK1; FooValue[] arrFV1; IDictionaryEnumerator enu1; Int32 iCount; DictionaryEntry[] arrDicEnt1; DictionaryEntry dicEnt1; Object obj1; // ICollection icol1; try { do { ///////////////////////// START TESTS //////////////////////////// //[]DictionaryBase implements IDictionary (which means both ICollection and IEnumerator as well :-() //To test this class, we will implement our own strongly typed DictionaryBase and call its methods iCountTestcases++; //[] Count property iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } //[]CopyTo iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); arrDicEnt1 = new DictionaryEntry[100]; mycol1.CopyTo(arrDicEnt1, 0); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i].Key; arrFV1[i] = (FooValue)arrDicEnt1[i].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned"); } } //Argument checking iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); arrDicEnt1 = new DictionaryEntry[100]; try { mycol1.CopyTo(arrDicEnt1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrDicEnt1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } arrDicEnt1 = new DictionaryEntry[200]; mycol1.CopyTo(arrDicEnt1, 100); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for (int i = 0; i < 100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key; arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned"); } } //[]GetEnumerator iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); enu1 = mycol1.GetEnumerator(); //Calling current should throw here try { //Calling current should throw here dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Key should throw here try { //Calling current should throw here fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Value should throw here try { //Calling current should throw here fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while (enu1.MoveNext()) { dicEnt1 = (DictionaryEntry)enu1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; fk1 = (FooKey)enu1.Key; if (fk1 != arrFK1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } fv1 = (FooValue)enu1.Value; if (fv1 != arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { //Calling current should throw here dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Key should throw here try { //Calling current should throw here fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //Calling Value should throw here try { //Calling current should throw here fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[] IEnumerable.GetEnumerator iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); IEnumerator iEnumerator1 = ((IEnumerable)mycol1).GetEnumerator(); //Calling current should throw here try { //Calling current should throw here dicEnt1 = (DictionaryEntry)iEnumerator1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while (iEnumerator1.MoveNext()) { dicEnt1 = (DictionaryEntry)iEnumerator1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; if (mycol1[arrFK1[iCount]] != arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for (int i = 0; i < 100; i++) { if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { //Calling current should throw here dicEnt1 = (DictionaryEntry)iEnumerator1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[]IsSynchronized iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized); } //[]SyncRoot iCountTestcases++; mycol1 = new MyDictionaryBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } //End of ICollection and IEnumerator methods //Now to IDictionary methods //[]Add, this, Contains, Remove, Clear iCountTestcases++; mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); for (int i = 0; i < 100; i++) { if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new FooKey(i, i.ToString())); if ((mycol1.Count != (99 - i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if ((mycol1.Contains(new FooKey(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } //[]Rest of the IList methods: this-set, IsFixedSize, IsReadOnly, Keys, Values iCountTestcases++; mycol1 = new MyDictionaryBase(); if (mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); } if (mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); } mycol1 = new MyDictionaryBase(); for (int i = 0; i < 100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); for (int i = 0, j = 100; i < 100; i++, j--) mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString()); for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString())) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); mycol1.Add(new FooKey(), new FooValue()); /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return true; } else { Console.WriteLine("Fail! iCountErrors==" + iCountErrors); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; MyDictionaryBase mycol1; MyDictionaryBase mycol2; FooKey fk1; FooValue fv1; FooKey[] arrFK1; FooValue[] arrFV1; IDictionaryEnumerator enu1; Int32 iCount; DictionaryEntry[] arrDicEnt1; DictionaryEntry dicEnt1; Object obj1; try { do { iCountTestcases++; iCountTestcases++; strLoc = "Loc_001oo"; mycol1 = new MyDictionaryBase(); if(mycol1.Count!=0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); if(mycol1.Count!=100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } iCountTestcases++; strLoc = "Loc_002oo"; mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); arrDicEnt1 = new DictionaryEntry[100]; mycol1.CopyTo(arrDicEnt1, 0); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for(int i=0; i<100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i].Key; arrFV1[i] = (FooValue)arrDicEnt1[i].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for(int i=0; i<100; i++) { if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); arrDicEnt1 = new DictionaryEntry[100]; try { mycol1.CopyTo(arrDicEnt1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch(ArgumentException) { } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrDicEnt1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch(ArgumentException) { } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } arrDicEnt1 = new DictionaryEntry[200]; mycol1.CopyTo(arrDicEnt1, 100); arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; for(int i=0; i<100; i++) { arrFK1[i] = (FooKey)arrDicEnt1[i+100].Key; arrFV1[i] = (FooValue)arrDicEnt1[i+100].Value; } Array.Sort(arrFK1); Array.Sort(arrFV1); for(int i=0; i<100; i++) { if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); enu1 = mycol1.GetEnumerator(); try { dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount=0; arrFK1 = new FooKey[100]; arrFV1 = new FooValue[100]; while( enu1.MoveNext() ) { dicEnt1 = (DictionaryEntry)enu1.Current; arrFK1[iCount] = (FooKey)dicEnt1.Key; arrFV1[iCount] = (FooValue)dicEnt1.Value; fk1 = (FooKey)enu1.Key; if(fk1!=arrFK1[iCount]) { iCountErrors++; Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); } fv1 = (FooValue)enu1.Value; if(fv1!=arrFV1[iCount]) { iCountErrors++; Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue); } iCount++; } if(iCount!=100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } Array.Sort(arrFK1); Array.Sort(arrFV1); for(int i=0; i<100; i++) { if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); } if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); } } try { dicEnt1 = (DictionaryEntry)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fk1 = (FooKey)enu1.Key; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } try { fv1 = (FooValue)enu1.Value; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } strLoc = "Loc_004oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); if(mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized); } iCountTestcases++; strLoc = "Loc_005oo"; mycol1 = new MyDictionaryBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if(obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); for(int i=0; i<100; i++) { if((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } } for(int i=0; i<100; i++) { mycol1.Remove(new FooKey(i, i.ToString())); if((mycol1.Count != (99-i)) ) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if((mycol1.Contains(new FooKey(i, i.ToString()))) ) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); mycol1.Clear(); if(mycol1.Count!=0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyDictionaryBase(); if(mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); } if(mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); } mycol1 = new MyDictionaryBase(); for(int i=0; i<100; i++) mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); for(int i=0, j=100; i<100; i++, j--) mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString()); for(int i=0, j=100; i<100; i++, j--) { if((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue!= j.ToString()) ) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyDictionaryBase(); mycol1.Add(new FooKey(), new FooValue()); } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }