private void бинарныйToolStripMenuItem_Click(object sender, EventArgs e)
        {
            arrayOfArray.Sort();

            DataGridViewOutput();
            NewArray     arrayForm = new NewArray();
            DialogResult result    = arrayForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }
            int[] intArray = StringToArray(arrayForm.textBox1.Text);
            int   index    = arrayOfArray.BinarySearch(new Array(intArray));

            if (index == -1)
            {
                MessageBox.Show(ERR_FIND, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                dataGridView1.ClearSelection();
                dataGridView1.Rows[index].Selected = true;
            }
        }
Example #2
0
        void IIdentifierCreationService.EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities)
        {
            if (parentActivity == null)
            {
                throw new ArgumentNullException("parentActivity");
            }
            if (childActivities == null)
            {
                throw new ArgumentNullException("childActivities");
            }

            ArrayList allActivities = new ArrayList();

            Queue activities = new Queue(childActivities);

            while (activities.Count > 0)
            {
                Activity activity = (Activity)activities.Dequeue();
                if (activity is CompositeActivity)
                {
                    foreach (Activity child in ((CompositeActivity)activity).Activities)
                    {
                        activities.Enqueue(child);
                    }
                }

                //If we are moving activities, we need not regenerate their identifiers
                if (((IComponent)activity).Site != null)
                {
                    continue;
                }

                allActivities.Add(activity);
            }

            // get the root activity
            CompositeActivity rootActivity = GetRootActivity(parentActivity) as CompositeActivity;
            ArrayList         identifiers  = new ArrayList(); // all the identifiers in the workflow

            identifiers.AddRange(GetIdentifiersInCompositeActivity(rootActivity));

            foreach (Activity activity in allActivities)
            {
                string finalIdentifier = activity.Name;

                // now loop until we find a identifier that hasn't been used.
                string baseIdentifier = GetBaseIdentifier(activity);
                int    index          = 0;

                identifiers.Sort();
                while (finalIdentifier == null || finalIdentifier.Length == 0 || identifiers.BinarySearch(finalIdentifier.ToLower(CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) >= 0)
                {
                    finalIdentifier = string.Format("{0}{1}", baseIdentifier, ++index);
                }

                // add new identifier to collection
                identifiers.Add(finalIdentifier);
                activity.Name = finalIdentifier;
            }
        }
Example #3
0
        private object EvaluateMV(Report rpt, Row row)
        {
            ArrayList ar = p.GetRuntimeValues(rpt);

            object va = this._arg == null ? null : _arg.Evaluate(rpt, row);

            switch (_type)
            {
            case ReportParameterMethodEnum.Value:
                return(ar);

            case ReportParameterMethodEnum.Contains:
                return(ar.Contains(va));

            case ReportParameterMethodEnum.BinarySearch:
                return(ar.BinarySearch(va));

            case ReportParameterMethodEnum.Count:
                return(ar.Count);

            case ReportParameterMethodEnum.IndexOf:
                return(ar.IndexOf(va));

            case ReportParameterMethodEnum.LastIndexOf:
                return(ar.LastIndexOf(va));

            case ReportParameterMethodEnum.Index:
                int i = Convert.ToInt32(va);
                return(ar[i]);

            default:
                throw new Exception("Internal error: unknown Report Parameter method");
            }
        }
Example #4
0
        protected int CalculoDimensionUbiNiv2(string codUbi, ref ArrayList elemFils)
        {
            //Traemos todas las ubicaciones que depende de codUbi
            DataSet ds = new DataSet();

            DBFunctions.Request(ds, IncludeSchema.NO, "SELECT pubi_ubicespacial, cast(RTRIM(SUBSTR(pubi_ubicespacial,LOCATE('-',pubi_ubicespacial,1)+1,LENGTH(pubi_ubicespacial)-LOCATE('-',pubi_ubicespacial,1)+1)) as integer) as numero_columna FROM pubicacionitem WHERE pubi_codpad=" + codUbi + " ORDER BY pubi_ubicespacial");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                //Dividimos la ubicacionespacial en sus dos partes fila-columna
                string[] divUbicEsp = ds.Tables[0].Rows[i][0].ToString().Split('-');
                int      indiceFila = elemFils.BinarySearch(Convert.ToInt32(divUbicEsp[0].Trim()));
                //Revisamos si esta ubicacion de fila no se ha agregado
                if (indiceFila < 0)
                {
                    elemFils.Add(Convert.ToInt32(divUbicEsp[0].Trim()));
                }
                elemFils.Sort();
            }
            elemFils.Sort();
            int retorno = -1;

            try{ retorno = Convert.ToInt32(ds.Tables[0].Compute("MAX(numero_columna)", "")); }
            catch {}
            return(retorno);
        }
Example #5
0
        void IIdentifierCreationService.ValidateIdentifier(Activity activity, string identifier)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            if (activity.Name.ToLower(CultureInfo.InvariantCulture).Equals(identifier.ToLower(CultureInfo.InvariantCulture)))
            {
                return;
            }

            ArrayList identifiers  = new ArrayList();
            Activity  rootActivity = GetRootActivity(activity);

            identifiers.AddRange(GetIdentifiersInCompositeActivity(rootActivity as CompositeActivity));
            identifiers.Sort();
            if (identifiers.BinarySearch(identifier.ToLower(CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) >= 0)
            {
                throw new ArgumentException(string.Format("Duplicate Component Identifier {0}", identifier));
            }
        }
Example #6
0
        private static CacheSection LookupSection(string section)
        {
            CacheSection dummySection = new CacheSection(section);
            int          index        = sections.BinarySearch(dummySection, new SectionCompare());

            return((index < 0) || (index >= sections.Count) ? null : (CacheSection)sections [index]);
        }
Example #7
0
    static void Main()
    {
        // Create an array list.
        ArrayList al = new ArrayList();

        // Add elements to the array list.
        al.Add(55);
        al.Add(43);
        al.Add(-4);
        al.Add(88);
        al.Add(3);
        al.Add(19);

        Console.Write("Original contents: ");
        foreach (int i in al)
        {
            Console.Write(i + " ");
        }

        Console.WriteLine("\n");

        // Sort
        al.Sort();

        // Use foreach loop to display the list.
        Console.Write("Contents after sorting: ");
        foreach (int i in al)
        {
            Console.Write(i + " ");
        }

        Console.WriteLine("\n");
        Console.WriteLine("Index of 43 is " + al.BinarySearch(43));
    }
Example #8
0
        private int this [LetterLabel label]
        {
            get
            {
                ArrayList a   = labels [(int)label];
                int       pos = a.BinarySearch(next);

                if (pos >= 0)
                {
                    return((int)a [pos]);                     // next found in the array.
                }
                else if (~pos < a.Count)
                {
                    return((int)a [~pos]);                     // next not found in the array, return the next higher.
                }
                else if (a.Count == 0)
                {
                    throw new Error();                      // empty array.
                }
                else
                {
                    return((int)a [0]);                     // wrap around.
                }
            }
            set
            {
                ArrayList a = labels [(int)label];

                Trace.Assert(!a.Contains(value));
                a.Add(value);
                a.Sort();
            }
        }
Example #9
0
        /// <summary>
        /// 修改服务注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="registration"></param>
        internal void ModifyServiceRegistration(BundleContextImpl context, ServiceRegistrationImpl registration)
        {
            // The list of Services published by BundleContextImpl is not sorted, so
            // we do not need to modify it.

            // Remove the ServiceRegistrationImpl from the list of Services published by Class Name
            // and then add at the correct index.
            String[] clazzes = registration.GetClasses();
            int      insertIndex;

            for (int i = 0, size = clazzes.Length; i < size; i++)
            {
                String    clazz    = clazzes[i];
                ArrayList services = (ArrayList)publishedServicesByClass[clazz];
                services.Remove(registration);
                // The list is sorted, so we must find the proper location to insert
                insertIndex = -services.BinarySearch(registration) - 1;
                services.Insert(insertIndex, registration);
            }

            // Remove the ServiceRegistrationImpl from the list of all published Services
            // and then add at the correct index.
            allPublishedServices.Remove(registration);
            // The list is sorted, so we must find the proper location to insert
            insertIndex = -allPublishedServices.BinarySearch(registration) - 1;
            allPublishedServices.Insert(insertIndex, registration);
        }
Example #10
0
 public override void In(FlowScriptEngine.FlowEventArgs e)
 {
     SetArrayList();
     if (ArrayList != null)
     {
         SetValue(nameof(Value));
         SetValue(nameof(StartIndex));
         SetValue(nameof(Count));
         var comparer = new CallbackComparer((x, y) =>
         {
             X = x;
             Y = y;
             FireEvent(Compare, true);
             ProcessChildEvent();
             SetValue(nameof(Result));
             return(Result);
         });
         FoundIndex = ArrayList.BinarySearch(StartIndex, Count, Value, comparer);
         OnSuccess();
     }
     else
     {
         OnFailed();
     }
 }
Example #11
0
 /// <summary>
 /// Returns files in a directory according to multiple file masks (separated by ';').
 /// </summary>
 /// <param name="path">Path of the directory to read.</param>
 /// <param name="multiFileMask">File masks, for example: <i>*.gif;*.jpg;*.png</i>.</param>
 /// <returns>List of files (without duplicates).</returns>
 static public string[] GetFiles(string path, string multiFileMask)
 {
     string[] m = multiFileMask.Split(';');
     if (m.Length > 1)
     {
         ArrayList l = new ArrayList();
         foreach (string oneMask in m)
         {
             if (oneMask.Length > 0)
             {
                 if (oneMask == "*" || oneMask == "*.*")
                 {
                     return(Directory.GetFiles(path));
                 }
                 string[] fs = Directory.GetFiles(path, oneMask);
                 foreach (string f in fs)
                 {
                     int pos = l.BinarySearch(f, StringComparer.InvariantCulture);
                     if (pos < 0)
                     {
                         l.Insert(~pos, f);
                     }
                 }
             }
         }
         return((string[])l.ToArray(typeof(string)));
     }
     if (m.Length > 0 && m[0] != "*" && m[0] != "*.*")
     {
         return(Directory.GetFiles(path, m[0]));
     }
     return(Directory.GetFiles(path));
 }
Example #12
0
        public int[] DropoutErrorsTau(double alpha)
        {
            ArrayList listX           = new ArrayList(arrX);
            ArrayList listIndexIgnore = new ArrayList();

            while (true)
            {
                double min = double.MaxValue, max = double.MinValue;
                double sum = 0, sumXPow2 = 0;
                int    indexMin = -1, indexMax = -1;
                for (int i = 0; i < listX.Count; i++)
                {
                    if (listIndexIgnore.BinarySearch(i) >= 0)
                    {
                        continue;
                    }
                    double x = (double)listX[i];
                    if (x < min)
                    {
                        min      = x;
                        indexMin = i;
                    }
                    if (x > max)
                    {
                        max      = x;
                        indexMax = i;
                    }
                    sum      += x;
                    sumXPow2 += x * x;
                }
                int    n = listX.Count - listIndexIgnore.Count;
                double average = sum / n;
                double devStd = sumXPow2 / (n - 1) - (sum / (n - 1)) * (sum / (n - 1));
                double sigmaStd = (double)Math.Sqrt(devStd);
                double tauXMin, tauXMax;
                tauXMin = (double)Math.Abs(min - average) / sigmaStd;
                tauXMax = (double)Math.Abs(max - average) / sigmaStd;
                int    index;
                double tauMax;
                if (tauXMin >= tauXMax)
                {
                    index  = indexMin;
                    tauMax = tauXMin;
                }
                else
                {
                    index  = indexMax;
                    tauMax = tauXMax;
                }
                //if (tauMax > StatTables.GetTau(alpha, n))
                //{
                //    listIndexIgnore.Add(index);
                //    listIndexIgnore.Sort();
                //}
                //else
                //    break;
            }
            return((int[])listIndexIgnore.ToArray(typeof(int)));
        }
