/// <summary> /// Mark a all properties to be ignored when setting of default values /// </summary> /// <exception cref="FluencyException"></exception> protected internal FluentBuilder <T> IgnoreAllProperties() { if (_preBuiltResult != null) { throw new FluencyException("Cannot ignore properties once a pre built result has been given. Property change will have no affect."); } _properties.Clear(); return(this); }
public void InsertRecord(Objects.Users obj) { try { parameters.Clear(); parameters.Add(new SqlParameter("@UserID", SqlDbType.Int, 8), obj.UserID); parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 50), obj.UserName); parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50), obj.Password); parameters.Add(new SqlParameter("@IsAdmin", SqlDbType.Bit, 1), obj.IsAdmin); parameters.Add(new SqlParameter("@IsSuperAdmin", SqlDbType.Bit, 1), obj.IsSuperAdmin); parameters.Add(new SqlParameter("@IsActive", SqlDbType.Bit, 1), obj.IsActive); new Database(connectionstring).ExecuteNonQueryOnly("SP_InsUsers", parameters); } catch (Exception exc) { throw exc; } }
/// <inheritdoc/> public void Dispose() { _WorkAreas.CollectionChanged -= WorkAreas_CollectionChanged; _ProductsBak.Clear(); foreach (var products in _WorkAreas.Select(x => x.Products.ProductsInfo.Products)) { products.CollectionChanged -= Products_CollectionChanged; products.CollectionPropertyChanged -= Products_CollectionPropertyChanged; } }
public void CanClearDictionary() { list.Add("foo", new object()); list.Add("bar", new object()); list.Add("baz", new object()); list.Clear(); Assert.AreEqual(0, list.Count); }
public void CanClearDictionary() { list.Add("foo", new object()); list.Add("bar", new object()); list.Add("baz", new object()); list.Clear(); Assert.Empty(list); }
public void ShouldBeAbleToRemoveAllValues() { ListDictionary <string, int> dict = new ListDictionary <string, int>(); dict.Add("a", 5); dict.Add("b", 8); dict.Clear(); Assert.AreEqual(0, dict.Count); }
public void ResetResponses() { _errors.Clear(); _notices.Clear(); _resultSets.Clear(); _responses.Clear(); _notifications.Clear(); _parameters.Clear(); _backend_key_data = null; _sqlSent = String.Empty; _commandTimeout = 20; }
public void Apply() { ListDictionary list = graph.Model.CompilerOptions; list.Clear(); list.Add("target", "library"); list.Add("checked", overflow.Checked); list.Add("debug", debug.Checked); list.Add("o", opt.Checked); list.Add("unsafe", allowunsafe.Checked); list.Add("w", warnings.SelectedIndex.ToString()); }
internal SmppBindRes Bind() { SmppBindRes res = null; SmppBindReq requestPdu = null; lock (this) { try { if (Connected) { throw new Exception("You must disconnect before connect again", new SocketException(0x186a1)); } TcpConnection.RemoteHost = Settings.RemoteHost; TcpConnection.RemotePort = Settings.RemotePort; TcpConnection.LocalHost = Settings.LocalHost; TcpConnection.LocalPort = Settings.LocalPort; TcpConnection.BufferSize = Settings.SocketBufferSize; ConnectionSuccess = false; TcpConnection.Connect(); } catch (Exception exception) { _LastException = exception; res = new SmppBindRes(new SmppHeader(Settings.ConnectionMode.Value, GetSequenceNumber())); res.Header.CommandStatus = 0x15f95; return(res); } requestPdu = new SmppBindReq(Settings.ConnectionMode.Value, GetSequenceNumber(), Settings.BindParams); var asyncObject = new SmppAsyncObject(); SendReqPdu(requestPdu, ref asyncObject); res = new SmppBindRes(asyncObject.PduRes); if (res.Header.CommandStatus != 0) { TcpConnection.Disconnect(); return(res); } PendingResponse.Clear(); ConnectionSuccess = true; } return(res); }
protected void Button1_Click(object sender, EventArgs e) { ListDictionary insertParameters = new ListDictionary(); TextBox name = FormView1.FindControl("nameBox") as TextBox; TextBox author = FormView1.FindControl("authorBox") as TextBox; DropDownList type = FormView1.FindControl("DropDownMovieList") as DropDownList; //check if data exists already bool exists = false; for (int i = 0; i < GridView1.Rows.Count; i++) { String valueName = GridView1.Rows[i].Cells[1].Text.ToString(); if ((valueName.Equals(name.Text))) { //record exists exists = true; //ShowPopUpMsg("Name already exists in the database. Please check details in 'name' field"); break; } else { exists = false; //record not exists } } //insert if valid if (exists == false) { insertParameters.Add("Name", name.Text); insertParameters.Add("AuthorName", author.Text); insertParameters.Add("Type", type.SelectedItem.Text); insertParameters.Add("DateAdded", DateTime.Now.ToShortDateString()); LinqDataSource1.Insert(insertParameters); GridView1.DataBind(); insertParameters.Clear(); messagePanel.Visible = true; messagePanel.Dispose(); } else if (exists == true) { PanelWarning.Visible = true; PanelWarning.Dispose(); } }
public void Load(string file) { using (StreamReader sr = new StreamReader(file)) { string line; entries.Clear(); lists.Clear(); string group = null; int sepc = 0; while ((line = sr.ReadLine()) != null) { bool skip = false; if (line.Length == 0 || line[0] == '#') { skip = true; } if (!skip && line[0] == '[') { group = line.Substring(1, line.Length - 2); skip = true; } if (!skip && group != "Desktop Entry") { skip = true; } if (!skip) { int i = line.IndexOf('='); if (i != -1) { string key = line.Substring(0, i); string val = line.Substring(i + 1); entries.Add(key, val); continue; } } entries.Add("_ " + sepc, line); sepc++; } } isLoadedFile = true; }
public void Clear() { if (_hashtable != null) { Hashtable cachedHashtable = _hashtable; _hashtable = null; cachedHashtable.Clear(); } if (_list != null) { ListDictionary cachedList = _list; _list = null; cachedList.Clear(); } }
public void Clear() { if (hashtable != null) { Hashtable cachedHashtable = hashtable; hashtable = null; cachedHashtable.Clear(); } if (list != null) { ListDictionary cachedList = list; list = null; cachedList.Clear(); } }
/// <summary> /// Overriden to unhook and dispose all the invokers. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { foreach (KeyValuePair <TInvoker, List <string> > pair in invokers) { List <string> events = pair.Value; for (int i = events.Count - 1; i >= 0; i--) { UnwireInvoker(pair.Key, events[i]); } } invokers.Clear(); } base.Dispose(disposing); }
private void btnApply_Click(object sender, EventArgs e) { // raise event to allow take over the items from local userIdentities and nntpServers // to app.FeedHandler.Identity and app.FeedHandler.NntpServers if (DefinitionsModified != null) { DefinitionsModified(this, EventArgs.Empty); } userIdentities.Clear(); nntpServers.Clear(); listAccounts.Clear(); treeServers.Nodes.Clear(); this.InitializeWidgets(application.Identities, application.CurrentNntpServers); this.btnApply.Enabled = false; }
public void ReadXmlSettings(XmlNode xmlSetting, XmlNamespaceManager xmlNsManager, string xmlPrefix, string readingFromPath) { m_columns.Clear(); XmlNodeList xmlColumnList = xmlSetting.SelectNodes(xmlPrefix + "column", xmlNsManager); foreach (XmlNode xmlColumn in xmlColumnList) { XmlNode xmlName = xmlColumn.Attributes["name"]; if (xmlName == null) { throw new System.ApplicationException("The 'column' element is missing the 'name' attribute."); } int width = XmlConvert.ToInt32(xmlColumn.InnerText); m_columns.Add(xmlName.Value, width); } }
/// <summary> /// 清理所有的资源 /// </summary> internal virtual void DoDispose() { while (dataWaitingQueue.Count > 0) { var loaderData = dataWaitingQueue.Dequeue(); dataPool.Release(loaderData); } for (int i = dataLoadingList.Count - 1; i >= 0; --i) { var loaderData = dataLoadingList[i]; dataLoadingList.RemoveAt(i); dataPool.Release(loaderData); } dataPool.Clear(); operations.Clear(); assetNodeDic.Clear(); State = AssetLoaderState.None; initCallback = null; addressConfig = null; }
/// <summary> /// This function will initialize a .NET data structure with a set of /// integer data that we will access as a linked list type of data /// structure. /// We will store the square of the array index as the data value for /// the element. /// In addition, for test purposes, we will create a string [] which will /// allow us to easily display the values entered into the list. /// In this way, it is easy to verify that are algorithm is working /// correctly and returning the correct value. /// </summary> /// <param name="Size"></param> private void InitList(Int32 Size) { // String entry list ArrayList List = new ArrayList(); string Entry; Int32 Value; // Clear linked list data structure m_List.Clear(); // initialize the list for the number of elements specified. for (Int32 i = 0; i < Size; i++) { Value = i * i; m_List.Add(i, Value); Entry = "Index " + i.ToString() + " Value = " + Value.ToString(); List.Add(Entry); } string [] Str = ( string [] )List.ToArray(typeof(string)); this.textBox1.Lines = Str; this.textBox1.Update(); }
public static void CreateMultipleLogs() { AppEvents appEventLog = new AppEvents("AppLog", "AppLocal"); AppEvents globalEventLog = new AppEvents("AppSystemLog", "AppGlobal"); ListDictionary logList = new ListDictionary(); logList.Add(appEventLog.LogName, appEventLog); logList.Add(globalEventLog.LogName, globalEventLog); ((AppEvents)logList[appEventLog.LogName]).WriteToLog( "App startup security check", EventLogEntryType.Information, CategoryType.AppStartUp, EventIDType.BufferOverflowCondition); ((AppEvents)logList[globalEventLog.LogName]).WriteToLog( "App startup security check", EventLogEntryType.Information, CategoryType.AppStartUp, EventIDType.BufferOverflowCondition); // iterate over all the AppEvents that write a single message foreach (DictionaryEntry log in logList) { ((AppEvents)log.Value).WriteToLog("App startup", EventLogEntryType.FailureAudit, CategoryType.AppStartUp, EventIDType.SecurityFailure); } // delete logList foreach (DictionaryEntry log in logList) { ((AppEvents)log.Value).DeleteLog(); } logList.Clear(); }
// ReSharper disable once UnusedMember.Local private void OnDisable() { foreach (var entry in _cache.Values) { var cache = entry as Stack <GameObject>; if (cache == null) { continue; } while (cache.Count > 0) { var @object = cache.Pop(); if (@object != null) { DestroyImmediate(@object); } } } _cache.Clear(); Debug.Log("GameCache destroyed"); }
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; } }
static void Main(string[] args) { StringDictionary Sd = new StringDictionary(); Sd.Add("1", "Lohitha"); Sd.Add("2", "ASmin"); Sd.Add("3", "Anitha"); Sd.Add("4", "Chamu"); Console.WriteLine("**************Displaying********************"); foreach (DictionaryEntry de in Sd) { Console.WriteLine(" {0} : {1}", de.Key, de.Value); } Console.WriteLine("**********ContainsValue***************"); Console.WriteLine(Sd.ContainsValue("Anitha")); Console.WriteLine("***********ContainKey**************"); Console.WriteLine(Sd.ContainsKey("1")); // DictionaryEntry[] myARr = { new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry() }; // DictionaryEntry[] STrArr = { new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry() }; Dictionary <string, string>[] STrArr = new Dictionary <string, string> [20]; //Sd.CopyTo(STrArr, 1); //for(int i=0;i<STrArr.Length;i++) //{ // Console.WriteLine("{0}:{1}",STrArr[i].Keys,STrArr[i].Values); // } DictionaryEntry[] myArr = { new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry() }; Sd.CopyTo(myArr, 0); Console.WriteLine("*************CopyTo***************"); // Displaying key and value pairs in Array myArr for (int i = 0; i < myArr.Length; i++) { Console.WriteLine(myArr[i].Key + " " + myArr[i].Value); } Console.WriteLine(Sd.Equals(Sd)); Console.WriteLine("*********GEtEnumerator************"); IEnumerator Ie = Sd.GetEnumerator(); DictionaryEntry ds; while (Ie.MoveNext()) { ds = (DictionaryEntry)Ie.Current; Console.WriteLine("{0}:{1}", ds.Key, ds.Value); } HybridDictionary Hd = new HybridDictionary(); Console.WriteLine("HyBRID DIcTIOnARY-----------------------------------------------------------------------------------------------------"); Hd.Add(1, "Amma"); Hd.Add(2, "Nanna"); Hd.Add(3, "Chelli"); foreach (DictionaryEntry de1 in Hd) { Console.WriteLine("{0}:{1}", de1.Key, de1.Value); } Console.WriteLine("ContainsKEyWord"); Console.WriteLine(Hd.Contains(1)); Console.WriteLine("Equals"); Console.WriteLine(Hd.Equals(Sd)); Console.WriteLine("GETs Hash Code"); Console.WriteLine(Hd.GetHashCode()); Console.WriteLine("REturns String the Represent dictionary TOSTRING"); Console.WriteLine(Hd.ToString()); ListDictionary Ld = new ListDictionary(); Ld.Add(1, "one"); Ld.Add(2, "Two"); Ld.Add(3, "Three"); foreach (DictionaryEntry de2 in Ld) { Console.WriteLine("{0}:{1}", de2.Key, de2.Value); } Ld.Remove(2); Console.WriteLine("AFter remove() Method"); foreach (DictionaryEntry de2 in Ld) { Console.WriteLine("{0}:{1}", de2.Key, de2.Value); } Console.WriteLine("Contains"); Console.WriteLine(Ld.Contains(1)); Ld.Clear(); Console.WriteLine("Clear"); foreach (DictionaryEntry de2 in Ld) { Console.WriteLine("{0}:{1}", de2.Key, de2.Value); } }
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(); // [] Remove() on empty dictionary // cnt = ld.Count; Assert.Throws <ArgumentNullException>(() => { ld.Remove(null); }); cnt = ld.Count; ld.Remove("some_string"); if (ld.Count != cnt) { Assert.False(true, string.Format("Error, changed dictionary after Remove(some_string)")); } cnt = ld.Count; ld.Remove(new Hashtable()); if (ld.Count != cnt) { Assert.False(true, string.Format("Error, changed dictionary after Remove(some_string)")); } // [] add simple strings and Remove() // cnt = ld.Count; int len = values.Length; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, values.Length)); } // for (int i = 0; i < len; i++) { cnt = ld.Count; ld.Remove(keys[i]); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } if (ld.Contains(keys[i])) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } // // Intl strings // [] Add Intl strings and Remove() // 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; } } cnt = ld.Count; for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } if (ld.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = ld.Count; ld.Remove(intlValues[i + len]); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } if (ld.Contains(intlValues[i + len])) { 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].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++) { ld.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key cnt = ld.Count; ld.Remove(intlValues[i + len]); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, returned: failed to remove item", i)); } if (ld.Contains(intlValues[i + len])) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } ld.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings } // LD is case-sensitive by default for (int i = 0; i < len; i++) { // lowercase key cnt = ld.Count; ld.Remove(intlValuesLower[i + len]); if (!caseInsensitive && ld.Count != cnt) { Assert.False(true, string.Format("Error, failed: removed item using lowercase key", i)); } } // // [] Remove() on LD with case-insensitive comparer // ld = new ListDictionary(new InsensitiveComparer()); 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) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, len)); } for (int i = 0; i < len; i++) { cnt = ld.Count; ld.Remove(kk.ToUpper() + i); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, failed to remove item", i)); } if (ld.Contains(kk + i)) { Assert.False(true, string.Format("Error, removed wrong item", i)); } } // // [] Remove(null) // ld = new ListDictionary(); cnt = ld.Count; if (ld.Count < len) { ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } } Assert.Throws <ArgumentNullException>(() => { ld.Remove(null); }); ld = new ListDictionary(); ld.Clear(); ArrayList b = new ArrayList(); ArrayList b1 = new ArrayList(); Hashtable lbl = new Hashtable(); Hashtable lbl1 = new Hashtable(); ld.Add(lbl, b); ld.Add(lbl1, b1); if (ld.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", ld.Count, 2)); } cnt = ld.Count; ld.Remove(lbl); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, failed to remove special object")); } if (ld.Contains(lbl)) { Assert.False(true, string.Format("Error, removed wrong special object")); } }
public static void ClearTest(ListDictionary ld, KeyValuePair<string, string>[] data) { Assert.Equal(data.Length, ld.Count); ld.Clear(); Assert.Equal(0, ld.Count); ld.Add("key", "value"); Assert.Equal(1, ld.Count); ld.Clear(); Assert.Equal(0, ld.Count); }
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. Contains() on empty dictionary"); iCountTestcases++; Console.WriteLine(" - Contains(null)"); try { ld.Contains(null); 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()); } Console.WriteLine(" - Contains(some_object)"); if ( ld.Contains("some_string") ) { iCountErrors++; Console.WriteLine("Err_0001c, empty dictionary contains some_object"); } Console.WriteLine("2. add simple strings and check Contains()"); 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 != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! ld.Contains(keys[i]) ) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, doesn't contain \"{1}\"", i, keys[i]); } } Console.WriteLine("3. add intl strings check Contains()"); 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++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i+len], intlValues[i]); } if ( ld.Count != (len) ) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, 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 \"{1}\"", 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(); } ld.Clear(); 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}a, doesn't contain added uppercase \"{1}\"", i, intlValues[i+len]); } iCountTestcases++; if ( !caseInsensitive && ld.Contains(intlValuesLower[i+len]) ) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, contains lowercase \"{1}\" - should not", i, intlValuesLower[i+len]); } } Console.WriteLine("5. similar_but_different_in_casing keys and Contains()"); strLoc = "Loc_005oo"; iCountTestcases++; ld.Clear(); string [] ks = {"Key", "kEy", "keY"}; len = ks.Length; for (int i = 0; i < len; i++) { ld.Add(ks[i], "Value"+i); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } iCountTestcases++; if ( ld.Contains("Value0") ) { iCountErrors++; Console.WriteLine("Err_0005b, returned true when should not"); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( !ld.Contains(ks[i]) ) { iCountErrors++; Console.WriteLine("Err_0005c_{0}, returned false when true expected", i); } } Console.WriteLine("6. Contains(null) for filled dictionary"); strLoc = "Loc_006oo"; iCountTestcases++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } try { ld.Contains(null); 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. Contains() for case-insensitive comparer"); ld = new ListDictionary(new Co8686_InsensitiveComparer()); strLoc = "Loc_007oo"; iCountTestcases++; ld.Clear(); len = ks.Length; ld.Add(ks[0], "Value0"); for (int i = 1; i < len; i++) { try { ld.Add(ks[i], "Value"+i); iCountErrors++; Console.WriteLine("Err_0007a_{0}, no exception", i); } catch (ArgumentException e) { Console.WriteLine("_{0}, Expected exception: {1}", i, e.Message); } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_0007b_{0}, unexpected exception: {1}", i, ex.ToString()); } } if (ld.Count != 1) { iCountErrors++; Console.WriteLine("Err_0007c, count is {0} instead of {1}", ld.Count, 1); } iCountTestcases++; if ( ld.Contains("Value0") ) { iCountErrors++; Console.WriteLine("Err_0007d, returned true when should not"); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( !ld.Contains(ks[i]) ) { iCountErrors++; Console.WriteLine("Err_0007e_{0}, returned false when true expected", i); } } iCountTestcases++; if ( !ld.Contains("KEY") ) { iCountErrors++; Console.WriteLine("Err_0007f, returned false non-existing-cased key"); } Console.WriteLine("10. Contains() and SpecialStructs_not_overriding_Equals"); ld = new ListDictionary(); strLoc = "Loc_010oo"; iCountTestcases++; Co8686_SpecialStruct s = new Co8686_SpecialStruct(); s.Num = 1; s.Wrd = "one"; Co8686_SpecialStruct s1 = new Co8686_SpecialStruct(); s.Num = 1; s.Wrd = "one"; ld.Add(s, "first"); ld.Add(s1, "second"); if (ld.Count != 2) { iCountErrors++; Console.WriteLine("Err_0010a, count is {0} instead of {1}", ld.Count, 2); } iCountTestcases++; if ( !ld.Contains(s) ) { iCountErrors++; Console.WriteLine("Err_0010b, returned false when true expected"); } iCountTestcases++; if ( !ld.Contains(s1) ) { iCountErrors++; Console.WriteLine("Err_0010c, returned false when true expected"); } } 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; 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 { 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 and check Count"); 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 get Count"); 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); } } 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; String strLoc = "Loc_000oo"; ListDictionary ld; try { Console.WriteLine("--- default ctor ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. compare to null"); iCountTestcases++; if (ld == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (ld.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", ld.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (ld["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; string temp = ld.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("ListDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"ListDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = ld.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("ListDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"ListDictionary\""); } Console.WriteLine("6. compare returned Type of two dictionary"); iCountTestcases++; string temp1 = (new ListDictionary()).GetType().ToString().Trim(); if (String.Compare(temp, temp1) != 0) { iCountErrors++; Console.WriteLine("Err_0006: returned types of two collections differ"); } Console.WriteLine("7. check Keys collection"); iCountTestcases++; System.Collections.ICollection keys = ld.Keys; if ( keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007: Keys contains {0} keys after default ctor", keys.Count); } Console.WriteLine("8. check Values collection"); iCountTestcases++; System.Collections.ICollection values = ld.Values; if ( values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0008: Values contains {0} items after default ctor", values.Count); } Console.WriteLine("9. Add(name, value)"); iCountTestcases++; ld.Add("Name", "Value"); if (ld.Count != 1) { iCountErrors++; Console.WriteLine("Err_0009a: Count returned {0} instead of 1", ld.Count); } if (String.Compare(ld["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b: Item() returned unexpected value"); } Console.WriteLine("10. Clear()"); iCountTestcases++; ld.Clear(); if (ld.Count != 0) { iCountErrors++; Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", ld.Count); } if (ld["Name"] != null) { iCountErrors++; Console.WriteLine("Err_00010b: Item() returned non-null value after Clear()"); } } 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 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" }; Array destination; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. Copy empty dictionary into empty array"); iCountTestcases++; destination = Array.CreateInstance(typeof(Object), 0); Console.WriteLine(" destination Length = " + destination.Length); Console.WriteLine(" - CopyTo(arr, -1)"); try { ld.CopyTo(destination, -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(" - CopyTo(arr, 0)"); try { ld.CopyTo(destination, 0); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString()); } iCountTestcases++; Console.WriteLine(" - CopyTo(arr, 1)"); try { ld.CopyTo(destination, 1); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_001d, unexpected exception: {0}", e.ToString()); } Console.WriteLine("2. Copy empty dictionary into non-empty array"); iCountTestcases++; destination = Array.CreateInstance(typeof(Object), values.Length); for (int i = 0; i < values.Length; i++) { destination.SetValue(values[i], i); } ld.CopyTo(destination, 0); if( destination.Length != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, altered array after copying empty dictionary"); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (String.Compare(destination.GetValue(i).ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty dictionary", i); } } } Console.WriteLine("3. add simple strings and CopyTo(Array, 0)"); strLoc = "Loc_003oo"; iCountTestcases++; cnt = ld.Count; int len = values.Length; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, values.Length); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if ( String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), ld[keys[i]]); } iCountTestcases++; if ( String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), keys[i]); } } Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length); ld.Clear(); strLoc = "Loc_004oo"; iCountTestcases++; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, values.Length); } destination = Array.CreateInstance(typeof(Object), len*2); ld.CopyTo(destination, len); for (int i = 0; i < len; i++) { iCountTestcases++; if ( String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Value.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Value, ld[keys[i]]); } iCountTestcases++; if ( String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i+len)).Key.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Key, keys[i]); } } Console.WriteLine("5. add intl strings and CopyTo(Array, 0)"); strLoc = "Loc_005oo"; 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++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i+len], intlValues[i]); } if ( ld.Count != (len) ) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if ( String.Compare(ld[intlValues[i+len]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, ld[intlValues[i+len]]); } iCountTestcases++; if ( String.Compare(intlValues[i+len], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, intlValues[i+len]); } } Console.WriteLine("6. add intl strings and CopyTo(Array, {0})", len); strLoc = "Loc_006oo"; destination = Array.CreateInstance(typeof(Object), len*2); ld.CopyTo(destination, len); for (int i = 0; i < len; i++) { iCountTestcases++; if ( String.Compare(ld[intlValues[i+len]].ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Value.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Value, ld[intlValues[i+len]]); } iCountTestcases++; if ( String.Compare(intlValues[i+len], ((DictionaryEntry)destination.GetValue(i+len)).Key.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Key, intlValues[i+len]); } } Console.WriteLine("7. case sensitivity"); strLoc = "Loc_007oo"; 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(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i+len], intlValues[i]); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if ( String.Compare(ld[intlValues[i+len]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, ld[intlValues[i+len]]); } iCountTestcases++; if ( !caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) > -1 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, copied lowercase string"); } iCountTestcases++; if ( String.Compare(intlValues[i+len], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, intlValues[i+len]); } iCountTestcases++; if ( !caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) > -1 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}d, copied lowercase key"); } } Console.WriteLine("8. CopyTo(null, int)"); strLoc = "Loc_008oo"; iCountTestcases++; destination = null; try { ld.CopyTo(destination, 0); iCountErrors++; Console.WriteLine("Err_0008a: no exception "); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0008b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("9. CopyTo(Array, -1)"); strLoc = "Loc_009oo"; iCountTestcases++; cnt = ld.Count; destination = Array.CreateInstance(typeof(Object), 2); try { ld.CopyTo(destination, -1); iCountErrors++; Console.WriteLine("Err_0009b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("10. CopyTo(Array, upperBound+1)"); strLoc = "Loc_0010oo"; iCountTestcases++; if (ld.Count < 1) { ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } } destination = Array.CreateInstance(typeof(Object), len); try { ld.CopyTo(destination, len); iCountErrors++; Console.WriteLine("Err_0010b: no exception "); } catch (IndexOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0010c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("11. CopyTo(Array, upperBound+2)"); strLoc = "Loc_010oo"; iCountTestcases++; try { ld.CopyTo(destination, len+1); iCountErrors++; Console.WriteLine("Err_0011b: no exception "); } catch (IndexOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0011c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("12. CopyTo(Array, not_enough_space)"); strLoc = "Loc_012oo"; iCountTestcases++; try { ld.CopyTo(destination, len / 2); iCountErrors++; Console.WriteLine("Err_0012a: no exception "); } catch (IndexOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0012b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("13. CopyTo(multidim_Array, 0)"); strLoc = "Loc_013oo"; iCountTestcases++; Array dest = Array.CreateInstance(typeof(string), len, len); try { ld.CopyTo(dest, 0); iCountErrors++; Console.WriteLine("Err_0013a: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0013b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("15. copy empty LD: CopyTo(Array, upperBound+1)"); strLoc = "Loc_0015oo"; iCountTestcases++; ld.Clear(); destination = Array.CreateInstance(typeof(Object), len); try { ld.CopyTo(destination, len); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0015a, 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; } }
static void Main(string[] args) { Hashtable hashTable = new Hashtable(); ListDictionary listDicti = new ListDictionary(); HybridDictionary hybDicti = new HybridDictionary(); Stopwatch stopWatchHashTable = new Stopwatch(); Stopwatch stopWatchListDicti = new Stopwatch(); Stopwatch stopWatchHybDicti = new Stopwatch(); int cnt = 1000, hashCnt = 0, listCnt = 0, hybCnt = 0; for (int k = 0; k < 999; k++) { stopWatchHashTable.Start(); for (int i = 0; i < cnt; i++) { hashTable.Add(i, "OOP/.NET"); } hashTable.Clear(); stopWatchHashTable.Stop(); TimeSpan tsHashTable = stopWatchHashTable.Elapsed; hashCnt += tsHashTable.Milliseconds; } Console.WriteLine("RunTime HashTable " + hashCnt / 1000); for (int k = 0; k < 999; k++) { stopWatchListDicti.Start(); for (int i = 0; i < cnt; i++) { listDicti.Add(i, "OOP/.NET"); } listDicti.Clear(); stopWatchListDicti.Stop(); TimeSpan tsListDicti = stopWatchListDicti.Elapsed; listCnt += tsListDicti.Milliseconds; } Console.WriteLine("RunTime ListDicti " + listCnt / 1000); for (int k = 0; k < 999; k++) { stopWatchHybDicti.Start(); for (int i = 0; i < cnt; i++) { hybDicti.Add(i, "OOP/.NET"); } hybDicti.Clear(); stopWatchHybDicti.Stop(); TimeSpan tsHybDicti = stopWatchHybDicti.Elapsed; hybCnt += tsHybDicti.Milliseconds; } Console.WriteLine("RunTime HybDicti " + hybCnt / 1000); Console.ReadKey(); }
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; Object itm; 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. Item() on empty dictionary"); iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - Item(null)"); try { itm = ld[null]; 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)"); itm = ld["some_string"]; if (itm != null) { iCountErrors++; Console.WriteLine("Err_0001c, returned non=null"); } Console.WriteLine("2. add simple strings, access 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 != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length); } 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++; if (String.Compare(ld[keys[i]].ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, returned wrong value", i); } } Console.WriteLine("3. add intl strings and access via Item()"); 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++; 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++; if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, returned wrong 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 access 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); } iCountTestcases++; if (String.Compare(ld[intlValues[i + len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}c, returned wrong value", i); } } ld.Clear(); Console.WriteLine(" - add uppercase but access 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++; if (!caseInsensitive && ld[intlValuesLower[i + len]] != null) { iCountErrors++; Console.WriteLine("Err_0004_{0}d, failed: returned non-null for lowercase key", i); } } Console.WriteLine("5. access Item() on LD with insensitive comparer"); ld = new ListDictionary(new Co8694_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 { if (String.Compare(ld[kk.ToUpper() + i].ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0005b_{0}, returned wrong value", i); } } } Console.WriteLine("6. 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 { itm = ld[null]; 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()); } } 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" }; Array arr; ICollection vs; int ind; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. get Values for empty dictionary"); iCountTestcases++; if (ld.Count > 0) { ld.Clear(); } if (ld.Values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned Values.Count = {0}", ld.Values.Count); } Console.WriteLine("2. get Values on filled dictionary"); strLoc = "Loc_002oo"; int len = values.Length; iCountTestcases++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, len); } vs = ld.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(Object), 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, values[i], ind); } } Console.WriteLine("3. get Values on dictionary with different_in_casing_only keys "); strLoc = "Loc_003oo"; iCountTestcases++; ld.Clear(); string intlStr = intl.GetString(MAX_LEN, true, true, true); ld.Add("keykey", intlStr); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } ld.Add("keyKey", intlStr); if (ld.Count != len + 2) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, len + 2); } iCountTestcases++; vs = ld.Values; if (vs.Count != ld.Count) { iCountErrors++; Console.WriteLine("Err_0003b, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(Object), 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, values[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; } ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, len); } vs = ld.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0004b, returned Values.Count = {0}", vs.Count); } arr = Array.CreateInstance(typeof(Object), 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"); strLoc = "Loc_005oo"; iCountTestcases++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } vs = ld.Values; if (vs.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, returned Values.Count = {0}", vs.Count); } Console.WriteLine(" - remove element from the dictionary"); ld.Remove(keys[0]); if (ld.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(Object), ld.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"); ld.Add(keys[0], "new item"); if (ld.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(Object), ld.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 "); } } 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; String strLoc = "Loc_000oo"; ListDictionary ld; int cnt; 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" }; try { Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. IsFixedSize on empty dictionary"); iCountTestcases++; if (ld.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_0001, returned true for empty dictionary"); } Console.WriteLine("2. IsFixedSize for filled dictionary"); strLoc = "Loc_002oo"; iCountTestcases++; ld.Clear(); cnt = values.Length; for (int i = 0; i < cnt; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, cnt); } iCountTestcases++; if (ld.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_0002b, returned true for filled dictionary"); } } 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 Clear() { properties.Clear(); }
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" }; Array arr; ICollection ks; int ind; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. get Keys for empty dictionary"); iCountTestcases++; if (ld.Count > 0) ld.Clear(); if (ld.Keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned Keys.Count = {0}", ld.Keys.Count); } Console.WriteLine("2. get Keys on filled dictionary"); strLoc = "Loc_002oo"; int len = values.Length; iCountTestcases++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, len); } ks = ld.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keys[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0002b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keys[i], ind); } } Console.WriteLine("3. get Keys on dictionary with different_in_casing_only values "); strLoc = "Loc_003oo"; iCountTestcases++; ld.Clear(); string intlStr = intl.GetString(MAX_LEN, true, true, true); ld.Add("keykey", intlStr); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } ld.Add("keyKey", intlStr); if (ld.Count != len+2) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, len+2); } iCountTestcases++; ks = ld.Keys; if (ks.Count != ld.Count) { iCountErrors++; Console.WriteLine("Err_0003b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len+2); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keys[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c_{0}, Keys doesn't contain \"{1}\" key", i, keys[i]); } } iCountTestcases++; ind = Array.IndexOf(arr, "keykey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys doesn't contain {0} key", "keykey"); } iCountTestcases++; ind = Array.IndexOf(arr, "keyKey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys doesn't contain \"{0}\" key", "keyKey"); } Console.WriteLine("4. get Keys 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; } ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i+len], intlValues[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, len); } ks = ld.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0004b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < arr.Length; i++) { iCountTestcases++; ind = Array.IndexOf(arr, intlValues[i+len]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0004c_{0}, Keys doesn't contain \"{1}\" key", i, intlValues[i+len]); } } Console.WriteLine("5. Change dictinary"); strLoc = "Loc_005oo"; iCountTestcases++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } ks = ld.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, returned Keys.Count = {0}", ks.Count); } Console.WriteLine(" - remove element from the dictionary"); ld.Remove(keys[0]); if (ld.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0005b, didn't remove element"); } if (ks.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0005c, Keys were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), ld.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keys[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0005d, Keys still contains removed key " + ind); } Console.WriteLine(" - add element to the dictionary"); ld.Add(keys[0], "new item"); if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0005e, didn't add element"); } if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0005f, Keys were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), ld.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keys[0]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005g, Keys doesn't contain added 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"; 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" }; Array destination; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; ld = new ListDictionary(); Console.WriteLine("1. Copy empty dictionary into empty array"); iCountTestcases++; destination = Array.CreateInstance(typeof(Object), 0); Console.WriteLine(" destination Length = " + destination.Length); Console.WriteLine(" - CopyTo(arr, -1)"); try { ld.CopyTo(destination, -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(" - CopyTo(arr, 0)"); try { ld.CopyTo(destination, 0); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString()); } iCountTestcases++; Console.WriteLine(" - CopyTo(arr, 1)"); try { ld.CopyTo(destination, 1); } 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. Copy empty dictionary into non-empty array"); iCountTestcases++; destination = Array.CreateInstance(typeof(Object), values.Length); for (int i = 0; i < values.Length; i++) { destination.SetValue(values[i], i); } ld.CopyTo(destination, 0); if (destination.Length != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, altered array after copying empty dictionary"); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (String.Compare(destination.GetValue(i).ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty dictionary", i); } } } Console.WriteLine("3. add simple strings and CopyTo(Array, 0)"); strLoc = "Loc_003oo"; iCountTestcases++; cnt = ld.Count; int len = values.Length; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, values.Length); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), ld[keys[i]]); } iCountTestcases++; if (String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), keys[i]); } } Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length); ld.Clear(); strLoc = "Loc_004oo"; iCountTestcases++; for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } if (ld.Count != len) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, values.Length); } destination = Array.CreateInstance(typeof(Object), len * 2); ld.CopyTo(destination, len); for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, ld[keys[i]]); } iCountTestcases++; if (String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, keys[i]); } } Console.WriteLine("5. add intl strings and CopyTo(Array, 0)"); strLoc = "Loc_005oo"; 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++; ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } if (ld.Count != (len)) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", ld.Count, len); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(ld[intlValues[i + len]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, ld[intlValues[i + len]]); } iCountTestcases++; if (String.Compare(intlValues[i + len], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, intlValues[i + len]); } } Console.WriteLine("6. add intl strings and CopyTo(Array, {0})", len); strLoc = "Loc_006oo"; destination = Array.CreateInstance(typeof(Object), len * 2); ld.CopyTo(destination, len); for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(ld[intlValues[i + len]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, ld[intlValues[i + len]]); } iCountTestcases++; if (String.Compare(intlValues[i + len], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, intlValues[i + len]); } } Console.WriteLine("7. case sensitivity"); strLoc = "Loc_007oo"; 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(); for (int i = 0; i < len; i++) { ld.Add(intlValues[i + len], intlValues[i]); } destination = Array.CreateInstance(typeof(Object), len); ld.CopyTo(destination, 0); for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(ld[intlValues[i + len]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, ld[intlValues[i + len]]); } iCountTestcases++; if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) > -1) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, copied lowercase string"); } iCountTestcases++; if (String.Compare(intlValues[i + len], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, intlValues[i + len]); } iCountTestcases++; if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) > -1) { iCountErrors++; Console.WriteLine("Err_0006_{0}d, copied lowercase key"); } } Console.WriteLine("8. CopyTo(null, int)"); strLoc = "Loc_008oo"; iCountTestcases++; destination = null; try { ld.CopyTo(destination, 0); iCountErrors++; Console.WriteLine("Err_0008a: no exception "); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0008b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("9. CopyTo(Array, -1)"); strLoc = "Loc_009oo"; iCountTestcases++; cnt = ld.Count; destination = Array.CreateInstance(typeof(Object), 2); try { ld.CopyTo(destination, -1); iCountErrors++; Console.WriteLine("Err_0009b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("10. CopyTo(Array, upperBound+1)"); strLoc = "Loc_0010oo"; iCountTestcases++; if (ld.Count < 1) { ld.Clear(); for (int i = 0; i < len; i++) { ld.Add(keys[i], values[i]); } } destination = Array.CreateInstance(typeof(Object), len); try { ld.CopyTo(destination, len); iCountErrors++; Console.WriteLine("Err_0010b: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0010c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("11. CopyTo(Array, upperBound+2)"); strLoc = "Loc_010oo"; iCountTestcases++; try { ld.CopyTo(destination, len + 1); iCountErrors++; Console.WriteLine("Err_0011b: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0011c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("12. CopyTo(Array, not_enough_space)"); strLoc = "Loc_012oo"; iCountTestcases++; try { ld.CopyTo(destination, len / 2); iCountErrors++; Console.WriteLine("Err_0012a: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0012b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("13. CopyTo(multidim_Array, 0)"); strLoc = "Loc_013oo"; iCountTestcases++; Array dest = Array.CreateInstance(typeof(string), len, len); try { ld.CopyTo(dest, 0); iCountErrors++; Console.WriteLine("Err_0013a: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0013b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("15. copy empty LD: CopyTo(Array, upperBound+1)"); strLoc = "Loc_0015oo"; iCountTestcases++; ld.Clear(); destination = Array.CreateInstance(typeof(Object), len); try { ld.CopyTo(destination, len); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0015a, 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 Process(ModuleConstraintsModel inputModel, string id) { Reset(); model = inputModel; m_socketsOffsets = model.socketsOffsets; m_socketsMirrors = model.socketsMirrors; m_socketCount = m_socketsOffsets.Length; #region group processing ModuleSampler[] samplerComponent = GameObject.FindObjectsOfType <ModuleSampler>(); ModuleSampler sampler; ByteTrio itemCoords, socketCoord; GameObject samplerGo, itemGo, modulePrefab; Transform samplerTr, itemTr; int3 samplerSize; ModuleConstraintsBuilder moduleBuilder; ModuleInfos moduleInfos; int itemCount; for (int samplerIndex = 0, count = samplerComponent.Length; samplerIndex < count; samplerIndex++) { sampler = samplerComponent[samplerIndex]; samplerGo = sampler.gameObject; if (!samplerGo.activeSelf || !sampler.enabled || sampler.manifestID != id) { continue; } samplerSize = sampler.gridSize; samplerTr = samplerGo.transform; m_moduleBuilders.Clear(); m_moduleBuildersMap.Clear(); m_items.Clear(); m_items.Capacity = samplerTr.childCount; m_itemsMap.Clear(); itemCount = samplerTr.childCount; // Go through all children and cache necessary data // such as each GameObject related prefab, coordinates in grid etc. for (int i = 0; i < itemCount; i++) { itemTr = samplerTr.GetChild(i); itemGo = itemTr.gameObject; moduleInfos = itemGo.GetComponent <ModuleInfos>(); modulePrefab = PrefabUtility.GetCorrespondingObjectFromSource <GameObject>(itemGo); if (modulePrefab == null) { continue; } if (!sampler.brain.TryGetCoordOf(itemTr.position, out itemCoords)) { Debug.LogWarning(itemGo.name + " is outside its parent grid.", itemGo); continue; } if (!m_builderMap.TryGetValue(modulePrefab, out moduleBuilder)) { moduleBuilder = Pool.Rent <ModuleConstraintsBuilder>(); moduleBuilder.m_index = uid++; moduleBuilder.m_prefab = modulePrefab; m_builderMap[modulePrefab] = moduleBuilder; m_builders.Add(moduleBuilder); } if (moduleInfos != null) { moduleBuilder.m_weight = moduleInfos.weight; } m_items.Add(itemGo); m_itemsMap[itemGo] = modulePrefab; m_moduleBuildersMap[itemGo] = itemCoords; m_moduleBuilders.Add(itemCoords, itemGo); } itemCount = m_items.Count; for (int i = 0; i < itemCount; i++) { itemGo = m_items[i]; itemCoords = m_moduleBuildersMap[itemGo]; moduleBuilder = m_builderMap[m_itemsMap[itemGo]]; for (int s = 0; s < m_socketCount; s++) { socketCoord = itemCoords + m_socketsOffsets[s]; if (socketCoord.x < 0 || socketCoord.x >= samplerSize.x || socketCoord.y < 0 || socketCoord.y >= samplerSize.y || socketCoord.z < 0 || socketCoord.z >= samplerSize.z) { // If coordinate falls outside, fill neighbor slot with null reference if (!sampler.ignoreNullSockets) { moduleBuilder.Add(s, null); } } else if (m_moduleBuilders.TryGet(socketCoord, out List <GameObject> list)) { // Feed module builder with current socket's contents for (int b = 0, listCount = list.Count; b < listCount; b++) { moduleBuilder.Add(s, m_builderMap[m_itemsMap[list[b]]]); } } } } } #endregion WriteData(id); #region Clean up for (int i = 0, count = m_builders.Count; i < count; i++) { m_builders[i].Release(); } m_builders.Clear(); m_builderMap.Clear(); #endregion }
static void Initialize() { g_cache.Clear(); g_pendingRequests.Clear(); }
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; Object itm; 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. Item() on empty dictionary"); iCountTestcases++; cnt = ld.Count; Console.WriteLine(" - Item(null)"); try { itm = ld[null]; 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)"); itm = ld["some_string"]; if (itm != null) { iCountErrors++; Console.WriteLine("Err_0001c, returned non=null"); } Console.WriteLine("2. add simple strings, access 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 != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length); } 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++; if (String.Compare(ld[keys[i]].ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, returned wrong value", i); } } Console.WriteLine("3. add intl strings and access via Item()"); 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++; 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++; if (String.Compare(ld[intlValues[i+len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}c, returned wrong 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 access 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); } iCountTestcases++; if (String.Compare(ld[intlValues[i+len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}c, returned wrong value", i); } } ld.Clear(); Console.WriteLine(" - add uppercase but access 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++; if ( !caseInsensitive && ld[intlValuesLower[i+len]] != null ) { iCountErrors++; Console.WriteLine("Err_0004_{0}d, failed: returned non-null for lowercase key", i); } } Console.WriteLine("5. access Item() on LD with insensitive comparer"); ld = new ListDictionary(new Co8694_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 { if (String.Compare(ld[kk.ToUpper() + i].ToString(), values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0005b_{0}, returned wrong value", i); } } } Console.WriteLine("6. 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 { itm = ld[null]; 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()); } } 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; } }