public void Test01() { IntlStrings intl; StringDictionary sd; string ind; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] check for empty dictionary // for (int i = 0; i < values.Length; i++) { if (sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, returned true for empty dictionary", i)); } } // [] add simple strings and verify ContainsKey() // cnt = values.Length; for (int i = 0; i < cnt; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != cnt) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, cnt)); } for (int i = 0; i < cnt; i++) { // verify that collection contains all added items // if (!sd.ContainsValue(values[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value \"{1}\"", i, values[i])); } if (!sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, collection doesn't contain key \"{1}\"", i, keys[i])); } } // // Intl strings // [] add Intl strings and verify ContainsKey() // int len = values.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant()) { caseInsensitive = true; } } // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // access the item // ind = intlValues[i + len]; if (String.Compare(sd[ind], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, sd[ind], intlValues[i])); } } // // add null string with non-null key // [] add null string with non-null key and verify ContainsKey() // cnt = sd.Count; string k = "keykey"; sd.Add(k, null); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsKey(k)) { Assert.False(true, string.Format("Error, dictionary doesn't contain new key")); } // // [] Case sensitivity: search should be case-sensitive // sd.Clear(); if (sd.Count != 0) { Assert.False(true, string.Format("Error, count is {1} instead of {2} after Clear()", sd.Count, 0)); } string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added uppercase item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // verify that collection doesn't contains lowercase item // if (!caseInsensitive && sd.ContainsValue(intlValuesLower[i])) { Assert.False(true, string.Format("Error, collection contains lowercase value of new item", i)); } // key is case insensitive if (!sd.ContainsKey(intlValuesLower[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain lowercase key of new item", i)); } } // // call ContainsKey with null - ArgumentNullException expected // [] ContainsKey (null) // Assert.Throws <ArgumentNullException>(() => { sd.ContainsKey(null); }); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; ListDictionary ld; string [] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. add simple strings"); for (int i = 0; i < values.Length; i++) { iCountTestcases++; cnt = ld.Count; ld.Add(keys[i], values[i]); if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0001_{0}a, count is {1} instead of {2}", i, ld.Count, cnt + 1); } iCountTestcases++; if (String.Compare(ld[keys[i]].ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, returned item \"{1}\" instead of \"{2}\"", i, ld[keys[i]], values[i]); } } Console.WriteLine("2. add intl strings"); int len = values.Length; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } Console.WriteLine(" initial number of items: " + ld.Count); strLoc = "Loc_002oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = ld.Count; ld.Add(intlValues[i + len], intlValues[i]); if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, ld.Count, cnt + 1); } iCountTestcases++; if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i]); } } Console.WriteLine("3. Case sensitivity"); string [] intlValuesLower = new string [len * 2]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } ld.Clear(); Console.WriteLine(" initial number of items: " + ld.Count); strLoc = "Loc_003oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = ld.Count; ld.Add(intlValues[i + len], intlValues[i]); if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0003_{0}a, count is {1} instead of {2}", i, ld.Count, cnt + 1); } iCountTestcases++; if (ld[intlValues[i + len]] == null) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned null", i); } else { if (!ld[intlValues[i + len]].Equals(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i]); } } if (!caseInsensitive && ld[intlValuesLower[i + len]] != null) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, returned non-null", i); } } Console.WriteLine("4. multiple string with the same key"); ld.Clear(); len = values.Length; string k = "keykey"; ld.Add(k, "value"); try { ld.Add(k, "newvalue"); iCountErrors++; Console.WriteLine("Err_0004a, no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0004b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("5. Add (string, null) "); Console.WriteLine(" initial number of items: " + ld.Count); strLoc = "Loc_005oo"; iCountTestcases++; cnt = ld.Count; k = "kk"; ld.Add(k, null); iCountTestcases++; if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, cnt + 1); } iCountTestcases++; if (ld[k] != null) { iCountErrors++; Console.WriteLine("Err_0005c, returned non-null on place of null"); } Console.WriteLine("6. Add (null, string) "); Console.WriteLine(" initial number of items: " + ld.Count); strLoc = "Loc_006oo"; cnt = ld.Count; iCountTestcases++; try { ld.Add(null, "item"); iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("7. add duplicate values"); ld.Clear(); for (int i = 0; i < values.Length; i++) { iCountTestcases++; cnt = ld.Count; ld.Add(keys[i], "value"); if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0007_{0}a, count is {1} instead of {2}", i, ld.Count, cnt + 1); } iCountTestcases++; if (!ld[keys[i]].Equals("value")) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, returned item \"{1}\" instead of \"{2}\"", i, ld[keys[i]], "value"); } } iCountTestcases++; if (ld.Keys.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0007_c, Keys contains {0} instead of {1}", ld.Keys.Count, values.Length); } iCountTestcases++; if (ld.Values.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0007_c, Values contains {0} instead of {1}", ld.Values.Count, values.Length); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 void Test01() { IntlStrings intl; StringDictionary sd; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; string itm; // returned Item // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] get Item() on empty dictionary // if (sd.Count > 0) { sd.Clear(); } for (int i = 0; i < keys.Length; i++) { itm = sd[keys[i]]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for {0} key", i)); } } // [] get Item() on filled dictionary // int len = values.Length; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } for (int i = 0; i < len; i++) { if (String.Compare(sd[keys[i]], values[i]) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", i, sd[keys[i]], values[i])); } } // // [] get Item on dictionary with identical values // sd.Clear(); string intlStr = intl.GetRandomString(MAX_LEN); sd.Add("keykey1", intlStr); // 1st duplicate for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } sd.Add("keykey2", intlStr); // 2nd duplicate if (sd.Count != len + 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len + 2)); } // get Item // if (String.Compare(sd["keykey1"], intlStr) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", sd["keykey1"], intlStr)); } if (String.Compare(sd["keykey2"], intlStr) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", sd["keykey2"], intlStr)); } // // Intl strings // [] get Item() on dictionary filled with Intl strings // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } // // will use first half of array as values and second half as keys // sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // get item for (int i = 0; i < len; i++) { if (String.Compare(sd[intlValues[i + len]], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", i, sd[intlValues[i + len]], intlValues[i])); } } // // [] Case sensitivity: keys are always lowercased // sd.Clear(); string[] intlValuesUpper = new string[len]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToLowerInvariant(); } // array of uppercase keys for (int i = 0; i < len; i++) { intlValuesUpper[i] = intlValues[i + len].ToUpperInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); // adding lowercase strings } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // get Item for (int i = 0; i < len; i++) { if (String.Compare(sd[intlValuesUpper[i]], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", i, sd[intlValuesUpper[i]], intlValues[i])); } } // // [] Invalid parameter // Assert.Throws <ArgumentNullException>(() => { itm = sd[null]; }); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; ListDictionary ld; string [] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. set Item() on empty dictionary"); iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - Item(null)"); try { ld[null] = "item"; iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - Item(some_string)"); ld["some_string"] = "item"; if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0001c, failed to add item"); } if (String.Compare(ld["some_string"].ToString(), "item", false) != 0) { iCountErrors++; Console.WriteLine("Err_0001d, failed to set item"); } Console.WriteLine("2. add simple strings, set via Item(Object)"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = ld.Count; int len = values.Length; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != cnt + len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, cnt + len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (!ld.Contains(keys[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, doesn't contain key", i); } iCountTestcases++; ld[keys[i]] = "newValue" + i; if (String.Compare(ld[keys[i]].ToString(), "newValue" + i, false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, failed to set value", i); } } Console.WriteLine("3. add intl strings and set via Item()"); strLoc = "Loc_003oo"; iCountTestcases++; string [] intlValues = new string [len * 2 + 1]; for (int i = 0; i < len * 2 + 1; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } iCountTestcases++; cnt = ld.Count; for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } if (ld.Count != (cnt + len)) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, cnt + len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (!ld.Contains(intlValues[i + len])) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, doesn't contain key", i); } iCountTestcases++; ld[intlValues[i + len]] = intlValues[len * 2]; if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[len * 2], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, failed to set value", i); } } Console.WriteLine("4. case sensitivity"); strLoc = "Loc_004oo"; string [] intlValuesLower = new string [len * 2]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } ld.Clear(); Console.WriteLine(" - add uppercase and set using uppercase"); for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } for (int i = 0; i < len; i++) { iCountTestcases++; if (!ld.Contains(intlValues[i + len])) { iCountErrors++; Console.WriteLine("Err_0004_{0}b, doesn't contain key", i); } } ld.Clear(); Console.WriteLine(" - add uppercase but set using lowercase"); for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } for (int i = 0; i < len; i++) { cnt = ld.Count; iCountTestcases++; ld[intlValuesLower[i + len]] = "item"; if (ld[intlValuesLower[i + len]] == null) { iCountErrors++; Console.WriteLine("Err_0004_{0}d, failed: returned non-null for lowercase key", i); } iCountTestcases++; if (!caseInsensitive && String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}e, failed: changed value via lowercase key", i); } iCountTestcases++; if (String.Compare(ld[intlValuesLower[i + len]].ToString(), "item", false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}e, failed: didn't add when set via lowercase key", i); } } Console.WriteLine("5. set Item() on LD with insensitive comparer"); ld = new ListDictionary(new Co8695_InsensitiveComparer()); strLoc = "Loc_005oo"; iCountTestcases++; len = values.Length; ld.Clear(); string kk = "key"; for (int i = 0; i < len; i++) { ld.Add(kk + i, values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (ld[kk.ToUpper() + i] == null) { iCountErrors++; Console.WriteLine("Err_0005b_{0}, returned null for differently cased key", i); } else { ld[kk.ToUpper() + i] = "Item" + i; if (String.Compare(ld[kk.ToUpper() + i].ToString(), "Item" + i, false) != 0) { iCountErrors++; Console.WriteLine("Err_0005b_{0}, failed to set value", i); } } } Console.WriteLine("6. set Item(null) for filled LD"); ld = new ListDictionary(); strLoc = "Loc_006oo"; iCountTestcases++; cnt = ld.Count; if (ld.Count < len) { ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } } iCountTestcases++; try { ld[null] = "item"; iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("8. set Item() to null"); ld = new ListDictionary(); strLoc = "Loc_006oo"; iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - with non-existing key"); ld["null_key"] = null; if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0008a, failed to add entry"); } if (ld["null_key"] != null) { iCountErrors++; Console.WriteLine("Err_0008b, failed to add entry with null value"); } iCountTestcases++; cnt = ld.Count; ld.Add("key", "value"); if (ld.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0008c, failed to add entry"); } iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - with existing key"); ld["key"] = null; if (ld["key"] != null) { iCountErrors++; Console.WriteLine("Err_0008d, failed to set entry to null "); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; NameValueCollection nvc; string [] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; string [] ks; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; nvc = new NameValueCollection(); Console.WriteLine("1. AllKeys on empty collection"); if (nvc.Count > 0) { nvc.Clear(); } ks = nvc.AllKeys; if (ks.Length != 0) { iCountErrors++; Console.WriteLine("Err_0001, number of keys is {0} instead of 0", ks.Length); } Console.WriteLine("2. AllKeys on collection with simple strings"); strLoc = "Loc_002oo"; for (int i = 0; i < values.Length; i++) { iCountTestcases++; cnt = nvc.Count; nvc.Add(keys[i], values[i]); if (nvc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt + 1); } iCountTestcases++; if (nvc.AllKeys.Length != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, incorrects Keys array", i); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, keys[i]) < 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, collection doesn't contain key of new item", i); } } Console.WriteLine("3. AllKeys on collection with intl strings"); int len = values.Length; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } Console.WriteLine(" initial number of items: " + nvc.Count); strLoc = "Loc_003oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = nvc.Count; nvc.Add(intlValues[i + len], intlValues[i]); if (nvc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0003_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt + 1); } iCountTestcases++; if (nvc.AllKeys.Length != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, wrong keys array", i); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, intlValues[i + len]) < 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, Array doesn't contain key of new item", i); } } Console.WriteLine("4. Case sensitivity"); string [] intlValuesLower = new string [len * 2]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } nvc.Clear(); Console.WriteLine(" initial number of items: " + nvc.Count); strLoc = "Loc_004oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = nvc.Count; nvc.Add(intlValues[i + len], intlValues[i]); if (nvc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, count is {1} instead of {2}", i, nvc.Count, cnt + 1); } iCountTestcases++; if (nvc.AllKeys.Length != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0004_{0}b, wrong keys array", i); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, intlValues[i + len]) < 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}c, collection doesn't contain key of new item", i); } iCountTestcases++; if (!caseInsensitive && Array.IndexOf(nvc.AllKeys, intlValuesLower[i + len]) >= 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}d, key was converted to lower", i); } } Console.WriteLine("5. AllKeys for multiple strings with the same key"); nvc.Clear(); len = values.Length; string k = "keykey"; iCountTestcases++; for (int i = 0; i < len; i++) { nvc.Add(k, "Value" + i); iCountTestcases++; if (nvc.Count != 1) { iCountErrors++; Console.WriteLine("Err_0005_{1}_a, count is {0} instead of 1", nvc.Count, i); } iCountTestcases++; if (nvc.AllKeys.Length != 1) { iCountErrors++; Console.WriteLine("Err_0005_{1}_b, AllKeys contains {0} instead of 1", nvc.AllKeys.Length, i); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, k) != 0) { iCountErrors++; Console.WriteLine("Err_0005_{0}_c, wrong key", i); } } string [] vals = nvc.GetValues(k); if (vals.Length != len) { iCountErrors++; Console.WriteLine("Err_0005d, number of values at given key is {0} instead of {1}", vals.Length, 1); } Console.WriteLine("6. AllKeys when collection has null-value "); strLoc = "Loc_006oo"; iCountTestcases++; k = "kk"; nvc.Remove(k); cnt = nvc.Count; Console.WriteLine(" initial number of items: " + cnt); nvc.Add(k, null); iCountTestcases++; if (nvc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0006a, count is {0} instead of {1}", nvc.Count, cnt + 1); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, k) < 0) { iCountErrors++; Console.WriteLine("Err_0006b, collection doesn't contain key of new item"); } iCountTestcases++; if (nvc[k] != null) { iCountErrors++; Console.WriteLine("Err_0006c, returned non-null on place of null"); } Console.WriteLine("7. AllKeys when item with null-key is present "); Console.WriteLine(" initial number of items: " + nvc.Count); strLoc = "Loc_007oo"; nvc.Remove(null); cnt = nvc.Count; Console.WriteLine(" - add item with null key with no such item previously"); iCountTestcases++; nvc.Add(null, "item"); iCountTestcases++; if (nvc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0007a, count is {0} instead of {1}", nvc.Count, cnt + 1); } iCountTestcases++; if (Array.IndexOf(nvc.AllKeys, null) < 0) { iCountErrors++; Console.WriteLine("Err_0007b, collection doesn't contain null key "); } iCountTestcases++; if (nvc[null] != "item") { iCountErrors++; Console.WriteLine("Err_0007c, returned wrong value at null key"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringDictionary sd; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; sd = new StringDictionary(); Console.WriteLine("1. Remove() from empty dictionary"); iCountTestcases++; if (sd.Count > 0) { sd.Clear(); } for (int i = 0; i < keys.Length; i++) { sd.Remove(keys[0]); } Console.WriteLine("2. Remove() on filled dictionary"); strLoc = "Loc_002oo"; int len = values.Length; iCountTestcases++; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = sd.Count; sd.Remove(keys[i]); if (sd.Count != cnt - 1) { iCountErrors++; Console.WriteLine("Err_0002b_{0}, didn't remove element with {0} key", i); } iCountTestcases++; if (sd.ContainsValue(values[i])) { iCountErrors++; Console.WriteLine("Err_0002c_{0}, removed wrong value", i); } iCountTestcases++; if (sd.ContainsKey(keys[i])) { iCountErrors++; Console.WriteLine("Err_0002d_{0}, removed wrong value", i); } } Console.WriteLine("3. Remove() on dictionary with duplicate values "); strLoc = "Loc_003oo"; iCountTestcases++; sd.Clear(); string intlStr = intl.GetString(MAX_LEN, true, true, true); sd.Add("keykey1", intlStr); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } sd.Add("keykey2", intlStr); if (sd.Count != len + 2) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, len + 2); } iCountTestcases++; sd.Remove("keykey2"); if (!sd.ContainsValue(intlStr)) { iCountErrors++; Console.WriteLine("Err_0003b, removed both duplicates"); } if (sd.ContainsKey("keykey2")) { iCountErrors++; Console.WriteLine("Err_0003c, removed not given instance"); } if (!sd.ContainsKey("keykey1")) { iCountErrors++; Console.WriteLine("Err_0003d, removed wrong instance"); } Console.WriteLine("4. Remove() from dictionary with intl strings"); strLoc = "Loc_004oo"; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = sd.Count; sd.Remove(intlValues[i + len]); if (sd.Count != cnt - 1) { iCountErrors++; Console.WriteLine("Err_0004b_{0}, didn't remove element with {0} key", i + len); } iCountTestcases++; if (sd.ContainsValue(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0004c_{0}, removed wrong value", i); } iCountTestcases++; if (sd.ContainsKey(intlValues[i + len])) { iCountErrors++; Console.WriteLine("Err_0004d_{0}, removed wrong key", i); } } Console.WriteLine("5. Case sensitivity"); strLoc = "Loc_005oo"; iCountTestcases++; sd.Clear(); string [] intlValuesUpper = new string [len]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToLower(); } for (int i = 0; i < len; i++) { intlValuesUpper[i] = intlValues[i + len].ToUpper(); } sd.Clear(); Console.WriteLine(" ... add Lowercased ..."); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len); } Console.WriteLine(" ... remove Uppercased ..."); for (int i = 0; i < len; i++) { iCountTestcases++; cnt = sd.Count; sd.Remove(intlValuesUpper[i]); if (sd.Count != cnt - 1) { iCountErrors++; Console.WriteLine("Err_0005b_{0}, didn't remove element with {0} lower key", i + len); } iCountTestcases++; if (sd.ContainsValue(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0005c_{0}, removed wrong value", i); } iCountTestcases++; if (sd.ContainsKey(intlValuesUpper[i])) { iCountErrors++; Console.WriteLine("Err_0005d_{0}, removed wrong key", i); } } Console.WriteLine("6. Remove(null)"); strLoc = "Loc_006oo"; iCountTestcases++; try { sd.Remove(null); iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (NullReferenceException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString()); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; Object itm; try { intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. set Item() on empty dictionary"); iCountTestcases++; cnt = hd.Count; Console.WriteLine(" - Item(null)"); try { hd[null] = valuesShort[0]; iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } iCountTestcases++; cnt = hd.Count; Console.WriteLine(" - Item(some_string)"); hd["some_string"] = valuesShort[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0001c, failed to add Item(some_string)"); } iCountTestcases++; itm = hd["some_string"]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0001d, added wrong Item(some_string)"); } Console.WriteLine("2. add few simple strings, set Item(Object)"); strLoc = "Loc_002oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, valuesShort.Length); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysShort[i]] = valuesLong[0]; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0002_{0}*, added item instead of setting", i); } itm = hd[keysShort[i]]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, failed to set item", i); } } cnt = hd.Count; iCountTestcases++; hd[keysLong[0]] = valuesLong[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0002_c, didn't add non-existing item"); } iCountTestcases++; itm = hd[keysLong[0]]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_d, failed to set item"); } Console.WriteLine("3. add many simple strings, set Item(Object)"); strLoc = "Loc_003oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[keysLong[i]] = valuesShort[0]; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0003_{0}*, added item instead of setting", i); } itm = hd[keysLong[i]]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, failed to set item", i); } } cnt = hd.Count; iCountTestcases++; hd[keysShort[0]] = valuesShort[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0003_c, didn't add non-existing item"); } iCountTestcases++; itm = hd[keysShort[0]]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_d, failed to set item"); } Console.WriteLine("4. add many intl strings and set Item()"); strLoc = "Loc_004oo"; iCountTestcases++; len = valuesLong.Length; string [] intlValues = new string [len * 2 + 1]; for (int i = 0; i < len * 2 + 1; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } string toSet = intlValues[len * 2]; iCountTestcases++; cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", hd.Count, cnt + len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[intlValues[i + len]] = toSet; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0004_{0}b, added item instead of setting", i); } itm = hd[intlValues[i + len]]; if (string.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}c, failed to set item", i); } } Console.WriteLine("5. add few intl strings and set Item()"); strLoc = "Loc_005oo"; iCountTestcases++; len = valuesShort.Length; iCountTestcases++; hd.Clear(); cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, cnt + len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[intlValues[i + len]] = toSet; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005_{0}b, added item instead of setting", i); } iCountTestcases++; itm = hd[intlValues[i + len]]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0005_{0}c, returned wrong item", i); } } Console.WriteLine("6. case sensitivity - hashtable"); strLoc = "Loc_006oo"; len = valuesLong.Length; hd.Clear(); Console.WriteLine(" - add uppercase and set via uppercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, failed to set", i); } } hd.Clear(); Console.WriteLine(" - add uppercase but set via lowercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, failed to add when setting", i); } iCountTestcases++; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}c, failed to set item", i); } iCountTestcases++; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}d, failed to preserve item", i); } } Console.WriteLine("7. case sensitivity - list"); strLoc = "Loc_007oo"; len = valuesShort.Length; Console.WriteLine(" ** fill with {0} elements", len); hd.Clear(); Console.WriteLine(" - add uppercase and set via uppercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, failed to set", i); } } hd.Clear(); Console.WriteLine(" - add uppercase but set via lowercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, failed to add when setting", i); } iCountTestcases++; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}c, failed to set item", i); } iCountTestcases++; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}d, failed to preserve item", i); } } Console.WriteLine("8. set Item() on case-insensitive HD - list"); hd = new HybridDictionary(true); strLoc = "Loc_008oo"; iCountTestcases++; len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0008a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0008b_{0}, failed to set via uppercase key", i); } iCountTestcases++; hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0008b_{0}, failed to set via lowercase key", i); } } Console.WriteLine("9. set Item() on case-insensitive HD - hashtable"); hd = new HybridDictionary(true); strLoc = "Loc_009oo"; iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0009a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b_{0}, failed to set via uppercase key", i); } iCountTestcases++; hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0009c_{0}, failed to set via lowercase key", i); } } Console.WriteLine("10. set Item(null) for filled HD - list"); hd = new HybridDictionary(); strLoc = "Loc_0010oo"; iCountTestcases++; len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } iCountTestcases++; try { hd[null] = toSet; iCountErrors++; Console.WriteLine("Err_0010a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0010b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("11. seet Item(null) for filled HD - hashtable"); hd = new HybridDictionary(); strLoc = "Loc_0011oo"; iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; try { hd[null] = toSet; iCountErrors++; Console.WriteLine("Err_0011a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0011b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("15. set Item() to null - list"); hd = new HybridDictionary(); strLoc = "Loc_0015oo"; iCountTestcases++; hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0015a, count is {0} instead of {1}", hd.Count, len); } iCountTestcases++; cnt = hd.Count; hd[keysShort[0]] = null; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0015b, added entry instead of setting"); } itm = hd[keysShort[0]]; if (itm != null) { iCountErrors++; Console.WriteLine("Err_0015c, failed to set to null"); } Console.WriteLine("16. set Item() to null - hashtable"); hd.Clear(); strLoc = "Loc_0016oo"; iCountTestcases++; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0016a, count is {0} instead of {1}", hd.Count, len); } iCountTestcases++; cnt = hd.Count; hd[keysLong[0]] = null; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0016b, added entry instead of setting"); } itm = hd[keysLong[0]]; if (itm != null) { iCountErrors++; Console.WriteLine("Err_0016c, failed to set to null"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; String str1; String strInsert; int iStartIndex; try { int[] iArrInvalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue }; int[] iArrLargeValues = new Int32[] { Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue / 2, Int32.MaxValue / 10, Int32.MaxValue / 100 }; int[] iArrValidValues = new Int32[] { 10000, 100000, Int32.MaxValue / 200, Int32.MaxValue / 1000 }; iCountTestcases++; String strNewString = "This is a tesing string"; String strTemp = new String('a', 10000); for (int iLoop = 0; iLoop < iArrInvalidValues.Length; iLoop++) { try { strNewString = strNewString.Insert(iArrInvalidValues[iLoop], strTemp); iCountErrors++; Console.Error.WriteLine("Error_0000!! Expected exception not occured"); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.Error.WriteLine("Error_2222!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++) { try { strNewString = strNewString.Insert(iArrLargeValues[iLoop], strTemp); iCountErrors++; Console.Error.WriteLine("Error_1111!! Expected exception not occured"); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.Error.WriteLine("Error_3333!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; strTemp = new String('a', Int32.MaxValue / 200); strNewString = strTemp; for (int iLoop = 0; iLoop < iArrValidValues.Length; iLoop++) { try { strNewString = strNewString.Insert(iArrValidValues[iLoop], strTemp); if (strNewString.Length != (Int32.MaxValue / 200) * (2 + iLoop)) { iCountErrors++; Console.Error.WriteLine("Error_6666!!!! Incorrect string length.... Expected...{0}, Actual...{1}", (Int32.MaxValue / 200) * (1 + iLoop), strNewString.Length); } } catch (Exception ex) { Console.Error.WriteLine("Error_7777!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } strLoc = "Loc_38947"; str1 = "\t\t"; strInsert = " "; iStartIndex = -1; iCountTestcases++; try { str1.Insert(iStartIndex, strInsert); iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_4982u"); } catch (ArgumentException) {} catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_9083u! , exc==" + exc); } strLoc = "Loc_129ew"; str1 = "\t\t"; strInsert = " "; iStartIndex = 3; iCountTestcases++; try { str1.Insert(iStartIndex, strInsert); iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_983uq"); } catch (ArgumentException) {} catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_5388g! , exc==" + exc); } strLoc = "Loc_538wi"; str1 = "\t\t"; strInsert = null; iStartIndex = 0; iCountTestcases++; try { str1.Insert(iStartIndex, strInsert); iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_128qu"); } catch (ArgumentException) {} catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_3948u! , exc==" + exc); } strLoc = "Loc_3894u"; str1 = ""; strInsert = "This is a string"; iStartIndex = 0; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals(strInsert)) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_438du"); } IntlStrings intl = new IntlStrings(); str1 = intl.GetString(19, true, true); strInsert = intl.GetString(12, false, true); iStartIndex = 0; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals(String.Concat(strInsert, str1))) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_299138du"); } strLoc = "Loc_3948r"; str1 = "This is a string"; strInsert = "\t\t\t\t"; iStartIndex = 0; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals("\t\t\t\tThis is a string")) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_8904e"); } strLoc = "Loc_3498j"; str1 = "This is a \n\n"; strInsert = "string"; iStartIndex = str1.ToCharArray().Length; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals(str1 + strInsert)) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_1289m"); } strLoc = "Loc_3487y"; str1 = "\t is a string"; strInsert = "This\t"; iStartIndex = 1; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals("\tThis\t is a string")) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_3739c"); } strLoc = "Loc_238us"; str1 = "This is a string"; strInsert = "!@#$%^&*()"; iStartIndex = str1.ToCharArray().Length - 1; iCountTestcases++; if (!str1.Insert(iStartIndex, strInsert).Equals("This is a strin!@#$%^&*()g")) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_34fdy"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringCollection sc; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. Insert into empty collection"); for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.Count > 0) { sc.Clear(); } sc.Insert(0, values[i]); if (sc.Count != 1) { iCountErrors++; Console.WriteLine("Err_0001_{0}a, Count {1} instead of 1", i, sc.Count); } if (!sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, doesn't contain just inserted item", i); } } Console.WriteLine("2. Insert into filled collection"); strLoc = "Loc_002oo"; Console.WriteLine(" - at the beginning"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length); } string val = intl.GetString(MAX_LEN, true, true, true); iCountTestcases++; sc.Insert(0, val); if (sc.Count != values.Length + 1) { iCountErrors++; Console.WriteLine("Err_0002b, Count returned {0} instead of {1}", sc.Count, values.Length + 1); } iCountTestcases++; if (sc.IndexOf(val) != 0) { iCountErrors++; Console.WriteLine("Err_0002c, IndexOf returned {0} instead of {1}", sc.IndexOf(val), 0); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.IndexOf(values[i]) != i + 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i + 1); } } Console.WriteLine(" - at the end"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002e, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.Insert(values.Length, val); if (sc.Count != values.Length + 1) { iCountErrors++; Console.WriteLine("Err_0002f, Count returned {0} instead of {1}", sc.Count, values.Length + 1); } iCountTestcases++; if (sc.IndexOf(val) != values.Length) { iCountErrors++; Console.WriteLine("Err_0002g, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.IndexOf(values[i]) != i) { iCountErrors++; Console.WriteLine("Err_0002_{0}h, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i); } } Console.WriteLine(" - into the middle"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002i, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.Insert(values.Length / 2, val); if (sc.Count != values.Length + 1) { iCountErrors++; Console.WriteLine("Err_0002j, Count returned {0} instead of {1}", sc.Count, values.Length + 1); } iCountTestcases++; if (sc.IndexOf(val) != values.Length / 2) { iCountErrors++; Console.WriteLine("Err_0002g, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length / 2); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; int expected = i; if (i >= values.Length / 2) { expected = i + 1; } if (sc.IndexOf(values[i]) != expected) { iCountErrors++; Console.WriteLine("Err_0002_{0}k, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), expected); } } Console.WriteLine("3. Insert(-1, string)"); strLoc = "Loc_003oo"; iCountTestcases++; try { sc.Insert(-1, val); iCountErrors++; Console.WriteLine("Err_0003a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0003b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("4. Insert(Count + 1, string)"); strLoc = "Loc_004oo"; iCountTestcases++; try { sc.Insert(sc.Count + 1, val); iCountErrors++; Console.WriteLine("Err_0004a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0004b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("5. Insert(Count + 2, string)"); strLoc = "Loc_005oo"; iCountTestcases++; try { sc.Insert(sc.Count + 2, val); iCountErrors++; Console.WriteLine("Err_0005a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0005b, unexpected exception: {0}", e.ToString()); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 void Test01() { IntlStrings intl; NameValueCollection nvc; // simple string values string[] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count string[] ks; // Keys array // initialize IntStrings intl = new IntlStrings(); // [] NameValueCollection is constructed as expected //----------------------------------------------------------------- nvc = new NameValueCollection(); // [] Remove() on empty collection // cnt = nvc.Count; nvc.Remove(null); if (nvc.Count != cnt) { Assert.False(true, "Error, changed collection after Remove(null)"); } cnt = nvc.Count; nvc.Remove("some_string"); if (nvc.Count != cnt) { Assert.False(true, "Error, changed collection after Remove(some_string)"); } // [] Remove() on collection filled with simple strings // cnt = nvc.Count; int len = values.Length; for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } if (nvc.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, values.Length)); } // for (int i = 0; i < len; i++) { cnt = nvc.Count; nvc.Remove(keys[i]); if (nvc.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } ks = nvc.AllKeys; if (Array.IndexOf(ks, keys[i]) > -1) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } // // Intl strings // [] Remove() on collection filled with Intl strings // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } cnt = nvc.Count; for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); } if (nvc.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = nvc.Count; nvc.Remove(intlValues[i + len]); if (nvc.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } ks = nvc.AllKeys; if (Array.IndexOf(ks, intlValues[i + len]) > -1) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } // // [] Case sensitivity // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } nvc.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key cnt = nvc.Count; nvc.Remove(intlValues[i + len]); if (nvc.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } ks = nvc.AllKeys; if (Array.IndexOf(ks, intlValues[i + len]) > -1) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } nvc.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // for (int i = 0; i < len; i++) { // lowercase key cnt = nvc.Count; nvc.Remove(intlValuesLower[i + len]); if (nvc.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item using lowercase key", i)); } ks = nvc.AllKeys; if (Array.IndexOf(ks, intlValues[i + len]) > -1) { Assert.False(true, string.Format("Error, removed wrong item using lowercase key", i)); } } // [] Remove() on filled collection - with multiple items with the same key // nvc.Clear(); len = values.Length; string k = "keykey"; string k1 = "hm1"; for (int i = 0; i < len; i++) { nvc.Add(k, "Value" + i); nvc.Add(k1, "iTem" + i); } if (nvc.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, 2)); } nvc.Remove(k); if (nvc.Count != 1) { Assert.False(true, "Error, failed to remove item"); } ks = nvc.AllKeys; if (Array.IndexOf(ks, k) > -1) { Assert.False(true, "Error, removed wrong item"); } nvc.Remove(k1); if (nvc.Count != 0) { Assert.False(true, "Error, failed to remove item"); } ks = nvc.AllKeys; if (Array.IndexOf(ks, k1) > -1) { Assert.False(true, "Error, removed wrong item"); } // // [] Remove(null) - when there is an item with null-key // cnt = nvc.Count; nvc.Add(null, "nullValue"); if (nvc.Count != cnt + 1) { Assert.False(true, "Error, failed to add item with null-key"); } if (nvc[null] == null) { Assert.False(true, "Error, didn't add item with null-key"); } cnt = nvc.Count; nvc.Remove(null); if (nvc.Count != cnt - 1) { Assert.False(true, "Error, failed to remove item"); } if (nvc[null] != null) { Assert.False(true, "Error, didn't remove item with null-key"); } // // [] Remove(null) - when no item with null key // nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } cnt = nvc.Count; nvc.Remove(null); if (nvc.Count != cnt) { Assert.False(true, "Error, removed something "); } }
public void Test01() { IntlStrings intl; ListDictionary ld; // simple string values string[] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); // [] ListDictionary is constructed as expected //----------------------------------------------------------------- ld = new ListDictionary(); // [] Add simple strings // for (int i = 0; i < values.Length; i++) { cnt = ld.Count; ld.Add(keys[i], values[i]); if (ld.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1)); } // access the item // if (String.Compare(ld[keys[i]].ToString(), values[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[keys[i]], values[i])); } } // // [] Add Intl strings // Intl strings // int len = values.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = ld.Count; ld.Add(intlValues[i + len], intlValues[i]); if (ld.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1)); } // access the item // if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i])); } } // // [] Case sensitivity // Casing doesn't change ( keys are not converted to lower!) // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } ld.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = ld.Count; ld.Add(intlValues[i + len], intlValues[i]); if (ld.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1)); } // access the item // if (ld[intlValues[i + len]] == null) { Assert.False(true, string.Format("Error, returned null", i)); } else { if (!ld[intlValues[i + len]].Equals(intlValues[i])) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i + len]], intlValues[i])); } } // verify that dictionary doesn't contains lowercase item // if (!caseInsensitive && ld[intlValuesLower[i + len]] != null) { Assert.False(true, string.Format("Error, returned non-null", i)); } } // // [] Add multiple values with the same key // Add multiple values with the same key - ArgumentException expected // ld.Clear(); len = values.Length; string k = "keykey"; ld.Add(k, "value"); Assert.Throws <ArgumentException>(() => { ld.Add(k, "newvalue"); }); // // [] Add(string, null) // Add null value // cnt = ld.Count; k = "kk"; ld.Add(k, null); if (ld.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, cnt + 1)); } // verify that dictionary contains null // if (ld[k] != null) { Assert.False(true, string.Format("Error, returned non-null on place of null")); } // // [] Add(null, string) // Add item with null key - ArgumentNullException expected // cnt = ld.Count; Assert.Throws <ArgumentNullException>(() => { ld.Add(null, "item"); }); // // [] Add duplicate values // ld.Clear(); for (int i = 0; i < values.Length; i++) { cnt = ld.Count; ld.Add(keys[i], "value"); if (ld.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, ld.Count, cnt + 1)); } // access the item // if (!ld[keys[i]].Equals("value")) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, ld[keys[i]], "value")); } } // verify Keys and Values if (ld.Keys.Count != values.Length) { Assert.False(true, string.Format("Error, Keys contains {0} instead of {1}", ld.Keys.Count, values.Length)); } if (ld.Values.Count != values.Length) { Assert.False(true, string.Format("Error, Values contains {0} instead of {1}", ld.Values.Count, values.Length)); } }
public virtual bool runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "123_er"; String strInfo = null; Console.Out.Write(strName); Console.Out.Write(": "); Console.Out.Write(strPath + strTest); Console.Out.WriteLine(" runTest started..."); String str1 = "Dill Guv Dill Guv Dill"; String str2 = null; try { LABEL_860_GENERAL: do { IntlStrings intl = new IntlStrings(); String str5 = intl.GetString(8, true, true); String str6 = intl.GetString(3, true, true); str6 = String.Concat(str5, str6); if (str6.StartsWith(str5) == false) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_208bt"; Console.WriteLine(strTest + strInfo); } ++iCountTestcases; str2 = "Dill "; if (str1.StartsWith(str2) == false) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke"; Console.WriteLine(strTest + strInfo); } str2 = "DILL "; if (str1.StartsWith(str2) == true) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_532dh"; Console.WriteLine(strTest + strInfo); } str2 = " "; if (str1.StartsWith(str2) == true) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_053kd"; Console.WriteLine(strTest + strInfo); } strLoc = "E_620pf"; str2 = String.Empty; if (str1.StartsWith(str2) == false) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_260is"; Console.WriteLine(strTest + strInfo); } str2 = null; try { str1.StartsWith(str2); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_304_jk"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException ex) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_278pw"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } str2 = " "; str1 = null; try { str1.StartsWith(str2); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_935ep "; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (NullReferenceException ex) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_267mo"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_103! strLoc==" + strLoc + " ,exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public void Test01() { IntlStrings intl; NameValueCollection nvc; // simple string values string[] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count string itm; // item // initialize IntStrings intl = new IntlStrings(); // [] NameValueCollection is constructed as expected //----------------------------------------------------------------- nvc = new NameValueCollection(); // [] get Item() on empty collection // Assert.Throws <ArgumentOutOfRangeException>(() => { itm = nvc[-1]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { itm = nvc[0]; }); // [] get Item() on collection filled with simple strings // cnt = nvc.Count; int len = values.Length; for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } if (nvc.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, values.Length)); } for (int i = 0; i < len; i++) { if (String.Compare(nvc[i], values[i]) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[i], values[i])); } } // // Intl strings // [] get Item() on collection filled with Intl strings // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant()) { caseInsensitive = true; } } nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); } if (nvc.Count != (len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, len)); } for (int i = 0; i < len; i++) { // if (String.Compare(nvc[i], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned \"{1}\" instead of \"{2}\"", i, nvc[i], intlValues[i])); } } // // [] Case sensitivity // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } nvc.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // for (int i = 0; i < len; i++) { // if (String.Compare(nvc[i], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned \"{1}\" instead of \"{2}\"", i, nvc[i], intlValues[i])); } if (!caseInsensitive && String.Compare(nvc[i], intlValuesLower[i]) == 0) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } // [] get Item() on filled collection - multiple items with the same key // nvc.Clear(); len = values.Length; string k = "keykey"; string k1 = "hm1"; string exp = ""; string exp1 = ""; for (int i = 0; i < len; i++) { nvc.Add(k, "Value" + i); nvc.Add(k1, "iTem" + i); if (i < len - 1) { exp += "Value" + i + ","; exp1 += "iTem" + i + ","; } else { exp += "Value" + i; exp1 += "iTem" + i; } } if (nvc.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, 2)); } if (String.Compare(nvc[0], exp) != 0) { Assert.False(true, string.Format("Error, returned \"{0}\" instead of \"{1}\"", nvc[0], exp)); } if (String.Compare(nvc[1], exp1) != 0) { Assert.False(true, string.Format("Error, returned \"{0}\" instead of \"{1}\"", nvc[1], exp1)); } // // [] Item(-1) // cnt = nvc.Count; Assert.Throws <ArgumentOutOfRangeException>(() => { itm = nvc[-1]; }); // // [] Item(count) // if (nvc.Count < 1) { for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } } cnt = nvc.Count; Assert.Throws <ArgumentOutOfRangeException>(() => { itm = nvc[cnt]; }); // // [] Item(count+1) // if (nvc.Count < 1) { for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } } cnt = nvc.Count; Assert.Throws <ArgumentOutOfRangeException>(() => { itm = nvc[cnt + 1]; }); // // [] Item(null) // Item(null) - calls other overloaded version of Get - Get(string) - no exception // itm = nvc[null]; if (itm != null) { Assert.False(true, "Error, returned non-null "); } }
public Boolean runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "123_er"; String strInfo = null; Console.Out.Write(strName); Console.Out.Write(": "); Console.Out.Write(strPath + strTest); Console.Out.WriteLine(" runTest started..."); String str1 = "Dill Guv Dill Guv Dill"; Char[] chArr1 = { 'G', 'M', 'X', 'Y', 'Z' }; Char[] chArr2 = null; try { LABEL_860_GENERAL: do { IntlStrings intl = new IntlStrings(); Char[] myCharArr = { '!', '@' }; String myIntlString = intl.GetString(10, true, true); myIntlString = String.Concat(myIntlString, "!@!!@"); if (myIntlString.IndexOfAny(myCharArr) > 15) { ++iCountErrors; } chArr1[3] = '\0'; ++iCountTestcases; if (str1.IndexOfAny(chArr1) != 5) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke "; Console.WriteLine(strTest + strInfo); } chArr1[3] = 'Y'; chArr1[0] = 'X'; chArr1[3] = 'D'; ++iCountTestcases; if (str1.IndexOfAny(chArr1) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_892dds "; Console.WriteLine(strTest + strInfo); } chArr1[0] = 'G'; chArr1[3] = 'Y'; chArr1[0] = 'X'; ++iCountTestcases; if (str1.IndexOfAny(chArr1) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_739cp"; Console.WriteLine(strTest + strInfo); } chArr1[0] = 'G'; chArr1[0] = 'G'; chArr1[3] = 'D'; ++iCountTestcases; if (str1.IndexOfAny(chArr1) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_720mr"; Console.WriteLine(strTest + strInfo); } chArr1[0] = 'G'; chArr1[3] = 'Y'; chArr1[0] = '\0'; ++iCountTestcases; if (str1.IndexOfAny(chArr1) != -1) { ++iCountErrors; strInfo += "FAiL. E_240hg "; strInfo += ", Exception not thrown ==" + (str1.IndexOfAny(chArr1)).ToString(); Console.WriteLine(strTest + strInfo); } try { ++iCountTestcases; str1.IndexOfAny(chArr2); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_248ko"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException ex) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_034fl"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } str1 = null; try { ++iCountTestcases; str1.IndexOfAny(chArr1); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_015qp "; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (NullReferenceException ex) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_104nu"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_103! strLoc==" + strLoc + " ,exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringCollection sc; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. Check for empty collection"); for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0001_{0}, returned true for empty collection", i); } } Console.WriteLine("2. add simple strings and verify Contains()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (!sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, collection doesn't contain item \"{1}\"", i, values[i]); } } Console.WriteLine("3. add intl strings and verify Contains()"); strLoc = "Loc_003oo"; string [] intlValues = new string [values.Length]; for (int i = 0; i < values.Length; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } int len = values.Length; Boolean caseInsensitive = false; for (int i = 0; i < len; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } iCountTestcases++; cnt = sc.Count; sc.AddRange(intlValues); if (sc.Count != (cnt + intlValues.Length)) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, cnt + intlValues.Length); } for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; if (!sc.Contains(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, collection doesn't contain item \"{1}\"", i, intlValues[i]); } } Console.WriteLine("4. Add a very long string and verify Contains()"); strLoc = "Loc_004oo"; iCountTestcases++; cnt = sc.Count; string intlStr = intlValues[0]; while (intlStr.Length < 10000) { intlStr += intlStr; } Console.WriteLine(" - add string of Length " + intlStr.Length); sc.Add(intlStr); if (sc.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0004a, count is {1} instead of {2}", sc.Count, cnt + 1); } iCountTestcases++; if (!sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0004b, collection doesn't contain new item"); } Console.WriteLine("5. Case sensitivity"); strLoc = "Loc_003oo"; iCountTestcases++; sc.Clear(); if (sc.Count != 0) { iCountErrors++; Console.WriteLine("Err_0005, count is {1} instead of {2} after Clear()", sc.Count, 0); } intlStr = intlValues[0].ToUpper(); iCountTestcases++; sc.Add(intlStr); if (sc.Count != 1) { iCountErrors++; Console.WriteLine("Err_0005a, count is {1} instead of {2}", sc.Count, 1); } iCountTestcases++; if (!sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0005b, Contains() returned false "); } intlStr = intlValues[0].ToLower(); iCountTestcases++; if (!caseInsensitive && sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0005c, Contains() returned true for lowercase version"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; String strBaseLoc = ""; String str1, str2; Char ch; Byte byt1a; SByte sbyt1a; Int16 in2a; Int32 in4a; Int64 in8a; Single sgl2; Double dbl2; Decimal dec2; try { LABEL_860_GENERAL: do { try { str1 = ""; ch = ' '; iCountTestcases++; if (str1.CompareTo(ch) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_394qi ,ch=[" + ch + "] ,str1=[" + str1 + "]"); } } catch (ArgumentException aexc) {} try { str1 = ""; byt1a = 0; iCountTestcases++; if (str1.CompareTo(byt1a) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_219qi"); } } catch (ArgumentException aexc) {} try { str1 = ""; sbyt1a = 0; iCountTestcases++; if (str1.CompareTo(sbyt1a) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_3849a"); } } catch (ArgumentException aexc) {} try { str1 = ""; in2a = 0; iCountTestcases++; if (str1.CompareTo(in2a) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_498uw"); } } catch (ArgumentException aexc) {} IntlStrings intl = new IntlStrings(); String intlString = intl.GetString(10, false, true); Object obj = (object)intlString; iCountTestcases++; if (intlString.CompareTo(obj) != 0) { ++iCountErrors; Console.WriteLine(intlString); } try { str1 = ""; in4a = 0; iCountTestcases++; if (str1.CompareTo(in4a) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_948qj"); } } catch (ArgumentException aexc) {} iCountTestcases++; try { str1 = ""; in8a = 0; iCountTestcases++; if (str1.CompareTo(in8a) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_983jq"); } } catch (ArgumentException aexc) {} iCountTestcases++; try { str1 = ""; sgl2 = 0; iCountTestcases++; if (str1.CompareTo(sgl2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_482ua"); } } catch (ArgumentException aexc) {} try { str1 = ""; dbl2 = 0; iCountTestcases++; if (str1.CompareTo(dbl2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_32580"); } } catch (ArgumentException aexc) {} try { str1 = ""; dec2 = 0; iCountTestcases++; if (str1.CompareTo(dec2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_480rr"); } } catch (ArgumentException aexc) {} str1 = ""; iCountTestcases++; try { if (str1.CompareTo(null) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + " Err_493ca"); } } catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_583oi"); } str1 = String.Empty; iCountTestcases++; if (str1.CompareTo("") != 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_938us"); } str1 = "blaH"; str2 = "blah"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_3940i"); } strLoc = "Loc_837hd"; str1 = "0"; str2 = "{"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_371eh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_192hw"; str1 = "z"; str2 = "{"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_732qu! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_128yr"; str1 = "A"; str2 = "*"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_347hw! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_834yw"; str1 = "0"; str2 = "$"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_289nk! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_372hu"; str1 = "0"; str2 = "5"; iCountTestcases++; if (str1.CompareTo(str2) >= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_793rh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_373hu"; str1 = "5"; str2 = "0"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_794rh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_373hu"; str1 = "5"; str2 = "0"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_794rh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_373hu"; str1 = "A"; str2 = "a"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_894rh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_481hu"; str1 = "A"; str2 = "B"; iCountTestcases++; if (str1.CompareTo(str2) >= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_933jw! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_473hu"; str1 = "a"; str2 = "A"; iCountTestcases++; if (str1.CompareTo(str2) >= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_812ks! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_751hu"; str1 = "B"; str2 = "A"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_941jd! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_573hu"; str1 = "}"; str2 = "<"; iCountTestcases++; if (str1.CompareTo(str2) >= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_094rh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_673hu"; str1 = "<"; str2 = "{"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_099uh! , result==" + str1.CompareTo(str2)); } strLoc = "Loc_683hu"; str1 = "A"; str2 = "0"; iCountTestcases++; if (str1.CompareTo(str2) <= 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_134eh! , result==" + str1.CompareTo(str2)); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public void Test01() { IntlStrings intl; StringCollection sc; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string[] destination; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); // [] StringCollection is constructed as expected //----------------------------------------------------------------- sc = new StringCollection(); // [] Copy empty collection into empty array // destination = new string[values.Length]; for (int i = 0; i < values.Length; i++) { destination[i] = ""; } sc.CopyTo(destination, 0); if (destination.Length != values.Length) { Assert.False(true, string.Format("Error, altered array after copying empty collection")); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { if (String.Compare(destination[i], "") != 0) { Assert.False(true, string.Format("Error, item = \"{1}\" insteead of \"{2}\" after copying empty collection", i, destination[i], "")); } } } // [] Copy empty collection into non-empty array // destination = values; sc.CopyTo(destination, 0); if (destination.Length != values.Length) { Assert.False(true, string.Format("Error, altered array after copying empty collection")); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { if (String.Compare(destination[i], values[i]) != 0) { Assert.False(true, string.Format("Error, altered item {0} after copying empty collection", i)); } } } // // [] add simple strings and CopyTo([], 0) cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length)); } destination = new string[values.Length]; sc.CopyTo(destination, 0); for (int i = 0; i < values.Length; i++) { // verify that collection is copied correctly // if (String.Compare(sc[i], destination[i]) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, destination[i], sc[i])); } } // [] add simple strings and CopyTo([], middle_index) // sc.Clear(); cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length)); } destination = new string[values.Length * 2]; sc.CopyTo(destination, values.Length); for (int i = 0; i < values.Length; i++) { // verify that collection is copied correctly // if (String.Compare(sc[i], destination[i + values.Length]) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, destination[i + values.Length], sc[i])); } } // // Intl strings // [] add intl strings and CopyTo([], 0) // string[] intlValues = new string[values.Length]; // fill array with unique strings // for (int i = 0; i < values.Length; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } sc.Clear(); sc.AddRange(intlValues); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } destination = new string[intlValues.Length]; sc.CopyTo(destination, 0); for (int i = 0; i < intlValues.Length; i++) { // verify that collection is copied correctly // if (String.Compare(sc[i], destination[i]) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, destination[i], sc[i])); } } // // Intl strings // [] add intl strings and CopyTo([], middle_index) // sc.Clear(); sc.AddRange(intlValues); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } destination = new string[intlValues.Length * 2]; sc.CopyTo(destination, intlValues.Length); for (int i = 0; i < intlValues.Length; i++) { // verify that collection is copied correctly // if (String.Compare(sc[i], destination[i + intlValues.Length]) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, destination[i + intlValues.Length], sc[i])); } } // // [] CopyTo(null, int) // sc.Clear(); sc.AddRange(values); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } destination = null; Assert.Throws <ArgumentNullException>(() => { sc.CopyTo(destination, 0); }); // // [] CopyTo(string[], -1) // if (sc.Count != values.Length) { sc.Clear(); sc.AddRange(values); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } } destination = new string[values.Length]; Assert.Throws <ArgumentOutOfRangeException>(() => { sc.CopyTo(destination, -1); }); // // [] CopyTo(string[], upperBound+1) // if (sc.Count != values.Length) { sc.Clear(); sc.AddRange(values); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } } destination = new string[values.Length]; Assert.Throws <ArgumentException>(() => { sc.CopyTo(destination, values.Length); }); // // [] CopyTo(string[], upperBound+2) // if (sc.Count != values.Length) { sc.Clear(); sc.AddRange(values); if (sc.Count != (intlValues.Length + 1)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } } destination = new string[values.Length]; Assert.Throws <ArgumentException>(() => { sc.CopyTo(destination, values.Length); }); // // [] CopyTo(string[], not_enough_space) // if (sc.Count != values.Length) { sc.Clear(); sc.AddRange(values); if (sc.Count != (intlValues.Length)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, intlValues.Length)); } } destination = new string[values.Length]; Assert.Throws <ArgumentException>(() => { sc.CopyTo(destination, values.Length / 2); }); }
public virtual bool runTest () { System.Console.Error.WriteLine("String.LastIndexOf: Co1160LIO runTest starting..."); int iCountTestcases = 0; int nErrorBits = 0; int n2 = -2; String strLoc = "Loc_000oo"; System.String swrString2 = null; System.String swrString3 = null; System.String swrString4 = null; int iResult = 0; int[] iArrInvalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue }; int[] iArrLargeValues = new Int32[] { Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue / 2, Int32.MaxValue / 10, Int32.MaxValue / 100, 100000, 10000, 1000, 100, 21 }; int[] iArrValidValues = new Int32[] { 100000, 99999, 10000, 1000, 100, 10, 1, 0 }; IntlStrings intl = new IntlStrings(); String intlString = intl.GetString(20, true, true); iCountTestcases++; for (int iLoop = 0; iLoop < iArrInvalidValues.Length; iLoop++) { try { iResult = intlString.LastIndexOf(intlString[5], iArrInvalidValues[iLoop]); nErrorBits++; Console.WriteLine("Error_0000!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_2222!!! Unexpected exception " + ex.ToString()); nErrorBits++; } } iCountTestcases++; for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++) { try { iResult = intlString.LastIndexOf(intlString[5], iArrLargeValues[iLoop]); nErrorBits++; Console.WriteLine("Error_1111!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_3333!!! Unexpected exception " + ex.ToString()); nErrorBits++; } } iCountTestcases++; intlString = intl.GetString(100002, true, true); for (int iLoop = 0; iLoop < iArrValidValues.Length; iLoop++) { try { iResult = intlString.LastIndexOf(intlString[iArrValidValues[iLoop]], intlString.Length - 1); if (iResult == -1) { nErrorBits++; Console.WriteLine("Error_6666!!!! Incorrect LastIndexOf value.... Actual...{0}", iResult); } } catch (Exception ex) { Console.WriteLine("Error_7777!!! Unexpected exception " + ex.ToString()); nErrorBits++; } } try { iCountTestcases++; swrString2 = "abc X def X ghi"; n2 = swrString2.LastIndexOf('i', 13); if (n2 != -1) { nErrorBits = nErrorBits | 0x1; } strLoc = "Loc_304sd"; try { swrString2 = "abc X def X ghi"; n2 = swrString2.LastIndexOf('i', -1); nErrorBits = nErrorBits | 0x2; } catch (ArgumentException) { } catch (Exception) { nErrorBits = nErrorBits | 0x40; } iCountTestcases++; strLoc = "Loc_204_os"; try { n2 = swrString2.LastIndexOf('I', -1); nErrorBits = nErrorBits | 0x10; } catch (ArgumentException) { } catch (Exception) { nErrorBits = nErrorBits | 0x80; } iCountTestcases++; strLoc = "Loc_038_ai"; swrString2 = "abc X def X ghi"; n2 = swrString2.LastIndexOf('c', 2); if (n2 != 2) { nErrorBits = nErrorBits | 0x4; } iCountTestcases++; strLoc = "Loc_543_lw"; swrString2 = "abc X def X ghi"; n2 = swrString2.LastIndexOf('X', 7); if (n2 != 4) { nErrorBits = nErrorBits | 0x8; } intl = new IntlStrings(); swrString2 = intl.GetString(4, true, true); swrString3 = intl.GetString(1, true, true); swrString4 = String.Concat(swrString2, swrString3); swrString4 = String.Concat(swrString4, swrString2); swrString4 = String.Concat(swrString4, swrString3); swrString4 = String.Concat(swrString4, swrString2); n2 = swrString4.LastIndexOf(swrString3[0], 7); if (n2 < 4) { nErrorBits = nErrorBits | 0x8; } } catch (Exception ex) { Console.Error.WriteLine("POINTTOBREAK: Error Err_343un! (Co1160LastIndexOf_CharInt) ex==" + ex); Console.Error.WriteLine("EXTENDEDINFO: (Err_343un) strLoc==" + strLoc); nErrorBits = nErrorBits | 0x20; } System.Console.Error.Write("String.LastIndexOf: Co1160LIO nErrorBits=="); System.Console.Error.WriteLine(nErrorBits); if (nErrorBits == 0) { return(true); } else { return(false); } }
public void Test01() { IntlStrings intl; NameValueCollection nvc; NameValueCollection nvc1; // simple string values string[] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); // [] NameValueCollection is constructed as expected //----------------------------------------------------------------- nvc = new NameValueCollection(); nvc1 = new NameValueCollection(); // [] Add(empty_coll) to empty collection // nvc.Clear(); nvc1.Clear(); nvc.Add(nvc1); if (nvc.Count != 0) { Assert.False(true, string.Format("Error, count is {0} instead of 0", nvc.Count)); } // [] Add(simple_strings_coll) to empty collection // nvc.Clear(); cnt = nvc.Count; int len = values.Length; for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } if (nvc.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, values.Length)); } nvc1.Clear(); nvc1.Add(nvc); if (nvc1.Count != nvc.Count) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, nvc.Count)); } // for (int i = 0; i < len; i++) { if (String.Compare(nvc1[keys[i]], values[i]) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i])); } } // [] Add(simple_strings_coll) to simple_string_collection // len = values.Length; if (nvc.Count < len) { nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } } nvc1.Clear(); for (int i = 0; i < len; i++) { nvc1.Add("k" + i, "v" + i); } cnt = nvc1.Count; nvc1.Add(nvc); if (nvc1.Count != cnt + nvc.Count) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, cnt + nvc.Count)); } // for (int i = 0; i < len; i++) { if (String.Compare(nvc1[keys[i]], values[i]) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i])); } if (String.Compare(nvc1["k" + i], "v" + i) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc["k" + i], "v" + i)); } } // // Intl strings // [] Add(intl_strings_coll) to empty collection // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant()) { caseInsensitive = true; } } // fill init collection with intl strings nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); } if (nvc.Count != (len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, len)); } // add filled collection to tested empty collection nvc1.Clear(); nvc1.Add(nvc); for (int i = 0; i < len; i++) { // if (String.Compare(nvc1[intlValues[i + len]], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned \"{1}\" instead of \"{2}\"", i, nvc1[intlValues[i + len]], intlValues[i])); } } // // [] Case sensitivity // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } nvc.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // add uppercase to tested collection nvc1.Clear(); nvc1.Add(nvc); // for (int i = 0; i < len; i++) { // uppercase key if (String.Compare(nvc1[intlValues[i + len]], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned \"{1}\" instead of \"{2}\"", i, nvc1[intlValues[i + len]], intlValues[i])); } // lowercase key if (String.Compare(nvc1[intlValuesLower[i + len]], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned \"{1}\" instead of \"{2}\"", i, nvc1[intlValuesLower[i + len]], intlValues[i])); } if (!caseInsensitive && (String.Compare(nvc1[intlValues[i + len]], intlValuesLower[i]) == 0)) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } // // when adding values with existing keys, values should be added to existing values // [] Add(NVC) with already existing keys // nvc.Clear(); cnt = nvc.Count; len = values.Length; for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } if (nvc.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, values.Length)); } nvc1.Clear(); for (int i = 0; i < len; i++) { nvc1.Add(keys[i], values[i]); } if (nvc1.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, values.Length)); } cnt = nvc1.Count; nvc1.Add(nvc); // count should not change if (nvc1.Count != cnt) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, cnt)); } // values should be added to previously existed values for (int i = 0; i < len; i++) { if (String.Compare(nvc1[keys[i]], values[i] + "," + values[i]) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i] + "," + values[i])); } } // [] multiple items with same key // nvc.Clear(); len = values.Length; string k = "keykey"; string k1 = "hm1"; string exp = ""; string exp1 = ""; for (int i = 0; i < len; i++) { nvc.Add(k, "Value" + i); nvc.Add(k1, "iTem" + i); if (i < len - 1) { exp += "Value" + i + ","; exp1 += "iTem" + i + ","; } else { exp += "Value" + i; exp1 += "iTem" + i; } } if (nvc.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, 2)); } // add NVC nvc1.Clear(); nvc1.Add(nvc); if (String.Compare(nvc1[k], exp) != 0) { Assert.False(true, string.Format("Error, returned \"{0}\" instead of \"{1}\"", nvc1[k], exp)); } // Values array should contain len items if (nvc1.GetValues(k).Length != len) { Assert.False(true, string.Format("Error, number of values is {0} instead of {1}", nvc1.GetValues(k).Length, len)); } for (int i = 0; i < len; i++) { if (String.Compare(nvc1.GetValues(k)[i], "Value" + i) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", i, nvc1.GetValues(k)[i], "Value" + i)); } } if (String.Compare(nvc1[k1], exp1) != 0) { Assert.False(true, string.Format("Error, returned \"{0}\" instead of \"{1}\"", nvc1[k1], exp1)); } // Values array should contain len items if (nvc1.GetValues(k1).Length != len) { Assert.False(true, string.Format("Error, number of values is {0} instead of {1}", nvc1.GetValues(k1).Length, len)); } for (int i = 0; i < len; i++) { if (String.Compare(nvc1.GetValues(k1)[i], "iTem" + i) != 0) { Assert.False(true, string.Format("Error, returned {1} instead of {2}", i, nvc1.GetValues(k1)[i], "iTem" + i)); } } // // [] Add(with_null_key) when there is item with null key // cnt = nvc.Count; nvc.Add(null, "nullValue"); nvc1[null] = "nullValue1"; nvc1.Add(nvc); if (String.Compare(nvc1[null], "nullValue1," + nvc[null]) != 0) { Assert.False(true, string.Format("Error, returned \"{0}\" instead of \"{1}\"", nvc1[null], "nullValue1," + nvc[null])); } // // [] Add(with_null_key) when there is no item with null key // nvc.Clear(); nvc1.Clear(); for (int i = 0; i < len; i++) { nvc1.Add(keys[i], values[i]); } nvc[null] = "newNullValue"; nvc1.Add(nvc); if (String.Compare(nvc1[null], "newNullValue") != 0) { Assert.False(true, "Error, returned unexpected value "); } // // [] Add(null_collection) // try { nvc1.Add(null); Assert.False(true, "Error, no exception"); } catch (ArgumentNullException) { } catch (Exception e) { Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString())); } // // [] Add(empty_coll) to filled collection // nvc.Clear(); if (nvc1.Count < len) { nvc1.Clear(); for (int i = 0; i < len; i++) { nvc1.Add(keys[i], values[i]); } if (nvc1.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, values.Length)); } } cnt = nvc1.Count; nvc1.Add(nvc); if (nvc1.Count != cnt) { Assert.False(true, string.Format("Error, count has changed: {0} instead of {1}", nvc1.Count, cnt)); } // verify that collection has not changed for (int i = 0; i < len; i++) { if (String.Compare(nvc1[keys[i]], values[i]) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i])); } } // // [] Add collection with null values // nvc.Clear(); nvc1.Clear(); for (int i = 0; i < len; i++) { nvc.Add(keys[i], null); } nvc1.Add(nvc); if (nvc1.Count != nvc.Count) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc1.Count, nvc.Count)); } // for (int i = 0; i < len; i++) { if (String.Compare(nvc1[keys[i]], null) != 0) { Assert.False(true, string.Format("Error, returned: \"{1}\", expected \"{2}\"", i, nvc[keys[i]], values[i])); } } }
public virtual bool runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "123_er"; String strInfo = null; Console.Out.Write(strName); Console.Out.Write(": "); Console.Out.Write(strPath + strTest); Console.Out.WriteLine(" runTest started..."); String str1 = String.Empty; try { int iResult = 0; int[] iArrInvalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue }; int[] iArrLargeValues = new Int32[] { Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue / 2, Int32.MaxValue / 10, Int32.MaxValue / 100, 100000, 10000, 1000, 100, 21 }; int[] iArrValidValues = new Int32[] { 100000, 99999, 10000, 1000, 100, 10, 1, 0 }; IntlStrings intl = new IntlStrings(); String intlString = intl.GetString(20, true, true); str1 = intlString.Substring(5, 5); iCountTestcases++; for (int iLoop = 0; iLoop < iArrInvalidValues.Length; iLoop++) { try { iResult = intlString.IndexOf(str1, iArrInvalidValues[iLoop]); iCountErrors++; Console.WriteLine("Error_0000!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_2222!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++) { try { iResult = intlString.IndexOf(str1, iArrLargeValues[iLoop]); iCountErrors++; Console.WriteLine("Error_1111!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_3333!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; intlString = intl.GetString(100002, true, true); str1 = intlString.Substring(100000, 2); for (int iLoop = 0; iLoop < iArrValidValues.Length; iLoop++) { try { iResult = intlString.IndexOf(str1, iArrValidValues[iLoop]); if (iResult == -1) { iCountErrors++; Console.WriteLine("Error_6666!!!! Incorrect IndexOf value.... Actual...{0}", iResult); } } catch (Exception ex) { Console.WriteLine("Error_7777!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } str1 = "Dill Guv Dill Guv Dill"; String str2 = "Dill"; ++iCountTestcases; if (str1.IndexOf(str2, 0) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke "; Console.WriteLine(strTest + strInfo); } intl = new IntlStrings(); String myIntlString = intl.GetString(5, true, true); String myIntlString2 = intl.GetString(13, true, true); myIntlString = String.Concat(myIntlString, myIntlString2); if (myIntlString.IndexOf(myIntlString2, 0) != 5) { ++iCountErrors; } if (str1.IndexOf(str2, 1) != 9) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_767fq "; Console.WriteLine(strTest + strInfo); } if (str1.IndexOf(str2, 19) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_013oi "; Console.WriteLine(strTest + strInfo); } str2 = "Dill Guv Dill Guv Dill"; if (str1.IndexOf(str2, 0) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_892dds "; Console.WriteLine(strTest + strInfo); } str2 = "Dill Guv Dill Guv Dill Dill Bill"; if (str1.IndexOf(str2, 0) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_256we "; Console.WriteLine(strTest + strInfo); } str2 = "ll"; if (str1.IndexOf(str2, 15) != 20) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_739cp"; Console.WriteLine(strTest + strInfo); } str2 = "Bill"; if (str1.IndexOf(str2, 0) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_720mr"; Console.WriteLine(strTest + strInfo); } str2 = "DILL"; if (str1.IndexOf(str2, 0) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_249vu"; Console.WriteLine(strTest + strInfo); } str2 = " "; if (str1.IndexOf(str2, 10) != 13) { ++iCountErrors; strInfo += "FAiL. E_240hg "; strInfo += ", Exception not thrown ==" + (str1.IndexOf(str2)).ToString(); Console.WriteLine(strTest + strInfo); } str2 = ""; if (str1.IndexOf(str2, 5) != 5) { ++iCountErrors; strInfo += "FAiL. E_235jf "; strInfo += ", Index ==" + "< " + (str1.IndexOf(str2)).ToString() + " >"; Console.WriteLine(strTest + strInfo); } try { str2 = "Dill"; str1.IndexOf(str2, 23); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_067sf"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_161gh"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } try { str2 = "Dill"; str1.IndexOf(str2, -50); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_135tq"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_175sg"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } try { str2 = null; str1.IndexOf(str2, 0); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_248ko"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_034fl"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } str1 = null; try { str1.IndexOf(str2, 9); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_015qp "; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (NullReferenceException) {} catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_104nu"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_103! strLoc==" + strLoc + " ,exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public void Test01() { IntlStrings intl; HybridDictionary hd; // simple string values string[] valuesShort = Test_EdgeCases(); // keys for simple string values string[] keysShort = Test_EdgeCases(); string[] valuesLong = TestValues(100); string[] keysLong = TestKeys(100); int cnt = 0; // Count Object itm; // Item // initialize IntStrings intl = new IntlStrings(); // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] get Item() on empty dictionary // cnt = hd.Count; Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); cnt = hd.Count; itm = hd["some_string"]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for Item(some_string)")); } cnt = hd.Count; itm = hd[new Hashtable()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for Item(some_object)")); } // [] get Item() on short dictionary with simple strings // cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; itm = hd[keysShort[i]]; if (String.Compare(itm.ToString(), valuesShort[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on long dictionary with simple strings // hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; itm = hd[keysLong[i]]; if (String.Compare(itm.ToString(), valuesLong[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on long dictionary with Intl strings // Intl strings // len = valuesLong.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) val = intl.GetRandomString(MAX_LEN); intlValues[i] = val; } cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; itm = hd[intlValues[i + len]]; if (string.Compare(itm.ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on short dictionary with Intl strings // len = valuesShort.Length; hd.Clear(); cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; itm = hd[intlValues[i + len]]; if (String.Compare(itm.ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // // [] Case sensitivity - hashtable // len = valuesLong.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) == 0) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default for (int i = 0; i < len; i++) { // lowercase key itm = hd[keysLong[i].ToLower()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for lowercase key", i)); } } // // [] Case sensitivity - list // len = valuesShort.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) == 0) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default for (int i = 0; i < len; i++) { // lowercase key itm = hd[keysLong[i].ToLower()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for lowercase key", i)); } } // // [] get Item() in case-insensitive HD - list // hd = new HybridDictionary(true); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for uppercase key", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item - for lowercase key", i)); } } // [] get Item() in case-insensitive HD - hashtable // hd = new HybridDictionary(true); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for uppercase key", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for lowercase key", i)); } } // // [] get Item(null) on filled HD - list // hd = new HybridDictionary(); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); // [] get Item(null) on filled HD - hashtable // hd = new HybridDictionary(); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); // // [] get Item(special_object) on filled HD - list // hd = new HybridDictionary(); hd.Clear(); len = 2; ArrayList[] b = new ArrayList[len]; Hashtable[] lbl = new Hashtable[len]; for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[lbl[i]]; if (!itm.Equals(b[i])) { Assert.False(true, string.Format("Error, returned wrong special object")); } } // [] get Item(special_object) on filled HD - hashtable // hd = new HybridDictionary(); hd.Clear(); len = 40; b = new ArrayList[len]; lbl = new Hashtable[len]; for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[lbl[i]]; if (!itm.Equals(b[i])) { Assert.False(true, string.Format("Error, returned wrong special object")); } } }
public virtual bool runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "123_er"; String strInfo = null; Console.Out.Write(strName); Console.Out.Write(": "); Console.Out.Write(strPath + strTest); Console.Out.WriteLine(" runTest started..."); String str1 = "Dill Guv Dill Guv Dill"; String str2 = "Dill"; try { do { ++iCountTestcases; if (str1.IndexOf(str2) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke "; Console.WriteLine(strTest + strInfo); } IntlStrings intl = new IntlStrings(); String myIntlString = intl.GetString(5, true, true); String myIntlString2 = intl.GetString(13, true, true); myIntlString = String.Concat(myIntlString, myIntlString2); if (myIntlString.IndexOf(myIntlString2) != 5) { ++iCountErrors; } str2 = "Dill Guv Dill Guv Dill"; if (str1.IndexOf(str2) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_892dds "; Console.WriteLine(strTest + strInfo); } str2 = "ll"; if (str1.IndexOf(str2) != 2) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_739cp"; Console.WriteLine(strTest + strInfo); } str2 = "Bill"; if (str1.IndexOf(str2) != -1) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_720mr"; Console.WriteLine(strTest + strInfo); } str2 = " "; if (str1.IndexOf(str2) != 4) { ++iCountErrors; strInfo += "FAiL. E_240hg "; strInfo += ", Exception not thrown ==" + (str1.IndexOf(str2)).ToString(); Console.WriteLine(strTest + strInfo); } str2 = ""; if (str1.IndexOf(str2) != 0) { ++iCountErrors; strInfo += "FAiL. E_235jf "; strInfo += ", Index ==" + "< " + (str1.IndexOf(str2)).ToString() + " >"; Console.WriteLine(strTest + strInfo); } try { str2 = null; str1.IndexOf(str2); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_248ko"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (ArgumentException) { } catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_034fl"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } str1 = null; try { str1.IndexOf(str2); ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_015qp "; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } catch (NullReferenceException) {} catch (Exception ex) { ++iCountErrors; strInfo = strTest + " error: "; strInfo = "FAiL. E_104nu"; strInfo += ", Wrong Exception thrown == " + ex.ToString(); Console.WriteLine(strTest + strInfo); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_103! strLoc==" + strLoc + " ,exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringDictionary sd; string [] values = { "", " ", "a", "aa", "tExt", " spAces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; Array arr; ICollection vs; int ind; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; sd = new StringDictionary(); Console.WriteLine("1. get Values for empty dictionary"); iCountTestcases++; if (sd.Count > 0) { sd.Clear(); } if (sd.Values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned Values.Count = {0}", sd.Values.Count); } Console.WriteLine("2. get Values on filled dictionary"); strLoc = "Loc_002oo"; int len = values.Length; iCountTestcases++; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len); } vs = sd.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(string), len); vs.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, values[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0002b_{0}, Values doesn't contain \"{1}\" value. Search result: {2}", i, keys[i], ind); } } Console.WriteLine("3. get Values on dictionary with duplicate values "); strLoc = "Loc_003oo"; iCountTestcases++; sd.Clear(); string intlStr = intl.GetString(MAX_LEN, true, true, true); sd.Add("keykey1", intlStr); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } sd.Add("keykey2", intlStr); if (sd.Count != len + 2) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, len + 2); } iCountTestcases++; vs = sd.Values; if (vs.Count != sd.Count) { iCountErrors++; Console.WriteLine("Err_0003b, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(string), len + 2); vs.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, values[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c_{0}, Values doesn't contain \"{1}\" value", i, keys[i]); } } iCountTestcases++; ind = Array.IndexOf(arr, intlStr); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c, Values doesn't contain {0} value", intlStr); } Console.WriteLine("4. get Values for dictionary with intl strings"); strLoc = "Loc_004oo"; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, len); } vs = sd.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0004b, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(string), len); vs.CopyTo(arr, 0); for (int i = 0; i < arr.Length; i++) { iCountTestcases++; ind = Array.IndexOf(arr, intlValues[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0004c_{0}, Values doesn't contain \"{1}\" value", i, intlValues[i]); } } Console.WriteLine("5. Change dictinary and verify case sensitivity"); strLoc = "Loc_005oo"; iCountTestcases++; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len); } vs = sd.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, returned Values.Count = {0}", vs.Count); } Console.WriteLine(" - remove element from the dictionary"); sd.Remove(keys[0]); if (sd.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0005b, didn't remove element"); } if (vs.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0005c, Values were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(string), sd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, values[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0005d, Values still contains removed value " + ind); } Console.WriteLine(" - add element to the dictionary"); sd.Add(keys[0], "new item"); if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0005e, didn't add element"); } if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0005f, Values were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(string), sd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, "new item"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005g, Values doesn't contain added value "); } Console.WriteLine(" - set to uppercase"); sd[keys[0]] = "UPPERCASE"; if (sd.Count != len) { iCountErrors++; Console.WriteLine("Err_0005h, Count changed after set"); } if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0005j, Values.Count changed after set"); } iCountTestcases++; arr = Array.CreateInstance(typeof(string), sd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, "UPPERCASE"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005k, Values doesn't contain value we just set "); } ind = Array.IndexOf(arr, "uppercase"); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0005m, Values contains lowercase version of value we just set "); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringCollection sc; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. Count on empty collection"); iCountTestcases++; if (sc.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned {0} for empty collection", sc.Count); } Console.WriteLine("2. add simple strings and verify Count"); strLoc = "Loc_002oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002b, count is {0} instead of {1}", sc.Count, values.Length); } Console.WriteLine("3. add intl strings and verify Count"); strLoc = "Loc_003oo"; string [] intlValues = new string [values.Length]; for (int i = 0; i < values.Length; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if (sc.Count != intlValues.Length) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, intlValues.Length); } iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if (sc.Count != intlValues.Length) { iCountErrors++; Console.WriteLine("Err_0003b, count is {0} instead of {1}", sc.Count, intlValues.Length); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 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"; String strValue = String.Empty; try { String str1 = String.Empty, str2 = String.Empty; strLoc = "Loc_498hv"; iCountTestcases++; str1 = String.Concat(String.Empty); str2 = String.Copy(str1); if (!str2.Equals(String.Empty)) { iCountErrors++; printerr("Error_498ch! incorrect string returned for null argument==" + str2); } strLoc = "Loc_498hv.2"; iCountTestcases++; if (str1 != str2) { iCountErrors++; printerr("Error_498ch.2! str1 != str2; str2 == " + str2); } strLoc = "Loc_498hv.3"; str1 = "Hi There"; str2 = String.Copy(str1); iCountTestcases++; if (!str2.Equals("Hi There")) { iCountErrors++; printerr("Error_498ch.3! incorrect string returned for null argument==" + str2); } IntlStrings intl = new IntlStrings(); str1 = intl.GetString(12, false, true); str2 = String.Copy(str1); String str3 = str1; iCountTestcases++; if (!str2.Equals(str3)) { iCountErrors++; printerr("Error_498ch.3! incorrect string returned for null argument==" + str2); } strLoc = "Loc_498hv.4"; iCountTestcases++; if (str1 != str2) { iCountErrors++; printerr("Error_498ch.4! str1 != str2; str2 == " + str2); } strLoc = "Loc_498hv.5"; iCountTestcases++; try { str2 = String.Copy(null); iCountErrors++; printerr("Error_498ch.5! expected argnullexc; instead resturned " + str2); } catch (ArgumentNullException) { } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public virtual bool runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "123_er"; String strInfo = null; Console.Out.Write(strName); Console.Out.Write(": "); Console.Out.Write(strPath + strTest); Console.Out.WriteLine(" runTest started..."); String strTest1 = "WA"; String strTest2 = "PN"; String str1 = null; String str2 = null; try { LABEL_860_GENERAL: do { IntlStrings intl = new IntlStrings(); String strTest3 = intl.GetString(18, true, true); str1 = strTest3; ++iCountTestcases; if (String.CompareOrdinal(str1, strTest3) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke"; Console.WriteLine(strTest + strInfo); } str1 = strTest1; ++iCountTestcases; if (String.CompareOrdinal(str1, strTest1) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_738ke"; Console.WriteLine(strTest + strInfo); } str2 = strTest1; if (String.CompareOrdinal(str2, strTest1) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_390nb"; Console.WriteLine(strTest + strInfo); } str2 = strTest1; if (String.CompareOrdinal(str2, strTest2) <= 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_023Sd"; Console.WriteLine(strTest + strInfo); } str2 = strTest2; if (String.CompareOrdinal(str2, strTest1) >= 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_033pw"; Console.WriteLine(strTest + strInfo); } str1 = strTest2; str2 = null; if (String.CompareOrdinal(str1, str2) <= 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_053jh"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } str1 = null; str2 = strTest1; if (String.CompareOrdinal(str1, str2) >= 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_304_jk"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } str1 = null; str2 = null; if (String.CompareOrdinal(str1, str2) != 0) { ++iCountErrors; strInfo = strTest + " error: "; strInfo += "FAiL. E_982ww"; strInfo += ", Exception not thrown"; Console.WriteLine(strTest + strInfo); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_103! strLoc==" + strLoc + " ,exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; NameValueCollection nvc; string [] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; nvc = new NameValueCollection(); Console.WriteLine("1. GetKey() on empty collection"); iCountTestcases++; Console.WriteLine(" - GetKey(-1)"); try { nvc.GetKey(-1); iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString()); } iCountTestcases++; Console.WriteLine(" - GetKey(0)"); try { nvc.GetKey(0); iCountErrors++; Console.WriteLine("Err_0001c, no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_001d, unexpected exception: {0}", e.ToString()); } Console.WriteLine("2. add simple strings access them via GetKey()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = nvc.Count; int len = values.Length; for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } if (nvc.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(nvc.GetKey(i), keys[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned: \"{1}\", expected \"{2}\"", i, nvc.GetKey(i), keys[i]); } } Console.WriteLine("3. add intl strings GetKey()"); strLoc = "Loc_003oo"; iCountTestcases++; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } iCountTestcases++; nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); } if (nvc.Count != (len)) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(nvc.GetKey(i), intlValues[i + len], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, returned \"{1}\" instead of \"{2}\"", i, nvc.GetKey(i), intlValues[i + len]); } } Console.WriteLine("4. case sensitivity"); strLoc = "Loc_004oo"; string [] intlValuesLower = new string [len * 2]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } nvc.Clear(); for (int i = 0; i < len; i++) { nvc.Add(intlValues[i + len], intlValues[i]); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(nvc.GetKey(i), intlValues[i + len], false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, returned \"{1}\" instead of \"{2}\"", i, nvc.GetKey(i), intlValues[i + len]); } iCountTestcases++; if (!caseInsensitive && String.Compare(nvc.GetKey(i), intlValuesLower[i + len], false) == 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, returned lowercase when added uppercase", i); } } Console.WriteLine("5. multiple items with same key and GetKey()"); strLoc = "Loc_005oo"; iCountTestcases++; nvc.Clear(); len = values.Length; string k = "keykey"; string k1 = "hm1"; string exp = ""; string exp1 = ""; for (int i = 0; i < len; i++) { nvc.Add(k, "Value" + i); nvc.Add(k1, "iTem" + i); if (i < len - 1) { exp += "Value" + i + ","; exp1 += "iTem" + i + ","; } else { exp += "Value" + i; exp1 += "iTem" + i; } } if (nvc.Count != 2) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", nvc.Count, 2); } iCountTestcases++; if (String.Compare(nvc.GetKey(0), k, false) != 0) { iCountErrors++; Console.WriteLine("Err_0005b, returned \"{0}\" instead of \"{1}\"", nvc.GetKey(0), k); } if (String.Compare(nvc.GetKey(1), k1, false) != 0) { iCountErrors++; Console.WriteLine("Err_0005c, returned \"{0}\" instead of \"{1}\"", nvc.GetKey(1), k1); } Console.WriteLine("6. GetKey(-1)"); strLoc = "Loc_006oo"; iCountTestcases++; cnt = nvc.Count; try { nvc.GetKey(-1); iCountErrors++; Console.WriteLine("Err_0006b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("7. GetKey(count)"); strLoc = "Loc_007oo"; iCountTestcases++; if (nvc.Count < 1) { for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } } cnt = nvc.Count; try { nvc.GetKey(cnt); iCountErrors++; Console.WriteLine("Err_007b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_007c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("8. GetKey(count+1)"); strLoc = "Loc_008oo"; iCountTestcases++; if (nvc.Count < 1) { for (int i = 0; i < len; i++) { nvc.Add(keys[i], values[i]); } } cnt = nvc.Count; try { nvc.GetKey(cnt + 1); iCountErrors++; Console.WriteLine("Err_008b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_008c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("9. GetKey(null)"); strLoc = "Loc_09oo"; iCountTestcases++; Object nl = null; try { string res = nvc.GetKey((int)nl); iCountErrors++; Console.WriteLine("Err_0009a: no exception "); } catch (NullReferenceException ex) { Console.WriteLine(" expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009b, unexpected exception: {0}", e.ToString()); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; ListDictionary ld; string [] values = { "", " ", "a", "aA", "text", " SPaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "oNe", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001_oo"; iCountTestcases++; ld = new ListDictionary(); cnt = ld.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001_, count is {0} instead of {1} after default ctor", ld.Count, 0); } Console.WriteLine("1. call Clear() on empty dictionary"); strLoc = "Loc_001oo"; iCountTestcases++; ld.Clear(); cnt = ld.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001a, count is {0} instead of {1} after Clear()", ld.Count, 0); } iCountTestcases++; cnt = ld.Keys.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001b, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = ld.Values.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001c, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("2. add simple strings and Clear()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = ld.Count; for (int i = 0; i < values.Length; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length); } iCountTestcases++; ld.Clear(); cnt = ld.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002b, count is {0} instead of {1} after Clear()", ld.Count, 0); } iCountTestcases++; cnt = ld.Keys.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = ld.Values.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("3. add intl strings and Clear()"); strLoc = "Loc_003oo"; int len = values.Length; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetString(MAX_LEN, true, true, true); } intlValues[i] = val; } cnt = ld.Count; iCountTestcases++; for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } if (ld.Count != (cnt + len)) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, cnt + len); } iCountTestcases++; ld.Clear(); cnt = ld.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003b, count is {0} instead of {1} after Clear()", ld.Count, 0); } iCountTestcases++; cnt = ld.Keys.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = ld.Values.Count; if (cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! 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 void Test01() { IntlStrings intl; StringDictionary sd; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] Remove() from empty dictionary // if (sd.Count > 0) { sd.Clear(); } for (int i = 0; i < keys.Length; i++) { sd.Remove(keys[0]); } // [] Remove() from filled dictionary // int len = values.Length; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(keys[i]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} key", i)); } // verify that indeed element with given key was removed if (sd.ContainsValue(values[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } } // // [] Remove() on dictionary with identical values // sd.Clear(); string intlStr = intl.GetRandomString(MAX_LEN); sd.Add("keykey1", intlStr); // 1st duplicate for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } sd.Add("keykey2", intlStr); // 2nd duplicate if (sd.Count != len + 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len + 2)); } // remove // sd.Remove("keykey2"); if (!sd.ContainsValue(intlStr)) { Assert.False(true, string.Format("Error, removed both duplicates")); } // second string should still be present if (sd.ContainsKey("keykey2")) { Assert.False(true, string.Format("Error, removed not given instance")); } if (!sd.ContainsKey("keykey1")) { Assert.False(true, string.Format("Error, removed wrong instance")); } // // Intl strings // [] Remove() from dictionary filled with Intl strings // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } // // will use first half of array as values and second half as keys // sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // remove for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(intlValues[i + len]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} key", i + len)); } // verify that indeed element with given key was removed if (sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, removed wrong key", i)); } } // // [] Case sensitivity: keys are always lowercased // sd.Clear(); string[] intlValuesUpper = new string[len]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToLowerInvariant(); } // array of uppercase keys for (int i = 0; i < len; i++) { intlValuesUpper[i] = intlValues[i + len].ToUpperInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); // adding lowercase strings } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // remove for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(intlValuesUpper[i]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} lower key", i + len)); } // verify that indeed element with given key was removed if (sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(intlValuesUpper[i])) { Assert.False(true, string.Format("Error, removed wrong key", i)); } } // // [] Invalid parameter // Assert.Throws <ArgumentNullException>(() => { sd.Remove(null); }); }
public Boolean runTest () { Console.Error.WriteLine("String-Co1030Compare_StrStrBool runTest started."); int nErrorBits = 0; String swrString2 = null; String swrString3 = null; String swrString4 = null; swrString2 = "HIJ"; swrString3 = "hij"; if (String.Compare(swrString2, swrString3, true) != 0 && CultureInfo.CurrentCulture.LCID != 0x41F) { nErrorBits = nErrorBits | 0x1; } if (String.Compare(swrString2, swrString3, false) <= 0 && CultureInfo.CurrentCulture.LCID != 0x41F) { nErrorBits = nErrorBits | 0x2; } swrString2 = "efg"; swrString3 = "hij"; if (String.Compare(swrString2, swrString3, true) >= 0) { nErrorBits = nErrorBits | 0x4; } if (String.Compare(swrString2, swrString3, false) >= 0) { nErrorBits = nErrorBits | 0x8; } swrString2 = "hij"; swrString3 = "efg"; if (String.Compare(swrString2, swrString3, true) <= 0) { nErrorBits = nErrorBits | 0x10; } if (String.Compare(swrString2, swrString3, false) <= 0) { nErrorBits = nErrorBits | 0x20; } swrString2 = "Foa"; swrString3 = "fob"; if (String.Compare(swrString2, swrString3, false) == 0) { nErrorBits = nErrorBits | 0x20; } swrString2 = "Blah"; swrString3 = "blab"; if (String.Compare(swrString2, swrString3, true) == 0) { nErrorBits = nErrorBits | 0x40; } if (String.Compare(swrString2, swrString3, false) == 0) { nErrorBits = nErrorBits | 0x80; } swrString2 = "hij"; swrString3 = "hij"; if (String.Compare(swrString2, swrString3, true) != 0) { nErrorBits = nErrorBits | 0x100; } if (String.Compare(swrString2, swrString3, false) != 0) { nErrorBits = nErrorBits | 0x200; } swrString2 = "H"; swrString3 = "q"; swrString4 = "Q"; if (String.Compare(swrString3, swrString2, true) < 0) { nErrorBits = nErrorBits | 0x400; } if (String.Compare(swrString3, swrString4, false) >= 0) { nErrorBits = nErrorBits | 0x800; } if (String.Compare(swrString3, swrString2, true) <= 0) { nErrorBits = nErrorBits | 0x1000; } if (String.Compare(swrString3, swrString4, true) != 0) { nErrorBits = nErrorBits | 0x2000; } long Var = 5; IntlStrings intl = new IntlStrings(Var); swrString2 = intl.GetString(6, true, true); swrString3 = swrString2; if (String.Compare(swrString2, swrString3, true) != 0) { nErrorBits = nErrorBits | 0x4000; } if (String.Compare(swrString2, swrString3, false) != 0) { nErrorBits = nErrorBits | 0x8000; } Console.Error.WriteLine(nErrorBits); if (nErrorBits == 0) { return(true); } else { Console.WriteLine(nErrorBits); return(false); } }