Example #13
0
 private bool IsValueInArray(ArrayList fieldsArray, string valueName)
 {
     if (fieldsArray == null || valueName == null)
     {
         return(false);
     }
     return(fieldsArray.BinarySearch(valueName) >= 0);
 }
Example #14
0
        public bool VerifyContId(string contId)
        {
            int index = workers.BinarySearch(0, workers.Count,
                                             new Worker(contId), null);

            if (index < 0)
            {
                return(false);
            }
            Worker w = workers[index] as Worker;

            if (w.type == WorkerType.Cont)
            {
                return(true);
            }
            return(false);
        }
 private bool IsSidIncluded(int sid)
 {
     if (_sids == null)
     {
         return(true);
     }
     return(_sids.BinarySearch((short)sid) >= 0);
 }
Example #16
0
        public static void getModule <T>(T module)
        {
            var foundedModule = arr.BinarySearch(module);

            Console.WriteLine(foundedModule);
            //var foundedModule
            //return foundedModule;
        }
Example #17
0
        public static void RunFind()//string textToFind, Scope scope, SearchFunctions searchFunctions, FindReplaceOptions options)
        {
            m_foundLocations.Clear();

            switch (searchFunctions)
            {
            case SearchFunctions.AllFunctions:
                ArrayList openFunctions = new ArrayList(Project.Instance.Functions.Count);

                // Process open functions first
                for (int tabCounter = 0; tabCounter < Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count; tabCounter++)
                {
                    FunctionInfo function = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter).CurrentFunction;
                    openFunctions.Add(function.Name);
                    SyntaxEditor editor = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter).syntaxEditor1;
                    FindInText(editor.Text, Options.FindText, scope, function, function.IsTemplateFunction, Options);
                }
                openFunctions.Sort();
                // Process remaining functions
                for (int functionCounter = 0; functionCounter < Project.Instance.Functions.Count; functionCounter++)
                {
                    FunctionInfo function = Project.Instance.Functions[functionCounter];

                    // Don't add functions that have already been added as open functions
                    if (openFunctions.BinarySearch(function.Name) < 0)
                    {
                        FindInText(function.Body, Options.FindText, scope, function, function.IsTemplateFunction, Options);
                    }
                }
                break;

            case SearchFunctions.CurrentFunction:
                if (Controller.Instance.MainForm.UcFunctions != null &&
                    Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count > 0)
                {
                    FunctionInfo function = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage().CurrentFunction;
                    SyntaxEditor editor   = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage().syntaxEditor1;
                    FindInText(editor.Text, Options.FindText, scope, function, function.IsTemplateFunction, Options, editor.SelectedView.Selection.StartOffset, false);
                }
                break;

            case SearchFunctions.OpenFunctions:
                if (Controller.Instance.MainForm.UcFunctions != null &&
                    Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count > 0)
                {
                    for (int tabCounter = 0; tabCounter < Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count; tabCounter++)
                    {
                        FunctionInfo function = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter).CurrentFunction;
                        SyntaxEditor editor   = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter).syntaxEditor1;
                        FindInText(editor.Text, Options.FindText, scope, function, function.IsTemplateFunction, Options);
                    }
                }
                break;

            default:
                throw new NotImplementedException("Not coded yet.");
            }
        }
        public void Update(GridNode node)
        {
            //Get the index of the node into i
            int i = InnerList.BinarySearch(node);

            if (i < 0)
            {
                return;
            }

            int p = i, pn;
            int p1, p2;

            while (true)
            {
                if (p == 0)
                {
                    break;
                }
                p2 = (p - 1) / 2;

                if (OnCompare(p, p2) < 0)
                {
                    SwitchElements(p, p2);
                    p = p2;
                }
                else
                {
                    break;
                }
            }

            if (p < i)
            {
                return;
            }

            while (true)
            {
                pn = p;
                p1 = 2 * p + 1;
                p2 = 2 * p + 2;
                if (InnerList.Count > p1 && OnCompare(p, p1) > 0)
                {
                    p = p1;
                }
                if (InnerList.Count > p2 && OnCompare(p, p2) > 0)
                {
                    p = p2;
                }

                if (p == pn)
                {
                    break;
                }
                SwitchElements(p, pn);
            }
        }
 public static bool IsCurrentTerm(string term)
 {
     if (AllSubjects == null)
     {
         Console.Error.WriteLine("Access to subjects data before initialization.");
         throw new UserException("This page is not available at the moment. Please check back in a few seconds.");
     }
     return(AllSubjects.BinarySearch(term) >= 0);
 }
        public int BinarySearch()
        {
            line_search();
            sum_vector_arr.Sort();

            int ind = sum_vector_arr.BinarySearch(rez);

            return(ind);
        }
Example #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="variables"></param>
        /// <param name="name"></param>
        /// <param name="VARIABLE_COMPARATOR"></param>
        /// <returns></returns>
        public static int BinarySearch(ICollection variables, Object name, IComparer VARIABLE_COMPARATOR)
        {
            ArrayList arrayList = variables as ArrayList;

            if (arrayList != null)
            {
                return(arrayList.BinarySearch(name, VARIABLE_COMPARATOR));
            }
            throw new NotImplementedException("BinarySearch(ICollection variables, Object name, IComparer VARIABLE_COMPARATOR)");
        }
Example #22
0
        /// <summary>
        /// set value to current table column value
        /// </summary>
        /// <param name="FieldName">Set <paramref name="FieldValue"/> to <see cref="SourceSchema"/> table's field value</param>
        /// <param name="FieldValue">Set <see cref="object"/> value to <paramref name="FieldName"/> of current table</param>
        public void SetField(string FieldName, object FieldValue)
        {
            m_currentTable.Fields[FieldName].Value = FieldValue;

            if (m_fieldList.BinarySearch(FieldName, CaseInsensitiveComparer.Default) < 0)
            {
                m_fieldList.Add(FieldName);
                m_fieldList.Sort(CaseInsensitiveComparer.Default);
            }
        }
Example #23
0
 protected void Sacar_Nits(DataTable dt, ref ArrayList nit)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         if (nit.BinarySearch(dt.Rows[i][2].ToString()) < 0)
         {
             nit.Add(dt.Rows[i][2].ToString());
         }
     }
 }
Example #24
0
        //
        // BinarySearch
        //

        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static public int BinarySearch(IList list, Object name)
        {
            if (list is ArrayList)
            {
                ArrayList tmp = (ArrayList)list;
                int       i   = tmp.BinarySearch(name);
                return(i);
            }
            throw new NotImplementedException("BinarySearch(IList list, Object name)");
        }
Example #25
0
        public void TestStandardArrayList()
        {
            //
            // Construct array list.
            //
            ArrayList list = new ArrayList();
            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
                list.Add(strHeroes[ii]);

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, list.Count);

            //
            // []  Use BinarySearch to find selected items.
            //
            // Search and verify selected items.
            for (int ii = 0; ii < strFindHeroes.Length; ++ii)
            {
                // Locate item.
                int ndx = list.BinarySearch(strFindHeroes[ii]);
                Assert.True(ndx >= 0);

                // Verify item.
                Assert.Equal(0, strHeroes[ndx].CompareTo(strFindHeroes[ii]));
            }

            // Return Value;
            // The zero-based index of the value in the sorted ArrayList, if value is found; otherwise, a negative number,
            // which is the bitwise complement of the index of the next element.

            list = new ArrayList();
            for (int i = 0; i < 100; i++)
                list.Add(i);
            list.Sort();

            Assert.Equal(100, ~list.BinarySearch(150));

            //[]null - should return -1
            Assert.Equal(-1, list.BinarySearch(null));

            //[]we can add null as a value and then search it!!!
            list.Add(null);
            list.Sort();
            Assert.Equal(0, list.BinarySearch(null));

            //[]duplicate values, always return the first one
            list = new ArrayList();
            for (int i = 0; i < 100; i++)
                list.Add(5);

            list.Sort();
            //remember this is BinarySeearch
            Assert.Equal(49, list.BinarySearch(5));
        }
Example #26
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                //更新会话

//				Oper _oper = (Oper)Session[ConstValue.LOGIN_USER_SESSION];
//				ArrayList lstPurview = (ArrayList)Session[ConstValue.LOGIN_USER_PURVIEW_SESSION];
//				Session.RemoveAll();
//				//将用户信息保存到Session变量
//				Session[ConstValue.LOGIN_USER_SESSION] = _oper;
//				//将用户权限保存到Session变量
//				Session[ConstValue.LOGIN_USER_PURVIEW_SESSION] = lstPurview;
                //清除
                Session.Remove("QUERY");
                Session.Remove("ExcelCaption");
                Session.Remove("ExcelBottom");
            }
            try
            {
                if (Session[ConstValue.LOGIN_USER_SESSION] == null || Session[ConstValue.LOGIN_USER_PURVIEW_SESSION] == null ||
                    Session[ConstValue.LOGIN_DEPT_SESSION] == null)
                {
                    this.Response.Redirect(@"..\Sysmanage\Default.aspx");
                }
                //登录操作员功能地址列表
                bool isAuthorization = true;

                ArrayList alFuncName = (ArrayList)Session[ConstValue.LOGIN_USER_PURVIEW_SESSION];
                //请求的路径
                string strFileName = System.IO.Path.GetFileName(this.Request.Path);
                //请求的功能名称

                string strFuncName = System.Web.HttpUtility.UrlDecode(this.Request["FuncName"].ToString(), Encoding.GetEncoding("GB2312"));               //this.Server.UrlDecode(this.Request["FuncName"].ToString());

                //进行比对是否具有此权限
                if (alFuncName.BinarySearch(strFuncName) < 0)
                {
                    isAuthorization = false;
                }

                if (!isAuthorization)                //如果无此功能地址
                {
//					Exception ex = new Exception(strFuncName);
//					LogAdapter.WriteInterfaceException(ex);
                    this.Response.Redirect(@"..\Sysmanage\wfmNoAuthorization.aspx");
                }
            }
            catch (BusinessException bex)
            {
                Popup(bex.Message);
                return;
            }
        }
Example #27
0
        public bool IsSeparador(string s)
        {
            int index = Separadores.BinarySearch(s);

            if (index >= 0)
            {
                return(true);
            }

            return(false);
        }
Example #28
0
 internal static bool CheckIfStandardOp(string idlMethodName)
 {
     if (s_standardOpList.BinarySearch(idlMethodName, new CaseInsensitiveComparer()) >= 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #29
0
 /// <summary>
 /// Retorna o םndice de um valor
 /// </summary>
 /// <param name="value">Valor a ser retornado</param>
 /// <returns>O valor do םndice na qual a posiחדo do valor se encontra</returns>
 public int indexValue(string value)
 {
     if (mValues != null)
     {
         return(mValues.BinarySearch(value));
     }
     else
     {
         return(-1);
     }
 }
Example #30
0
        public int Add(object value)
        {
            int pos = list.BinarySearch(value, comparer);

            if (pos < 0)
            {
                pos = ~pos;
            }
            list.Insert(pos, value);
            return(pos);
        }
Example #31
0
    public long minStart(int n, int delta)
    {
        ArrayList parts = new ArrayList();
        long start = 1;
        for (int i = 1; i < 1000000; i++) {
            parts.Add(new Range(start, start + i - 1));
            start += 2 * i;
            if ((long)i >= (long)n*(long)delta)
                break;
        }
        n--;
        Range newRange = new Range(0,0);

        while (n > 0) {
            for (int i = 0; i < parts.Count; i++) {
                Range range = (Range)parts[i];
                newRange.start = range.start + delta;
                newRange.end = range.end + delta;
                int index = parts.BinarySearch(i, parts.Count - i, newRange, null);
                if (index < 0)
                    range.valid = false;
                else {
                    Range otherRange = (Range)parts[index];
                    if (range.end + delta <= otherRange.end) {
                        long diff = range.end + delta - otherRange.start + 1;
                        if (diff < range.length) {
                            range.start = range.end - diff + 1;
                        }
                    }
                    else if (range.start + delta >= otherRange.start) {
                        long diff = otherRange.end - range.start - delta + 1;
                        if (diff < range.length) {
                            range.end = range.start + diff - 1;
                        }
                    }
                }
            }
            ArrayList temp = parts;
            parts = new ArrayList();
            for (int i = 0; i < temp.Count; i++) {
                if (((Range)temp[i]).valid)
                    parts.Add(temp[i]);
            }
            n--;
        }
        for (int i = 0; i < parts.Count; i++) {
            Range range = (Range)parts[i];
            if (!range.valid)
                continue;
            return (range.start);
        }

        return -1;
    }
Example #32
0
        public bool IsCommentario(string s)
        {
            int index = Comentario.BinarySearch(s);

            if (index >= 0)
            {
                return(true);
            }

            return(false);
        }
 public bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc="123_er";
   String strInfo = null;
   Console.Out.Write( s_strClassMethod );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strTFPath + s_strTFName );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strDtTmVer );
   Console.Out.WriteLine( " runTest started..." );
   Object o1;
   Char chValue;
   Int16 i16Value;
   int iReturnValue;
   Object[,] o2ArrValues;
   ArrayList lst1;
   try
     {
     LABEL_860_GENERAL:
     do
       {
       strLoc="536df";
       lst1 = new ArrayList( (cArr) );
       lst1.Sort();
       if ( cArr.Length != lst1.Count)
	 {
	 ++iCountErrors;
	 Console.WriteLine( s_strTFAbbrev + ", Err_623sd! cArr.Length==" + cArr.Length);
	 }
       ++iCountTestcases;
       for(int i=0; i<cArr.Length; i++)
	 {
	 chValue = cArr[i];
	 if ( lst1.BinarySearch(0, lst1.Count, chValue, null) < 0 )
	   {
	   ++iCountErrors;
	   Console.WriteLine( s_strTFAbbrev + "Err_320ye_" + i + " chValue==" + chValue);
	   }
	 }
       } while ( false );
     }
   catch (Exception exc_general)
     {
     ++iCountErrors;
     Console.WriteLine( s_strTFAbbrev + "Error Err_8888yyy!  strLoc=="+ strLoc +" ,exc_general=="+ exc_general );
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Example #34
0
    static void SupprimerTOUS(ArrayList pers, string nomRecherche)
    {
        WorldCup aChercher = new WorldCup(nomRecherche, ' ', 0.0, 0.0, 0);

        int indice = 123456, rang = 0;

        while (indice >= 0)
        {
            indice = pers.BinarySearch(aChercher);
            Console.WriteLine(indice);
            if (indice >= 0)
            {
                Console.WriteLine("{0, 2:D}) {1}", ++rang, pers[indice]);
                pers.RemoveAt(indice);
            }
        }
        if (rang > 0)
            Console.WriteLine("On a supprime {0} WorldCup(s)", rang);
        else
            Console.WriteLine("On ne trouve pas:\n" + aChercher);

        Console.WriteLine();
    }
Example #35
0
    static void Main(string[] args)
    {
        Console.WriteLine("Sorting Algorithms Demo Code\n\n");

        const int nItems = 20;
        Random rdn = new Random(nItems);
        int[] xdata = new int[nItems];

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        bubbleSort1(ref xdata);
        DisplayElements(ref xdata, 'a', "bubbleSort1");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        bubbleSort2(ref xdata);
        DisplayElements(ref xdata, 'a', "bubbleSort2");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        bubbleSort3(ref xdata);
        DisplayElements(ref xdata, 'a', "bubbleSort3");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        bubbleSortRange(ref xdata);
        DisplayElements(ref xdata, 'a', "bubbleSortRange");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        CocktailSort(ref xdata);
        DisplayElements(ref xdata, 'a', "CocktailSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        OddEvenSort(ref xdata);
        DisplayElements(ref xdata, 'a', "OddEvenSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        CombSort(ref xdata);
        DisplayElements(ref xdata, 'a', "CombSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        GnomeSort(ref xdata);
        DisplayElements(ref xdata, 'a', "GnomeSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        InsertionSort(ref xdata);
        DisplayElements(ref xdata, 'a', "InsertionSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        ShellSort(ref xdata);
        DisplayElements(ref xdata, 'a', "ShellSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        SelectionSort(ref xdata);
        DisplayElements(ref xdata, 'a', "SelectionSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        MergeSort(ref xdata, 0, xdata.Length - 1);
        DisplayElements(ref xdata, 'a', "MergeSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        BucketSort(ref xdata);
        DisplayElements(ref xdata, 'a', "BucketSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        Heapsort(ref xdata);
        DisplayElements(ref xdata, 'a', "HeapSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        Count_Sort(ref xdata);
        DisplayElements(ref xdata, 'a', "CountSort");
        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");
        int bits = 4;
        RadixSort(ref xdata, bits);
        DisplayElements(ref xdata, 'a', "RadixSort");
        Console.WriteLine("\n\n");

        //The search tests that follow are divided into two steps
        //(1) Tries to find the 4th data entry in a randomized list. 
        //Since this data value always exist, the result will always be successful
        //(2) Tries to find a numerical value of 100 in a randomized list.
        //Since this data value is beyond the maximum value that the random generator is setup 
        //to produce, the result will always fail. This way all possible outcomes are fully checked.
        //Note that the linear search strategy is the out method that accepts randomized data.
        //For all other searches, the data must be sorted first.

        Console.WriteLine("Search Algorithms Demo Code\n\n");

        MixDataUp(ref xdata, rdn); //Randomize data to be searched
        DisplayElements(ref xdata, 'b', ""); //Display random data

        Console.WriteLine("Using LINEAR SEARCH ALGORITHM to look for 4th data entry in randomized list");
        int location = LinearSearch(ref xdata, xdata[4]); //Look for the 4th data entry in the list
        if (location == -1)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);
        location = LinearSearch(ref xdata, 100); //Look for the number 100 in the list.
        if (location == -1)
            Console.WriteLine("Value of 100 was not found in list");
        else
            Console.WriteLine("Value of 100 was found at at location = {0}", location);

        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', ""); //Display random data
        QuickSort(ref xdata);
        Console.WriteLine("Using INTERPOLATION SEARCH ALGORITHM to look for 4th data entry in randomized list");

        location = InterpolationSearch(ref xdata, xdata[4]);
        if (location == -1)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);

        location = InterpolationSearch(ref xdata, 100);
        if (location == -1)
            Console.WriteLine("Value of 100 was not found in list");
        else
            Console.WriteLine("Value of 100 was found at at location = {0}", location);

        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', ""); //Display random data
        QuickSort(ref xdata);
        Console.WriteLine("Using BINARY SEARCH ALGORITHM to look for 4th data entry in randomized list");

        location = BinSearch(ref xdata, xdata[4]);
        if (location == -1)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);

        location = InterpolationSearch(ref xdata, 100);
        if (location == -1)
            Console.WriteLine("Value of 100 was not found in list");
        else
            Console.WriteLine("Value of 100 was found at at location = {0}", location);

        Console.WriteLine("\n\n");

        //The ArrayList collection in C# comes with its own built-in search algorithm.
        //And can be called up to perform a search as shown below.

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");    //Display random data
        Console.WriteLine("Using the built-in BINARY SEARCH ALGORITHM in ArrayList data structure");
        ArrayList alist = new ArrayList();      //Set up an ArrayList object
        for (int i = 0; i < xdata.Length; i++)
            alist.Add(xdata[i]);                //and add some radomized data to it

        location = alist.BinarySearch(xdata[4]); //Call up its BinarySearch method
        if (location == -1)                     //and run the examples
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);

        location = alist.BinarySearch(100);
        if (location < 0)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);


        Console.WriteLine("Testing to find the n-th largest value in a random array\n\nOriginal Data (method 1): \n");
        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");

        int nthMathIndex1 = 8;

        int nthMaxValue1 = NthLargest1(xdata, nthMathIndex1);

        Console.WriteLine("\nThe " + nthMathIndex1 + " largest value in the array above is: " + nthMaxValue1 + "\n");

        Console.WriteLine("Verifying result... \nFirst verify that original data array is not changed.\n");
        DisplayElements(ref xdata, 'b', "");
        Console.WriteLine("\nThen sort the array and count the requested position from the largest value at the top\n");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");

        //////

        Console.WriteLine("\n\nTesting to find the n-th largest value in a random array\n\nOriginal Data (method 2): \n");
        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");

        int nthMathIndex2 = 4;

        int nthMinValue2 = NthLargest2(xdata, nthMathIndex2);

        Console.WriteLine("\nThe " + nthMathIndex2 + " largest value in the array above is: " + nthMinValue2 + "\n");

        Console.WriteLine("Verifying result... \nFirst verify that original data array is not changed.\n");
        DisplayElements(ref xdata, 'b', "");
        Console.WriteLine("\nThen sort the array and count the requested position from the smallest value at the bottom\n");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");



        Console.WriteLine("\n\nTesting to find the m-th smallest value in a random array\n\nOriginal Data (method 1): \n");
        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");

        int mthMathIndex1 = 3;

        int mthMinValue1 = MthSmallest1(xdata, mthMathIndex1);

        Console.WriteLine("\nThe " + mthMathIndex1 + " smallest value in the array above is: " + mthMinValue1 + "\n");

        Console.WriteLine("Verifying result... \nFirst verify that original data array is not changed.\n");
        DisplayElements(ref xdata, 'b', "");
        Console.WriteLine("\nThen sort the array and count the requested position from the smallest value at the bottom\n");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");


        Console.WriteLine("\n\nTesting to find the m-th smallest value in a random array\n\nOriginal Data (method 2): \n");
        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");

        int mthMathIndex2 = 3;

        int mthMinValue2 = MthSmallest2(xdata, mthMathIndex2);

        Console.WriteLine("\nThe " + mthMathIndex2 + " smallest value in the array above is: " + mthMinValue2 + "\n");

        Console.WriteLine("Verifying result... \nFirst verify that original data array is not changed.\n");
        DisplayElements(ref xdata, 'b', "");
        Console.WriteLine("\nThen sort the array and count the requested position from the smallest value at the bottom\n");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");

        Console.WriteLine("\n\nTesting sorting utitlities\n");
        int[] sortedInts = new int[] { 1, 5, 20, 50 };
        int[] unsortedInts = new int[] { 35, 2, 56, 1 };
        int[] reversedInts = new int[] { 10, 9, 8, 7 };
        string[] sortedStrings = new string[] { "monkey", "duck", "bird" };
        string[] unsortedStrings = new string[] { "duck", "monkey", "dog" };
        string[] reversedStrings = new string[] { "dog", "duck", "monkey" };

        Console.WriteLine(IsSorted(sortedInts));                // True
        Console.WriteLine(IsSortedDescending(sortedInts));      // False
        Console.WriteLine(IsSorted(unsortedInts));              // False
        Console.WriteLine(IsSortedDescending(unsortedInts));    // False
        Console.WriteLine(IsSorted(reversedInts));              // False
        Console.WriteLine(IsSortedDescending(reversedInts));    // True
        Console.WriteLine(IsSorted(sortedStrings));             // True
        Console.WriteLine(IsSortedDescending(sortedStrings));   // False
        Console.WriteLine(IsSorted(unsortedStrings));           // False
        Console.WriteLine(IsSortedDescending(unsortedStrings)); // False
        Console.WriteLine(IsSorted(reversedStrings));           // False
        Console.WriteLine(IsSortedDescending(reversedStrings)); // True
        Console.ReadLine();

        Console.WriteLine("\n\nTesting Conversion from List to Array\n");
        List<string> myList = new List<string>();
        myList.Add("dog");
        myList.Add("cat");
        myList.Add("duck");
        myList.Add("monkey");
        myList.Add("bird");
        string[] myString = myList.ToArray();
        foreach (string s in myString)
            Console.WriteLine(s);

        Console.WriteLine("\n\nTesting Conversion from Array to List\n");
        string[] str = new string[] { "duck", "cat", "dog", "monkey", "bird" };
        List<string> myOtherList = new List<string>(str);
        myOtherList = str.ToList();
        foreach (string s in myOtherList)
            Console.WriteLine(s);

        Console.ReadLine();
    }
Example #36
0
 /// <summary>
 /// Retrieves the data in a list mapped by a key.
 /// Returns null if no such data exists.
 /// </summary>
 /// <param name="list">The sorted list to check.</param>
 /// <param name="key">The data to map with.</param>
 /// <param name="comparator">IComparer object for sorting.</param>
 protected internal static object GetData(ArrayList list, object key, IComparer comparator)
 {
     int ind;
     string s = key as string;
     if (s != null)
     {
         s = s.NormalizeWhiteSpaces();
         ind = list.BinarySearch(s, comparator);
     }
     else
     {
         ind = list.BinarySearch(key, comparator);
     }
     if (ind < 0) return null;
     return list[ind];
 }
Example #37
0
    protected void forwardSend_Click(object sender, EventArgs e)
    {
        SortedList noPrivilegeList = new SortedList();
        SortedList noEmailAddressList = new SortedList();
        SortedList wrongEmailAddressList = new SortedList();
        ArrayList allExternalUsers = new ArrayList();

        ISubjectFetchProvider subjectProvider = (new SubjectProviderFactory()).GetSubjectFetchProvider();
        ArrayList userList = new ArrayList();
        IList users = new ArrayList();
        const string MatchEmailPattern =
            @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
           + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
           + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
           + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

        try
        {
            StringBuilder mailtoUsers = new StringBuilder();
            MailToUser[] jsonObjectArray = WebUtility.DeserializeAjaxResult("[" + hideMailto.Value + "]", typeof(MailToUser[])) as MailToUser[];
            String[] externalUsers = this.txtMailto.Value.Trim().Split(';'); //外部收件者
            foreach (string emailAddress in externalUsers)
            {
                if (externalUsers.Length==0)
                {
                    break;
                }
                string address = emailAddress.Trim();

                if (address.Length == 0)
                {
                    noEmailAddressList.Add(address, address);
                }
                else
                {
                    if (Regex.IsMatch(address, MatchEmailPattern))
                    {
                        if (allExternalUsers.BinarySearch(address) < 0)
                        {
                            allExternalUsers.Add(address);
                        }
                    }
                    else
                    {
                        wrongEmailAddressList.Add(address, address);
                    }
                }
            }

            foreach (MailToUser mailtoUser in jsonObjectArray)
            {
                users.Clear();
                switch (Convert.ToInt32(mailtoUser.SubjectType))
                {
                    case 0:
                        if (!string.IsNullOrEmpty(mailtoUser.EmailAddress))
                        {
                            if (Regex.IsMatch(mailtoUser.EmailAddress, MatchEmailPattern))
                            {
                                userList.Add(mailtoUser);
                            }
                            else
                            {
                                wrongEmailAddressList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                            }
                        }
                        else
                        {
                            noEmailAddressList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                        }
                        break;
                    case 1:
                        users = subjectProvider.GetUsersInOU(mailtoUser.SubjectId);
                        break;
                    case 2:
                        users = subjectProvider.GetUsersInGroup(mailtoUser.SubjectId);
                        break;
                    case 3:
                        users = subjectProvider.GetUsersInRole(mailtoUser.SubjectId);
                        break;
                    default:
                        break;
                }

                if (users != null && users.Count > 0)
                {
                    foreach (User user in users)
                    {
                        if (!string.IsNullOrEmpty(user.EmailAddress))
                        {
                            if (Regex.IsMatch(user.EmailAddress, MatchEmailPattern))
                            {
                                userList.Add(ConvertUserToMailToUser(user));
                            }
                            else
                            {
                                wrongEmailAddressList.Add(user.SubjectId, user.DisplayName);
                            }
                        }
                        else
                        {
                            noEmailAddressList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                        }
                    }
                }
            }
            ArrayList uniList = new ArrayList();
            if (userList.Count > 0)
            {
                int i;
                MailToUser preUser = (MailToUser)userList[0];
                uniList.Add(preUser);
                ComparerUtility comp = new ComparerUtility();
                comp.ObjectType = (typeof(MailToUser));
                comp.SortingOrder = (int)ComparerUtility.SortOrder.Ascending;
                comp.SortProperty = "SubjectId";
                MailToUser[] userAry = userList.ToArray(typeof(MailToUser)) as MailToUser[];
                Array.Sort(userAry, comp);

                //移除重複的,因為上面有先做過排序
                for (i = 1; i < userAry.Length; i++)
                {
                    if (preUser.SubjectId != ((MailToUser)userAry[i]).SubjectId)
                    {
                        preUser = (MailToUser)userAry[i];
                        uniList.Add(preUser);
                    }
                }
            }
            foreach (MailToUser mailtoUser in uniList)
            {
                if (!allowSendToNoPrivilegeUser)
                {
                    KBUserDetailInfo checkkbuser;
                    checkkbuser = kbuserService.GetKBUserDetailBySubjectId(mailtoUser.SubjectId);

                    if (PrivilegeUtility.HasPrivilege(PrivilegeType.DocumentPrivilege, docId, checkkbuser, DocumentOperationAttributes.DOC_READ_DOCUMENT))
                    {
                        mailtoUsers.Append(mailtoUser.DisplayName).Append("<").Append(mailtoUser.EmailAddress).Append(">;");
                    }
                    else
                    {
                        noPrivilegeList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                    }
                }
                else
                {
                    mailtoUsers.Append(mailtoUser.DisplayName).Append("<").Append(mailtoUser.EmailAddress).Append(">;");
                }
            }
            string mailto = mailtoUsers.ToString();
            if (allowSendToNoPrivilegeUser)
            {
                if (allExternalUsers.Count>0)
                {
                    mailto += string.Join(";", ((string[])allExternalUsers.ToArray(typeof(string))));
                }
            }

            //如果最後還是有 email 要寄送的話
            if (mailto.Length > 0)
            {
                string subject = "[" + i18n.GetMessage("m858") + "] " + this.txtSubject.Value;
                string message = this.txtAreaBody.Value.Replace(" ", "&nbsp;").Replace("\r\n", "<br />");
                string mailCC = string.Empty;
                string mailBCC = string.Empty;

                if (sendToMe.Checked)
                {
                    if (!string.IsNullOrEmpty(currentUser.EmailAddress))
                    {
                        if (Regex.IsMatch(currentUser.EmailAddress, MatchEmailPattern))
                        {
                            mailCC = currentUser.DisplayName + "<" + currentUser.EmailAddress + ">";
                        }
                        else
                        {
                            wrongEmailAddressList.Add(currentUser.SubjectId, currentUser.DisplayName);
                        }
                    }
                    else
                    {
                        noEmailAddressList.Add(currentUser.SubjectId, currentUser.DisplayName);
                    }
                }
                //建立樣本引擎實體
                VelocityEngine velocity = new VelocityEngine();
                //設定引擎的一些屬性
                ExtendedProperties props = new ExtendedProperties();
                //設定樣版被載入的來源位置
                props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                ArrayList resourceLocators = new ArrayList();
                resourceLocators.Add(".");
                resourceLocators.Add(System.Configuration.ConfigurationManager.AppSettings["TemplatePath"]);
                props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, resourceLocators);
                //設定讀寫樣版的 Encoding
                props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
                props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
                //將設定的屬性塞給引擎
                velocity.Init(props);

                Template detailTemplate = velocity.GetTemplate(System.Configuration.ConfigurationManager.AppSettings["DocumentDetailTemplateFileName"]);
                Template masterTemplate = velocity.GetTemplate(System.Configuration.ConfigurationManager.AppSettings["ForwardMasterTemplateFileName"]);
                VelocityContext context = new VelocityContext();
                StringWriter detailWriter = new StringWriter();
                StringWriter masterWriter = new StringWriter();
                string Attachs = string.Empty;
                ArrayList list = new ArrayList();
                string photoPath = System.Configuration.ConfigurationManager.AppSettings["photoPath"];
                KBUserInfo kbuser = GetKBUser(doc.VersionCreatorId);
                string personalPhotoFilenName = kbuser.AvatarPath;

                if (personalPhotoFilenName == null || personalPhotoFilenName.Trim().Length == 0)
                {
                    personalPhotoFilenName = "default.jpg";
                }
                string uppath = Server.MapPath(Request.ApplicationPath + photoPath + personalPhotoFilenName);
                context.Put("UserImage", kbuser.AvatarPath);
                Attachs = uppath;
                string folderPath = string.Empty;
                FolderInfo[] fiArray = folderService.GetFolderPath(currentUser, documentService.GetParentFolders(currentUser, doc.DocumentId)[0].FolderId);

                for (int i = 0; i < fiArray.Length; i++)
                {
                    if (!fiArray[i].DisplayName.Equals(GSS.Vitals.KnowledgeBase.SpecialFolder.ROOT_FOLDER))
                    {
                        if (fiArray[i].DisplayName.Equals(GSS.Vitals.KnowledgeBase.SpecialFolder.PUBLIC_FOLDER))
                        {
                            folderPath += i18n.GetMessage("m82");
                        }
                        else
                        {
                            folderPath += fiArray[i].DisplayName;
                        }
                        if (i < fiArray.Length - 1)
                        {
                            folderPath += " / ";
                        }
                    }
                }
                context.Put("Author", kbuser.DisplayName.Trim());
                context.Put("Modify", i18n.GetMessage("m152")); //修改於
                TimeSpan ts2 = WebUtility.GetCurrentUserUTCOffset(currentUser);
                DateTime dt2 = doc.VersionCreationDatetime.Add(ts2);

                context.Put("ModifyDateTime", dt2.ToString());
                context.Put("DocumentClass", i18n.GetMessage("m273"));
                context.Put("DocumentClassName", doc.DocumentClass.ClassName.Trim());

                context.Put("FolderPath", folderPath);
                context.Put("Link", System.Configuration.ConfigurationManager.AppSettings["lambdaSite"] + "readdocument.aspx?documentid=" + doc.DocumentId);
                context.Put("VersionTitle", doc.VersionTitle.Trim());
                //render 文件欄位

                for (int i = 0; i < doc.DocumentAttributes.Length; i++)
                {
                    if (doc.DocumentAttributes[i].AttributeType != GSS.Vitals.KnowledgeBase.AttributeType.TITLE)
                    {
                        if (doc.DocumentAttributes[i].Value != string.Empty)
                        {
                            GSS.Vitals.KnowledgeBase.UIField.FieldType ft = GSS.Vitals.KnowledgeBase.UIField.ParseUIFieldType(doc.DocumentAttributes[i].UIFieldInfo);

                            if (ft == GSS.Vitals.KnowledgeBase.UIField.FieldType.CALENDAR)
                            {
                                DateTime dt = KBUtility.ParseISO8601SimpleString(doc.DocumentAttributes[i].Value);
                                dt = dt.Add(WebUtility.GetCurrentUserUTCOffset(currentUser));
                                list.Add(new InfoItem(doc.DocumentAttributes[i].DisplayName, dt.ToString("yyyy/MM/dd")));
                            }
                            else if (ft == GSS.Vitals.KnowledgeBase.UIField.FieldType.DATETIME)
                            {
                                DateTime dt = KBUtility.ParseISO8601SimpleString(doc.DocumentAttributes[i].Value);
                                dt = dt.Add(WebUtility.GetCurrentUserUTCOffset(currentUser));
                                list.Add(new InfoItem(doc.DocumentAttributes[i].DisplayName, dt.ToString("yyyy/MM/dd HH:mm:ss")));
                            }
                            else if (ft == GSS.Vitals.KnowledgeBase.UIField.FieldType.RICHTEXT)
                            {
                                list.Add(new InfoItem(doc.DocumentAttributes[i].DisplayName, doc.DocumentAttributes[i].Value));
                            }
                            else
                            {
                                list.Add(new InfoItem(doc.DocumentAttributes[i].DisplayName, WebUtility.crlf2br(doc.DocumentAttributes[i].Value)));
                            }
                        }
                    }
                }
                context.Put("Items", list);
                detailTemplate.Merge(context, detailWriter);

                //將Detail加入到master當中
                context.Put("DocSections", detailWriter.GetStringBuilder().ToString());
                string header = String.Format(i18n.GetMessage("m862"), currentUser.DisplayName, "<a href='" + System.Configuration.ConfigurationManager.AppSettings["lambdaSite"] + "'>" +
                                        System.Configuration.ConfigurationManager.AppSettings["SystemName"] + "</a>");
                context.Put("Header", header);
                context.Put("Message", i18n.GetMessage("m863") + ":<br/><br/>" + message);
                masterTemplate.Merge(context, masterWriter);
                mailService.SendMail(mailService.FromMailAddress, mailto, mailBCC, mailCC, subject, masterWriter.GetStringBuilder().ToString(), Attachs);
                forwardService.SetForwardRecord((KBUserInfo)currentUser, mailto, mailCC, subject, masterWriter.GetStringBuilder().ToString(), message);
                this.txtMailto.Value = string.Empty;
                this.txtAreaBody.Value = string.Empty;
                this.sendToMe.Checked = false;
            }

            if (noEmailAddressList.Count > 0 || wrongEmailAddressList.Count > 0 || noPrivilegeList.Count > 0)
            {
                Table a = makeTable(noPrivilegeList, i18n.GetMessage("m478"));
                Table b = makeTable(noEmailAddressList, i18n.GetMessage("m926"));
                Table c = makeTable(wrongEmailAddressList, i18n.GetMessage("m927"));
                renderForwardResult(new Table[] { a, b, c });
            }
            else
            {
                forwardResultPanel.Visible = false;
            }
        }
        catch (Exception ex)
        {
            log4net.LogManager.GetLogger("MAIL").Error(ex.Message, ex);
            renderForwardResult(ex);
        }
    }
Example #38
0
    static void Inserer(ArrayList pers, string nom, char sexe, double taille,
        double poids, int numero)
    {
        nom = nom.ToUpper();
        for (int i = nom.Length; i < 30; i++) nom += " ";

        WorldCup aAjouter = new WorldCup(nom, sexe, taille, poids, numero);

        int indice = pers.BinarySearch(aAjouter);
        if (indice < 0)
            indice = (-indice) - 1;
        pers.Insert(indice, aAjouter);
    }
Example #39
0
    private void CompareObjects(ArrayList good, ArrayList bad, Hashtable hsh1)
    {
        //IList, this includes ICollection tests as well!!
        DoIListTests(good, bad, hsh1);

        //we will now test ArrayList specific methods
        good.Clear();
        for (int i = 0; i < 100; i++)
            good.Add(i);

        //AL's CopyTo methods
        int[] iArr1 = null;
        int[] iArr2 = null;
        iArr1 = new int[100];
        iArr2 = new int[100];
        good.CopyTo(iArr1);
        bad.CopyTo(iArr2);
        for (int i = 0; i < 100; i++)
        {
            if (iArr1[i] != iArr2[i])
                hsh1["CopyTo"] = "()";
        }

        iArr1 = new int[100];
        iArr2 = new int[100];
        good.CopyTo(0, iArr1, 0, 100);
        try
        {
            bad.CopyTo(0, iArr2, 0, 100);
            for (int i = 0; i < 100; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["CopyTo"] = "()";
            }
        }
        catch
        {
            hsh1["CopyTo"] = "(int, Array, int, int)";
        }

        iArr1 = new int[200];
        iArr2 = new int[200];
        for (int i = 0; i < 200; i++)
        {
            iArr1[i] = 50;
            iArr2[i] = 50;
        }

        good.CopyTo(50, iArr1, 100, 20);
        try
        {
            bad.CopyTo(50, iArr2, 100, 20);
            for (int i = 0; i < 200; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["CopyTo"] = "(Array, int, int)";
            }
        }
        catch
        {
            hsh1["CopyTo"] = "(int, Array, int, int)";
        }

        //Clone()
        ArrayList alstClone = (ArrayList)bad.Clone();
        //lets make sure that the clone is what it says it is
        if (alstClone.Count != bad.Count)
            hsh1["Clone"] = "Count";
        for (int i = 0; i < bad.Count; i++)
        {
            if (alstClone[i] != bad[i])
                hsh1["Clone"] = "[]";
        }

        //GerEnumerator()
        IEnumerator ienm1 = null;
        IEnumerator ienm2 = null;

        ienm1 = good.GetEnumerator(0, 100);
        try
        {
            ienm2 = bad.GetEnumerator(0, 100);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, false);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

        ienm1 = good.GetEnumerator(50, 50);
        try
        {
            ienm2 = bad.GetEnumerator(50, 50);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, false);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

        try
        {
            bad.GetEnumerator(50, 150);
            hsh1["GetEnumerator"] = "(int, int)";
        }
        catch (Exception)
        {
        }

        ienm1 = good.GetEnumerator(0, 100);
        try
        {
            ienm2 = bad.GetEnumerator(0, 100);
            good.RemoveAt(0);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, true);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

        //GetRange
        good.Clear();
        for (int i = 0; i < 100; i++)
            good.Add(i);

        ArrayList alst1 = good.GetRange(0, good.Count);
        try
        {
            ArrayList alst2 = bad.GetRange(0, good.Count);
            for (int i = 0; i < good.Count; i++)
            {
                if (alst1[i] != alst2[i])
                    hsh1["GetRange"] = i;
            }
        }
        catch
        {
            hsh1["Range"] = "(int, int)";
        }

        //IndexOf(Object, int)

        if (bad.Count > 0)
        {
            for (int i = 0; i < good.Count; i++)
            {
                if (good.IndexOf(good[i], 0) != bad.IndexOf(good[i], 0))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (good.IndexOf(good[i], i) != bad.IndexOf(good[i], i))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.IndexOf(good[i], i + 1) != bad.IndexOf(good[i], i + 1))
                    {
                        hsh1["IndexOf"] = "(Object, int)";
                    }
                }
            }

            try
            {
                bad.IndexOf(1, -1);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            try
            {
                bad.IndexOf(1, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            // IndexOf(Object, int, int)
            // The semantics of this method has changed, the 3rd parameter now refers to count instead of length
            for (int i = 0; i < good.Count; i++)
            {
                if (good.IndexOf(good[i], 0, good.Count - 1) != bad.IndexOf(good[i], 0, good.Count - 1))
                {
                    hsh1["IndexOf"] = "(Object, int, int)";
                }
                if (good.IndexOf(good[i], i, good.Count - i) != bad.IndexOf(good[i], i, good.Count - i))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (good.IndexOf(good[i], i, 0) != bad.IndexOf(good[i], i, 0))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.IndexOf(good[i], i + 1, good.Count - (i + 1)) != bad.IndexOf(good[i], i + 1, good.Count - (i + 1)))
                    {
                        hsh1["IndexOf"] = "(Object, int)";
                    }
                }
            }

            try
            {
                bad.IndexOf(1, 0, -1);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            try
            {
                bad.IndexOf(1, 0, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            try
            {
                bad.IndexOf(1, bad.Count - 1, bad.Count - 2);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            //LastIndexOf(Object)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i]) != bad.LastIndexOf(good[i]))
                {
                    hsh1["LastIndexOf"] = "(Object)";
                }
                if (good.LastIndexOf(i + 1000) != bad.LastIndexOf(i + 1000))
                {
                    hsh1["LastIndexOf"] = "(Object)";
                }
            }

            try
            {
                bad.LastIndexOf(null);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            //LastIndexOf(Object, int)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i], good.Count - 1) != bad.LastIndexOf(good[i], good.Count - 1))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], 0) != bad.LastIndexOf(good[i], 0))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], i) != bad.LastIndexOf(good[i], i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.LastIndexOf(good[i], i + 1) != bad.LastIndexOf(good[i], i + 1))
                    {
                        hsh1["LastIndexOf"] = "(Object, int)";
                    }
                }
            }

            try
            {
                bad.LastIndexOf(1, -1);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            try
            {
                bad.LastIndexOf(1, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            //LastIndexOf(Object, int, int)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i], good.Count - 1, 0) != bad.LastIndexOf(good[i], good.Count - 1, 0))
                {
                    hsh1["LastIndexOf"] = "(Object, int, int)";
                }
                if (good.LastIndexOf(good[i], good.Count - 1, i) != bad.LastIndexOf(good[i], good.Count - 1, i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], i, i) != bad.LastIndexOf(good[i], i, i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.LastIndexOf(good[i], good.Count - 1, i + 1) != bad.LastIndexOf(good[i], good.Count - 1, i + 1))
                    {
                        hsh1["LastIndexOf"] = "(Object, int)";
                    }
                }
            }

            try
            {
                bad.LastIndexOf(1, 1, -1);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            try
            {
                bad.LastIndexOf(1, bad.Count - 2, bad.Count - 1);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }
        }

        //ReadOnly()
        ArrayList alst3 = ArrayList.ReadOnly(bad);
        if (!alst3.IsReadOnly)
            hsh1["ReadOnly"] = "Not";

        IList ilst1 = ArrayList.ReadOnly((IList)bad);
        if (!ilst1.IsReadOnly)
            hsh1["ReadOnly"] = "Not";

        //Synchronized()
        alst3 = ArrayList.Synchronized(bad);
        if (!alst3.IsSynchronized)
            hsh1["Synchronized"] = "Not";

        ilst1 = ArrayList.Synchronized((IList)bad);
        if (!ilst1.IsSynchronized)
            hsh1["Synchronized"] = "Not";

        //ToArray()
        if (good.Count == bad.Count)
        {
            object[] oArr1 = good.ToArray();
            object[] oArr2 = bad.ToArray();
            for (int i = 0; i < good.Count; i++)
            {
                if ((int)oArr1[i] != (int)oArr2[i])
                    hsh1["ToArray"] = "()";
            }

            //ToArray(type)
            iArr1 = (int[])good.ToArray(typeof(int));
            iArr2 = (int[])bad.ToArray(typeof(int));
            for (int i = 0; i < good.Count; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["ToArray"] = "(Type)";
            }
        }

        //Capacity - get
        if (good.Capacity != bad.Capacity)
        {
            hsh1["Capacity"] = "get";
        }

        //Fixed size methods
        if (!hsh1.ContainsKey("IsReadOnly"))
        {
            good.Clear();
            for (int i = 100; i > 0; i--)
                good.Add(i);
            //Sort() & BinarySearch(Object)
            bad.Sort();
            for (int i = 0; i < bad.Count - 1; i++)
            {
                if ((int)bad[i] > (int)bad[i + 1])
                    hsh1["Sort"] = "()";
            }

            for (int i = 0; i < bad.Count; i++)
            {
                if (bad.BinarySearch(bad[i]) != i)
                    hsh1["BinarySearch"] = "(Object)";
            }

            //Reverse()
            bad.Reverse();
            if (bad.Count > 0)
            {
                for (int i = 0; i < 99; i++)
                {
                    if ((int)bad[i] < (int)bad[i + 1])
                        hsh1["Reverse"] = "()";
                }

                good.Clear();
                for (int i = 100; i > 0; i--)
                    good.Add(i.ToString());
            }

            good.Clear();
            for (int i = 90; i > 64; i--)
                good.Add(((Char)i).ToString());

            try
            {
                bad.Sort(new CaseInsensitiveComparer());
                if (bad.Count > 0)
                {
                    for (int i = 0; i < (bad.Count - 1); i++)
                    {
                        if (((String)bad[i]).CompareTo(((String)bad[i + 1])) >= 0)
                            hsh1["Sort"] = "(IComparer)";
                    }
                    for (int i = 0; i < bad.Count; i++)
                    {
                        if (bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                            hsh1["BinarySearch"] = "(Object, IComparer)";
                    }
                }
                bad.Reverse();

                good.Clear();
                for (int i = 65; i < 91; i++)
                    good.Add(((Char)i).ToString());

                if (bad.Count > 0)
                {
                    for (int i = 0; i < good.Count; i++)
                    {
                        if (bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                            hsh1["BinarySearch"] = "(int, int, Object, IComparer)";
                    }
                }
            }
            catch (Exception)
            {
            }

            good.Clear();
            for (int i = 0; i < 100; i++)
                good.Add(i);

            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);

            try
            {
                bad.SetRange(0, que);
            }
            catch (Exception ex)
            {
                hsh1["SetRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }
            for (int i = bad.Count; i < bad.Count; i++)
            {
                if ((int)bad[i] != (i + 5000))
                {
                    hsh1["SetRange"] = i;
                }
            }
        }
        else
        {
            //we make sure that the above methods throw here
            good.Clear();
            for (int i = 100; i > 0; i--)
                good.Add(i);

            try
            {
                bad.Sort();
                hsh1["Sort"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }

            try
            {
                bad.Reverse();
                hsh1["Reverse"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Reverse"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }

            try
            {
                bad.Sort(new CaseInsensitiveComparer());
                hsh1["Sort"] = "Copy - Icomparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }

            try
            {
                bad.Sort(0, 0, new CaseInsensitiveComparer());
                hsh1["Sort"] = "Copy - int, int, IComparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }

            //BinarySearch
            try
            {
                for (int i = 0; i < bad.Count; i++)
                {
                    if (bad.BinarySearch(bad[i]) != i)
                        hsh1["BinarySearch"] = "(Object)";
                }
                hsh1["BinarySearch"] = "(Object)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

            try
            {
                for (int i = 0; i < bad.Count; i++)
                {
                    if (bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                        hsh1["BinarySearch"] = "(Object)";
                }

                hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

            try
            {
                for (int i = 0; i < bad.Count; i++)
                {
                    if (bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                        hsh1["BinarySearch"] = "(Object)";
                }

                hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

            good.Clear();
            for (int i = 0; i < 100; i++)
                good.Add(i);

            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);

            try
            {
                bad.SetRange(0, que);
                hsh1["Sort"] = "Copy - int, int, IComparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }
        }

        //Modifiable methods
        if (!hsh1.ContainsKey("IsReadOnly") && !hsh1.ContainsKey("Fixed"))
        {
            good.Clear();
            for (int i = 0; i < 100; i++)
                good.Add(i);

            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);
            bad.InsertRange(0, que);
            for (int i = 0; i < 100; i++)
            {
                if ((int)bad[i] != i + 5000)
                {
                    hsh1["InsertRange"] = i;
                }
            }

            //AddRange()
            que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 2222);
            bad.AddRange(que);
            for (int i = bad.Count - 100; i < bad.Count; i++)
            {
                if ((int)bad[i] != (i - (bad.Count - 100)) + 2222)
                {
                    hsh1["AddRange"] = i + " " + (int)bad[i];
                }
            }

            bad.RemoveRange(0, que.Count);
            for (int i = 0; i < 100; i++)
            {
                if ((int)bad[i] != i)
                {
                    hsh1["RemoveRange"] = i + " " + (int)bad[i];
                }
            }

            //Capacity
            try
            {
                bad.Capacity = bad.Capacity * 2;
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            try
            {
                bad.Capacity = -1;
                hsh1["Capacity"] = "No_Exception_Thrown, -1";
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            int iMakeSureThisDoesNotCause = 0;
            while (bad.Capacity == bad.Count)
            {
                if (iMakeSureThisDoesNotCause++ > 100)
                    break;
                bad.Add(bad.Count);
            }
            if (iMakeSureThisDoesNotCause > 100)
                hsh1["TrimToSize"] = "Monekeyed, " + bad.Count + " " + bad.Capacity;

            //TrimToSize()
            try
            {
                bad.TrimToSize();
                if (bad.Capacity != bad.Count)
                {
                    hsh1["TrimToSize"] = "Problems baby";
                }
            }
            catch (Exception ex)
            {
                hsh1["TrimToSize"] = ex.GetType().Name;
            }
        }
        else
        {
            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);
            try
            {
                bad.AddRange(que);
                hsh1["AddRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["AddRange"] = "Copy_ExceptionType";
            }

            try
            {
                bad.InsertRange(0, que);
                hsh1["InsertRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["InsertRange"] = "Copy_ExceptionType";
            }

            good.Clear();
            for (int i = 0; i < 10; i++)
                good.Add(i);
            try
            {
                bad.RemoveRange(0, 10);
                hsh1["RemoveRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["RemoveRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }

            try
            {
                bad.Capacity = bad.Capacity * 2;
                hsh1["Capacity"] = "No_Exception_Thrown, bad.Capacity*2";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            try
            {
                bad.TrimToSize();
                hsh1["TrimToSize"] = "No_Exception_Thrown";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["TrimToSize"] = ex.GetType().Name;
            }
        }
    }
Example #40
0
 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( s_strClassMethod + ": " + s_strTFName + " runTest started..." );
     ArrayList list = null;
     String strLoc = "Loc_000oo";
     String [] strHeroes =
         {
             "Aquaman",
             "Atom",
             "Batman",
             "Black Canary",
             "Captain America",
             "Captain Atom",
             "Catwoman",
             "Cyborg",
             "Flash",
             "Green Arrow",
             "Green Lantern",
             "Hawkman",
             "Huntress",
             "Ironman",
             "Nightwing",
             "Robin",
             "SpiderMan",
             "Steel",
             "Superman",
             "Thor",
             "Wildcat",
             "Wonder Woman",
     };
     String [] strFindHeroes =
         {
             "Batman",
             "Superman",
             "SpiderMan",
             "Wonder Woman",
             "Green Lantern",
             "Flash",
             "Steel"
         };
     try 
     {
         strLoc = "Loc_001o1";
         ++iCountTestcases;
         try
         {
             list = new ArrayList();
             if ( list == null )
             {
                 Console.WriteLine( s_strTFName+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
             }
             for ( int ii = 0; ii < strHeroes.Length; ++ii )
                 list.Add( strHeroes[ii] );
             if ( list.Count != strHeroes.Length )
             {
                 Console.WriteLine( "E_202: ");
                 ++iCountErrors;
             }
         }
         catch (Exception ex)
         {
             ++iCountErrors;
             Console.WriteLine( s_strTFName+ "E_10001: Unexpected Exception: " + ex.ToString() );
         }
         ++iCountTestcases;
         try
         {
             for ( int ii = 0; ii < strFindHeroes.Length; ++ii )
             {
                 int ndx = list.BinarySearch(strFindHeroes[ii]);
                 if ( ndx >= strHeroes.Length )
                 {
                     ++iCountErrors;
                     Console.WriteLine( "Err_753fg unexpected value returned" );
                 }
                 if ( strHeroes[ndx].CompareTo( strFindHeroes[ii] ) != 0 )
                 {
                     ++iCountErrors;
                     Console.WriteLine( "Err_853deg! unexpected value returned");
                 }
             }
         }
         catch (Exception ex)
         {
             ++iCountErrors;
             Console.WriteLine( s_strTFName+ "E_10002: Unexpected Exception: " + ex.ToString() );
         }
         strLoc = "Loc_00437sg";
         iCountTestcases++;
         list = new ArrayList();
         for(int i=0; i<100; i++)
             list.Add(i);
         list.Sort();
         if(~list.BinarySearch(150)!= 100)
         {
             iCountErrors++;
             Console.WriteLine( "Err_7853rg! wrong value returned, " + list.BinarySearch(150) );
         }
         strLoc = "Loc_347sg";
         iCountTestcases++;
         if(list.BinarySearch(null)!= -1)
         {
             iCountErrors++;
             Console.WriteLine( "Err_247sg! wrong value returned, " + list.BinarySearch(null) );
         }
         strLoc = "Loc_87245dsg";
         iCountTestcases++;
         list.Add(null);
         list.Sort();
         if(list.BinarySearch(null)!= 0)
         {
             iCountErrors++;
             Console.WriteLine( "Err_7853rg! wrong value returned, " + list.BinarySearch(null) );
         }
         strLoc = "Loc_9437tsdfg";
         iCountTestcases++;
         list = new ArrayList();
         for(int i=0; i<100; i++)
             list.Add(5);
         list.Sort();
         if(list.BinarySearch(5)!= 49)
         {
             iCountErrors++;
             Console.WriteLine( "Err_3846tsdg! wrong value returned, " + list.BinarySearch(5) );
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     Console.Error.Write( s_strClassMethod );
     Console.Error.Write( ": " );
     if ( iCountErrors == 0 )
     {
         Console.Error.WriteLine( s_strTFName + " iCountTestcases==" + iCountTestcases + " paSs" );
         return true;
     }
     else
     {
         Console.WriteLine( s_strTFName+ s_strTFPath );
         Console.WriteLine( s_strTFName+ "FAiL" );
         Console.Error.WriteLine( s_strTFName + " iCountErrors==" + iCountErrors );
         return false;
     }
 }
Example #41
0
File: 3b.cs Project: dsj312/DSJD
//---------------------------------------------------------------------5.Ajouter
    static void Inserer(ArrayList paysInscrits, char groupe, int continent,
    string pays, string capitale, int superficie, int population)
    {
        pays = pays.ToUpper();
        pays = pays.ToUpper();

        for (int i = pays.Length; i < 34; i++) pays += " ";
        
        for (int i = capitale.Length; i < 9; i++) capitale += " ";

        WorldCup aAjouter = new WorldCup(groupe, continent, pays, capitale,
            superficie, population);

        int indice = paysInscrits.BinarySearch(aAjouter);
        if (indice < 0)
            indice = (-indice) - 1;
        paysInscrits.Insert(indice, aAjouter);
        
        Console.WriteLine("Nous avons ajouté le pays :\n {1}) {0}\n",
        aAjouter, indice);
    }
Example #42
0
 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
     ArrayList arrList = null;
     String [] strHeroes =
         {
             "Aquaman",
             "Atom",
             "Batman",
             "Black Canary",
             "Captain America",
             "Captain Atom",
             "Catwoman",
             "Cyborg",
             "Flash",
             "Green Arrow",
             "Green Lantern",
             "Hawkman",
             "Huntress",
             "Ironman",
             "Nightwing",
             "Robin",
             "SpiderMan",
             "Steel",
             "Superman",
             "Thor",
             "Wildcat",
             "Wonder Woman",
     };
     String [] strFindHeroes =
         {
             "Batman",
             "Superman",
             "SpiderMan",
             "Wonder Woman",
             "Green Lantern",
             "Flash",
             "Steel"
         };
     do
     {
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Construct ArrayList" );
         try
         {
             arrList = new ArrayList();
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
             for ( int ii = 0; ii < strHeroes.Length; ++ii )
             {
                 arrList.Add( strHeroes[ii] );
             }
             if ( arrList.Count != strHeroes.Length )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected size <"+ strHeroes.Length + "> ";
                 strInfo = strInfo + "Returned size <"+ arrList.Count + "> ";
                 Console.WriteLine( strTest+ "E_202: " + strInfo );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Use BinarySearch to find selected items" );
         try
         {
             for ( int ii = 0; ii < strFindHeroes.Length; ++ii )
             {
                 int ndx = arrList.BinarySearch( 0, arrList.Count, strFindHeroes[ii], this );
                 if ( ndx >= strHeroes.Length )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Returned index <"+ ndx + "> out of range";
                     Console.WriteLine( strTest+ "E_303: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
                 if ( strHeroes[ndx].CompareTo( strFindHeroes[ii] ) != 0 )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Expected index of hero <"+ strFindHeroes[ii] + "> ";
                     strInfo = strInfo + "Returned index of hero <"+ strHeroes[ndx] + "> ";
                     Console.WriteLine( strTest+ "E_404: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Locate item in list using null comparer" );
         try
         {
             int ndx = arrList.BinarySearch( 0, arrList.Count, "Batman", null );
             if ( ndx != 2 )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected index <2> ";
                 strInfo = strInfo + "Returned index <"+ ndx + "> ";
                 Console.WriteLine( strTest+ "E_505: " + strInfo );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10003: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Locate insertion index of new list item" );
         try
         {
             int ndx = arrList.BinarySearch( 0, arrList.Count, "Batgirl", this );
             if ( ~ndx != 2 )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected insertion index <2> ";
                 strInfo = strInfo + "Returned insertion index <"+ ~ndx + "> ";
                 Console.WriteLine( strTest+ "E_505: " + strInfo );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10004: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[] Bogus Arguments" );
         try
         {
             arrList.BinarySearch( -100, 1000, arrList.Count, this );
             Console.WriteLine( strTest+ "E_606: Expected ArgumentException" );
             ++iCountErrors;
             break;
         }
         catch (ArgumentException ex)
         {
             Console.Out.WriteLine( ex.ToString() + " caught" );
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10005: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         try
         {
             arrList.BinarySearch( -100, 1000, "Batman", this );
             Console.WriteLine( strTest+ "E_707: Expected ArgumentException" );
             ++iCountErrors;
             break;
         }
         catch (ArgumentException ex)
         {
             Console.Out.WriteLine( ex.ToString() + " caught" );
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10006: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
     }
     while ( false );
     Console.Error.Write( strName );
     Console.Error.Write( ": " );
     if ( iCountErrors == 0 )
     {
         Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
         return true;
     }
     else
     {
         System.String strFailMsg = null;
         Console.WriteLine( strTest+ strPath );
         Console.WriteLine( strTest+ "FAiL" );
         Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
         return false;
     }
 }
Example #43
0
        public void TestArrayListWrappers()
        {
            //
            // Construct array list.
            //
            ArrayList arrList = new ArrayList();

            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
            {
                arrList.Add(strHeroes[ii]);
            }

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, arrList.Count);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    arrList,
                                    ArrayList.Adapter(arrList),
                                    ArrayList.FixedSize(arrList),
                                    arrList.GetRange(0, arrList.Count),
                                    ArrayList.ReadOnly(arrList),
                                    ArrayList.Synchronized(arrList)};

            int ndx = 0;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                //
                // []  Use BinarySearch to find selected items.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strFindHeroes.Length; ++ii)
                {
                    // Locate item.
                    ndx = arrList.BinarySearch(0, arrList.Count, strFindHeroes[ii], this);
                    Assert.True(ndx >= 0);

                    // Verify item.
                    Assert.Equal(0, strHeroes[ndx].CompareTo(strFindHeroes[ii]));
                }

                //
                // []  Locate item in list using null comparer.
                //
                ndx = arrList.BinarySearch(0, arrList.Count, "Batman", null);
                Assert.Equal(2, ndx);

                //
                // []  Locate insertion index of new list item.
                //
                // Append the list.
                ndx = arrList.BinarySearch(0, arrList.Count, "Batgirl", this);
                Assert.Equal(2, ~ndx);

                //
                // []  Bogus Arguments
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, arrList.Count, this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(0, -1, "Batman", this));

                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(3, arrList.Count - 2, "Batman", this));
            }
        }
Example #44
0
 private void CompareObjects(ArrayList good, ArrayList bad, Hashtable hsh1)
 {
     DoIListTests(good, bad, hsh1);
     good.Clear();
     for(int i=0; i<100; i++)
         good.Add(i);
     if(fVerbose)
         Console.WriteLine("CopyTo()");
     Int32[] iArr1 = null;
     Int32[] iArr2 = null;
     iArr1 = new Int32[100];
     iArr2 = new Int32[100];
     good.CopyTo(iArr1);
     bad.CopyTo(iArr2);
     for(int i=0; i<100; i++)
     {
         if(iArr1[i] != iArr2[i])
             hsh1["CopyTo"] = "()";
     }
     iArr1 = new Int32[100];
     iArr2 = new Int32[100];
     good.CopyTo(0, iArr1, 0, 100);
     try
     {
         bad.CopyTo(0, iArr2, 0, 100);
         for(int i=0; i<100; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["CopyTo"] = "()";
         }
     }
     catch
     {
         hsh1["CopyTo"] = "(Int32, Array, Int32, Int32)";
     }
     iArr1 = new Int32[200];
     iArr2 = new Int32[200];
     for(int i=0; i<200; i++)
     {
         iArr1[i]=50;
         iArr2[i]=50;
     }
     good.CopyTo(50, iArr1, 100, 20);
     try
     {
         bad.CopyTo(50, iArr2, 100, 20);
         for(int i=0; i<200; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["CopyTo"] = "(Array, Int32, Int32)";
         }
     }
     catch
     {
         hsh1["CopyTo"] = "(Int32, Array, Int32, Int32)";
     }
     if(fVerbose)
         Console.WriteLine("Clone()");
     ArrayList alstClone = (ArrayList)bad.Clone();
     if(alstClone.Count != bad.Count)
         hsh1["Clone"] = "Count";
     for(int i=0; i<bad.Count; i++)
     {
         if(alstClone[i] != bad[i])
             hsh1["Clone"] = "[]";
     }
     if(fVerbose)
         Console.WriteLine("GetEnumerator()");
     IEnumerator ienm1 = null;
     IEnumerator ienm2 = null;
     ienm1 = good.GetEnumerator(0, 100);
     try
     {
         ienm2 = bad.GetEnumerator(0, 100);
         DoIEnumerableTest(ienm1, ienm2, hsh1, false);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     ienm1 = good.GetEnumerator(50, 50);
     try
     {
         ienm2 = bad.GetEnumerator(50, 50);
         DoIEnumerableTest(ienm1, ienm2, hsh1, false);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     try
     {
         bad.GetEnumerator(50, 150);
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     catch(Exception)
     {
     }
     ienm1 = good.GetEnumerator(0, 100);
     try
     {
         ienm2 = bad.GetEnumerator(0, 100);
         good.RemoveAt(0);
         DoIEnumerableTest(ienm1, ienm2, hsh1, true);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     good.Clear();
     for(int i=0; i<100; i++)
         good.Add(i);
     if(fVerbose)
         Console.WriteLine("GetRange()");
     ArrayList alst1 = good.GetRange(0, good.Count);
     try
     {
         ArrayList alst2 = bad.GetRange(0, good.Count);
         for(int i=0; i<good.Count; i++)
         {
             if(alst1[i] != alst2[i])
                 hsh1["GetRange"] = i;
         }
     }
     catch
     {
         hsh1["Range"] = "(Int32, Int32)";
     }
     if(bad.Count>0)
     {
         if(fVerbose)
             Console.WriteLine("IndexOf()");
         for(int i=0; i<good.Count; i++)
         {
             if(good.IndexOf(good[i], 0) != bad.IndexOf(good[i], 0))
             {
                 Console.WriteLine(good .Count + " " + bad.Count + " " + good[i] + " " + bad[i] + " " + good.IndexOf(good[i], 0) + " " + bad.IndexOf(good[i], 0));
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(good.IndexOf(good[i], i) != bad.IndexOf(good[i], i))
             {
                 Console.WriteLine("2" + good.IndexOf(good[i], i) + " " + bad.IndexOf(good[i], i));
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.IndexOf(good[i], i+1) != bad.IndexOf(good[i], i+1))
                 {
                     Console.WriteLine("3" + good.IndexOf(good[i], i+1) + " " + bad.IndexOf(good[i], i+1));
                     hsh1["IndexOf"] = "(Object, Int32)";
                 }
             }			
         }
         try
         {
             bad.IndexOf(1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         for(int i=0; i<good.Count; i++)
         {
             if(good.IndexOf(good[i], 0, good.Count-1) != bad.IndexOf(good[i], 0, good.Count-1))
             {
                 hsh1["IndexOf"] = "(Object, Int32, Int32)";
             }
             if(good.IndexOf(good[i], i, good.Count-i) != bad.IndexOf(good[i], i, good.Count-i))
             {
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(good.IndexOf(good[i], i, 0) != bad.IndexOf(good[i], i, 0))
             {
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.IndexOf(good[i], i+1, good.Count-(i+1)) != bad.IndexOf(good[i], i+1, good.Count-(i+1)))
                 {
                     hsh1["IndexOf"] = "(Object, Int32)";
                 }
             }
         }
         try
         {
             bad.IndexOf(1, 0, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, 0, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, bad.Count-1, bad.Count-2);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         if(fVerbose)
             Console.WriteLine("LastIndexOf(), " + good.Count + " " + bad.Count);
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i]) != bad.LastIndexOf(good[i]))
             {
                 hsh1["LastIndexOf"] = "(Object)";
             }
             if(good.LastIndexOf(i+1000) != bad.LastIndexOf(i+1000))
             {
                 hsh1["LastIndexOf"] = "(Object)";
             }
         }
         try
         {
             bad.LastIndexOf(null);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         if(fVerbose)
             Console.WriteLine("LastIndexOf(Object, Int32)");
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i], good.Count-1) != bad.LastIndexOf(good[i], good.Count-1))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], 0) != bad.LastIndexOf(good[i], 0))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], i) != bad.LastIndexOf(good[i], i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.LastIndexOf(good[i], i+1) != bad.LastIndexOf(good[i], i+1))
                 {
                     hsh1["LastIndexOf"] = "(Object, Int32)";
                 }
             }			
         }
         try
         {
             bad.LastIndexOf(1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         try
         {
             bad.LastIndexOf(1, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i], good.Count-1, 0) != bad.LastIndexOf(good[i], good.Count-1, 0))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32, Int32)";
             }
             if(good.LastIndexOf(good[i], good.Count-1, i) != bad.LastIndexOf(good[i], good.Count-1, i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], i, i) != bad.LastIndexOf(good[i], i, i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.LastIndexOf(good[i], good.Count-1, i+1) != bad.LastIndexOf(good[i], good.Count-1, i+1))
                 {
                     hsh1["LastIndexOf"] = "(Object, Int32)";
                 }
             }
         }
         try
         {
             bad.LastIndexOf(1, 1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         try
         {
             bad.LastIndexOf(1, bad.Count-2, bad.Count-1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
     }
     if(fVerbose)
         Console.WriteLine("ReadOnly()");
     ArrayList alst3 = ArrayList.ReadOnly(bad);
     if(!alst3.IsReadOnly)
         hsh1["ReadOnly"] = "Not";
     IList ilst1 = ArrayList.ReadOnly((IList)bad);
     if(!ilst1.IsReadOnly)
         hsh1["ReadOnly"] = "Not";
     if(fVerbose)
         Console.WriteLine("Synchronized()");
     alst3 = ArrayList.Synchronized(bad);
     if(!alst3.IsSynchronized)
         hsh1["Synchronized"] = "Not";
     ilst1 = ArrayList.Synchronized((IList)bad);
     if(!ilst1.IsSynchronized)
         hsh1["Synchronized"] = "Not";
     if(good.Count == bad.Count)
     {
         if(fVerbose)
             Console.WriteLine("ToArray()");
         Object[] oArr1 = good.ToArray();
         Object[] oArr2 = bad.ToArray();
         for(int i=0; i<good.Count; i++)
         {
             if((Int32)oArr1[i] != (Int32)oArr2[i])
                 hsh1["ToArray"] = "()";
         }
         iArr1 = (Int32[])good.ToArray(typeof(Int32));
         iArr2 = (Int32[])bad.ToArray(typeof(Int32));
         for(int i=0; i<good.Count; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["ToArray"] = "(Type)";
         }
     }
     if(fVerbose)
         Console.WriteLine("Capacity()");
     if(good.Capacity != bad.Capacity)
     {
         hsh1["Capacity"] = "get";
     }
     if(!hsh1.ContainsKey("IsReadOnly"))
     {
         good.Clear();
         for(int i=100; i>0; i--)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("Sort() & BinarySearch()");
         bad.Sort();
         for(int i=0; i<bad.Count-1; i++)
         {
             if((Int32)bad[i] > (Int32)bad[i+1])
                 hsh1["Sort"] = "()";
         }			
         for(int i=0; i<bad.Count; i++)
         {
             if(bad.BinarySearch(bad[i]) != i)
                 hsh1["BinarySearch"] = "(Object)";
         }
         bad.Reverse();
         if(bad.Count>0)
         {
             for(int i=0; i<99; i++)
             {
                 if((Int32)bad[i] < (Int32)bad[i+1])
                     hsh1["Reverse"] = "()";
             }
             good.Clear();
             for(int i=100; i>0; i--)
                 good.Add(i.ToString());
         }
         good.Clear();
         for(int i=90; i>64; i--)
             good.Add(((Char)i).ToString());
         try
         {
             bad.Sort(new CaseInsensitiveComparer());
             if(bad.Count>0)
             {
                 for(int i=0; i<(bad.Count-1); i++)
                 {
                     if(((String)bad[i]).CompareTo(((String)bad[i+1])) >= 0)
                         hsh1["Sort"] = "(IComparer)";
                 }			
                 for(int i=0; i<bad.Count; i++)
                 {
                     if(bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                         hsh1["BinarySearch"] = "(Object, IComparer)";
                 }
             }
             bad.Reverse();			
             good.Clear();
             for(int i=65; i<91; i++)
                 good.Add(((Char)i).ToString());
             if(bad.Count>0)
             {
                 for(int i=0; i<good.Count; i++)
                 {
                     if(bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                         hsh1["BinarySearch"] = "(Int32, Int32, Object, IComparer)";
                 }
             }
         }
         catch(Exception)
         {
         }
         good.Clear();
         for(int i=0; i<100; i++)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("SetRange()");
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         try
         {
             bad.SetRange(0, que);
         }
         catch(Exception ex)
         {
             hsh1["SetRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         for(int i=bad.Count; i<bad.Count; i++)
         {
             if((Int32)bad[i] != (i + 5000))
             {
                 hsh1["SetRange"] = i;
             }
         }
     }
     else
     {
         good.Clear();
         for(int i=100; i>0; i--)
             good.Add(i);
         try
         {
             bad.Sort();
             hsh1["Sort"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             bad.Reverse();
             hsh1["Reverse"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Reverse"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         try
         {
             bad.Sort(new CaseInsensitiveComparer());
             hsh1["Sort"] = "Copy - Icomparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             bad.Sort(0, 0, new CaseInsensitiveComparer());
             hsh1["Sort"] = "Copy - Int32, Int32, IComparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(bad[i]) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "(Object)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         good.Clear();
         for(int i=0; i<100; i++)
             good.Add(i);
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         try
         {
             bad.SetRange(0, que);
             hsh1["Sort"] = "Copy - Int32, Int32, IComparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
     }
     if(!hsh1.ContainsKey("IsReadOnly") && !hsh1.ContainsKey("Fixed"))
     {
         good.Clear();
         for(int i=0; i<100; i++)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("InsertRange()");
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         bad.InsertRange(0, que);
         for(int i=0; i<100; i++)
         {
             if((Int32)bad[i] != i + 5000)
             {
                 hsh1["InsertRange"] = i;
             }
         }
         if(fVerbose)
             Console.WriteLine("AddRange()");
         que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+2222);
         bad.AddRange(que);
         for(int i=bad.Count-100; i<bad.Count; i++)
         {
             if((Int32)bad[i] != (i-(bad.Count-100)) + 2222)
             {
                 hsh1["AddRange"] = i + " " + (Int32)bad[i];
             }
         }
         if(fVerbose)
             Console.WriteLine("RemoveRange()");
         bad.RemoveRange(0, que.Count);
         for(int i=0; i<100; i++)
         {
             if((Int32)bad[i] != i)
             {
                 hsh1["RemoveRange"] = i + " " + (Int32)bad[i];
             }
         }
         try
         {
             bad.Capacity = bad.Capacity*2;
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         try
         {
             bad.Capacity = -1;
             hsh1["Capacity"] = "No_Exception_Thrown, -1";
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         Int32 iMakeSureThisDoesNotCause = 0;
         while(bad.Capacity == bad.Count)
         {
             if(iMakeSureThisDoesNotCause++>100)
                 break;
             bad.Add(bad.Count);
         }
         if(iMakeSureThisDoesNotCause>100)
             hsh1["TrimToSize"] = "Monekeyed, " + bad.Count + " " + bad.Capacity;
         try
         {
             bad.TrimToSize();
             if(bad.Capacity != bad.Count)
             {
                 hsh1["TrimToSize"] = "Problems baby";
             }
         }
         catch(Exception ex)
         {
             hsh1["TrimToSize"] = ex.GetType().Name;
         }
     }
     else
     {
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         try
         {
             bad.AddRange(que);
             hsh1["AddRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["AddRange"] = "Copy_ExceptionType";
         }
         try
         {
             bad.InsertRange(0, que);
             hsh1["InsertRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["InsertRange"] = "Copy_ExceptionType";
         }
         good.Clear();
         for(int i=0; i<10; i++)
             good.Add(i);
         try
         {
             bad.RemoveRange(0, 10);
             hsh1["RemoveRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["RemoveRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         try
         {
             bad.Capacity = bad.Capacity*2;
             hsh1["Capacity"] = "No_Exception_Thrown, bad.Capacity*2";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         try
         {
             bad.TrimToSize();
             hsh1["TrimToSize"] = "No_Exception_Thrown";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["TrimToSize"] = ex.GetType().Name;
         }
     }
 }