Example #1
0
File: Matrix.cs Project: ikvm/test
 public virtual void addCols(int index, int count, int beginRow, int endRow, bool alignColHead)
 {
     if (((index < 0) || (index > this.int_4)) || (count < 0))
     {
         throw new SystemException();
     }
     if (count != 0)
     {
         ArrayList list2 = this.method_1(count);
         for (int i = 0; i < this.int_3; i++)
         {
             ArrayList list = (ArrayList)this.arrayList_0[i];
             if ((i >= beginRow) && (i <= endRow))
             {
                 list.InsertRange(index, list2);
             }
             else if (i != 0)
             {
                 list.AddRange(list2);
             }
             else if (!alignColHead)
             {
                 list.AddRange(list2);
             }
             else
             {
                 list.InsertRange(index, list2);
             }
         }
         this.int_4 += count;
     }
 }
        private ArrayList MultiClassCombination(string multiClass)
        {
            multiClass = Common.SortMutiClass(multiClass);
            string[]  className           = multiClass.Split(' ');
            ArrayList result              = new ArrayList();
            ArrayList concate             = new ArrayList();
            ArrayList resultCssClassOrder = new ArrayList();
            int       len = className.Length;

            if (len == 1)
            {
                resultCssClassOrder.AddRange(className);
                return(resultCssClassOrder);
            }
            result.AddRange(className);
            int searchFrom;
            int searchTo = 0;

            for (int i = 0; i < len - 1; i++)
            {
                searchFrom = searchTo + 1;
                searchTo   = result.Count - 1;
                concate    = MultiClassConcate(className, result, len, searchFrom, searchTo);
                result.AddRange(concate);
                resultCssClassOrder.InsertRange(0, OrderByCss(concate));
            }
            concate.Clear();
            concate.AddRange(className);
            resultCssClassOrder.AddRange(OrderByCss(concate));

            return(resultCssClassOrder);
        }
Example #3
0
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList();

            list.Add(true);
            list.Add("hello world");//可以重复包含
            list.Add("hello world");
            list.Add("Felix");
            list.Add(6666.68m);
            list.Add(123);
            list.AddRange(new int[] { 1, 23, 4, 5, 67, 78 });
            list.Insert(0, "first");         //从下标插入后面的后移
            list.InsertRange(0, new string[] { "fdjf", "jdkfdk" });
            bool flag = list.Contains(true); //是否包含

            Console.WriteLine("集合是否包含true:" + flag);
            //list.Remove("Felix");//通过元素直接删除
            //list.RemoveAt(0);//通过下标删除
            //list.RemoveRange(0,2);//通过下标移除一定范围的元素(index,.count)
            //for(var i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}
            //Console.WriteLine("对集合进行sort操作");
            ////list.Sort();
            //list.Reverse();
            for (var i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }
            Console.ReadKey();
        }
Example #4
0
        // 1.基本使用, ArrayList的创建 添加元素
        public static void ArrayListTest1()
        {
            ArrayList list = new ArrayList();

            list.Add("小王");
            list.Add(9);
            list.Add('A');

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }

            list.AddRange(new string[] { "老王", "隔壁" });
            // 指定位置插入
            list.Insert(0, "小东");
            list.InsertRange(2, new int[] { 1, 5, 65 });
            // 移除
            Console.WriteLine("------------------------操作后打印------------------------");
            list.Remove("小王");

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }

            if (list.Contains("小东"))
            {
                Console.WriteLine("包含小东这个元素");
            }
        }
Example #5
0
        static void Main()
        {
            ArrayList names = new ArrayList();

            names.Add("Michael Erick");
            names.Add("Jacqueline");
            names.Add("Roy Eduard");
            names.Add("Joni Mae");
            names.Add("Omega");
            Console.WriteLine("The original list of names are: ");
            foreach (object name in names)
            {
                Console.WriteLine(name);
            }
            Console.WriteLine();
            String[]  newNames  = new string[] { "Jian Carlo", "August" };
            ArrayList moreNames = new ArrayList();

            moreNames.Add("Crizzle");
            moreNames.Add("Juvy");
            moreNames.Add("Vanessa");
            moreNames.Add("Clayton");
            moreNames.Add("Alisa");
            names.InsertRange(0, newNames);
            names.AddRange(moreNames);
            Console.WriteLine("The new list of names are: ");
            foreach (object name in names)
            {
                Console.WriteLine(name);
            }
            Console.Read();
        }
Example #6
0
        private void RemoveNodeAndPromoteChildren(ArrayList nodes, int indexToRemove)
        {
            ProgressNode item = (ProgressNode)nodes[indexToRemove];

            if (item != null)
            {
                if (item.Children == null)
                {
                    this.RemoveNode(nodes, indexToRemove);
                    return;
                }
                else
                {
                    for (int i = 0; i < item.Children.Count; i++)
                    {
                        ((ProgressNode)item.Children[i]).ParentActivityId = -1;
                    }
                    nodes.RemoveAt(indexToRemove);
                    PendingProgress pendingProgress = this;
                    pendingProgress.nodeCount = pendingProgress.nodeCount - 1;
                    nodes.InsertRange(indexToRemove, item.Children);
                    return;
                }
            }
            else
            {
                return;
            }
        }
        static void Main(string[] args)
        {
            var myList = new ArrayList();

            string[] anArray = new string[] { "Hello", "Word" };
            myList.AddRange(anArray);

            foreach (var item in myList)
            {
                Console.WriteLine(item.ToString());
            }
            Console.ReadLine();

            myList.Insert(1, "OmGTU");

            foreach (var item in myList)
            {
                Console.WriteLine(item.ToString());
            }
            Console.ReadLine();

            var moreString = new[] { "goodnight", "see ya" };

            myList.InsertRange(1, moreString);

            foreach (var item in myList)
            {
                Console.WriteLine(item.ToString());
            }
            Console.ReadLine();
        }
Example #8
0
        public bool Remove(string startingPath)
        {
            ProgressDialog scanFilesProgress = new ProgressDialog("Scanning local data", "Please wait while MOG scans the local directories...", LocateNonMogAssets_Worker, startingPath, false);

            if (scanFilesProgress.ShowDialog(MogMainForm.MainApp) == DialogResult.OK)
            {
                // Initialize our list of removeFiles to mKnownSyncFiles which was populated with LocateNonMogAssets_Worker
                ArrayList removeFiles = new ArrayList(mKnownSyncFiles.Values);

                ArrayList rogueFiles = scanFilesProgress.WorkerResult as ArrayList;
                if (rogueFiles.Count > 0)
                {
                    if (guiConfirmDialog.MessageBoxDialog("Remove non-Mog files", "Are you sure you want to remove these files?", startingPath, rogueFiles, null, null, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        // Insert the files that the user has flagged for removal
                        removeFiles.InsertRange(0, guiConfirmDialog.SelectedItems);
                    }
                }

                // Check if we have something to remove?
                if (removeFiles.Count > 0)
                {
                    ProgressDialog progress = new ProgressDialog("Removing local data", "Please wait while MOG removes these files.", Clean_Worker, removeFiles, true);
                    progress.ShowDialog(MogMainForm.MainApp);
                    return(true);
                }
            }

            return(false);
        }
Example #9
0
        private static void basicTest()
        {
            ArrayList names = new ArrayList();

            names.Add("Mike");
            names.Add("Beata");
            names.Add("Raymond");
            names.Add("Bernica");
            names.Add("jenneifer");
            Console.WriteLine("The original list of names: ");
            foreach (Object name in names)
            {
                Console.WriteLine(name);
            }
            Console.WriteLine();
            string[]  newNames = new string[] { "David", "Michael" };
            ArrayList moreName = new ArrayList();

            moreName.Add("Terrill");
            moreName.Add("Donnie");
            moreName.Add("Mayo");
            moreName.Add("Clayton");
            moreName.Add("Akisa");
            names.InsertRange(0, newNames); //插入到指定索引处
            names.AddRange(moreName);       //添加到末尾
            Console.WriteLine("The new lsit of names: ");
            foreach (object name in names)
            {
                Console.WriteLine(name);
            }
        }
        public double[] Normalize(object[] row)
        {
            ArrayList list = new ArrayList(NumSlots);

            int slot = 0;

            for (int j = 0; j < NumColumns; ++j)
            {
                var index = ColumnHelperIndices[j];
                if (index.Key)
                {
                    var helper = HelpersMultiple[index.Value];
                    var objs   = helper.Normalize(row[j]);
                    list.InsertRange(slot, objs);
                    slot += helper.NumSlots;
                }
                else
                {
                    list[slot] = HelpersSingle[index.Value].Normalize(row[j]);
                    ++slot;
                }
            }

            return(list.Cast <double>().ToArray());
        }
Example #11
0
        private char[] Read_byte_int_int(SerialPort com)
        {
            ArrayList receivedBytes = new ArrayList();

            byte[] buffer         = new byte[DEFAULT_READ_BYTE_ARRAY_SIZE];
            int    totalBytesRead = 0;

            while (true)
            {
                int numBytes;
                try
                {
                    numBytes = com.Read(buffer, 0, buffer.Length);
                }
                catch (TimeoutException)
                {
                    break;
                }

                receivedBytes.InsertRange(totalBytesRead, buffer);
                totalBytesRead += numBytes;
            }

            if (totalBytesRead < receivedBytes.Count)
            {
                receivedBytes.RemoveRange(totalBytesRead, receivedBytes.Count - totalBytesRead);
            }

            return(com.Encoding.GetChars((byte[])receivedBytes.ToArray(typeof(byte))));
        }
Example #12
0
        void AddDefaultResponseFile(ref ArrayList arglist)
        {
            ArrayList result = new ArrayList();

            foreach (string arg in arglist)
            {
                if (arg == "-noconfig")
                {
                    _noConfig = true;
                }
                else
                {
                    result.Add(arg);
                }
            }
            if (!_noConfig)
            {
                string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "booc.rsp");
                if (File.Exists(file))
                {
                    result.InsertRange(0, LoadResponseFile(file));
                }
            }
            arglist = result;
        }
Example #13
0
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList();

            //添加单个元素
            list.Add(true);
            list.Add(1);
            list.Add("张三");
            list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 });
            list.AddRange(list);
            //list.Clear();//清空所有元素
            list.Remove(true);                                //删除单个元素,但只删除匹配的第一个元素
            list.RemoveAt(0);                                 //根据下标删除元素
            list.RemoveRange(0, 3);                           //根据下标去移除一定范围的元素
            //list.Sort();//升序排列,但是元素无法排序时抛异常
            list.Insert(1, "插入的");                            //在指定的位置插入元素
            list.InsertRange(3, new string[] { "张三", "李四" }); //在指定的位置插入集合
            bool b = list.Contains(1);                        //确认是否包含某个指定的元素

            list.Add(b);
            if (!list.Contains("闫世伟"))
            {
                list.Add("闫世伟");
            }
            else
            {
                Console.WriteLine("已经有了");
            }
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }
            Console.ReadKey();
        }
Example #14
0
        //我们将一个对象输出到控制台,默认情况下,打印的就是这个对象所在类的命名空间

        static void Main(string[] args)
        {
            //创建了一个集合对象
            ArrayList list = new ArrayList();

            //集合:很多数据的一个集合
            //数组:长度不可变,类型单一
            //集合的好处:长度可以任意改变,类型随便

            list.Add(1);//添加单个元素
            list.Add(true);
            int[] vs = new int[] { 1, 2, 3 };
            list.AddRange(vs);       //把集合的每个元素单独添加进去
            list.RemoveAt(0);        //根据下标去删除元素
            list.Remove(true);       //根据元素内容删除元素
            list.RemoveRange(0, 3);  //根据下标移除一定范围内的元素
            list.Sort();             //升序排列(该集合内的类型要差不多)
            list.Reverse();          //将集合内的元素反转
            list.Insert(0, "插入的");   //在指定位置插入元素
            list.InsertRange(0, vs); //在指定位置插入一个集合
            list.Contains(0);        //判断是否包含某个指定元素

            //count表示这个元素中实际包含的元素的个数
            //capcity表示这个集合中可以包含的元素的个数
            //每次集合中实际包含的元素个数count超过了可以包含元素的个数capcity的时候集合就会向内存申请多开辟一倍的空间,来保证集合的长度一直够用


            Console.WriteLine(list.Count);
            Console.WriteLine(list.Capacity);
            Console.ReadKey();
        }
Example #15
0
        private char[] Read_char_int_int(SerialPort com)
        {
            ArrayList receivedChars = new ArrayList();

            char[] buffer         = new char[DEFAULT_READ_CHAR_ARRAY_SIZE];
            int    totalCharsRead = 0;
            int    numChars;

            while (true)
            {
                try
                {
                    numChars = com.Read(buffer, 0, buffer.Length);
                }
                catch (TimeoutException)
                {
                    break;
                }

                receivedChars.InsertRange(totalCharsRead, buffer);
                totalCharsRead += numChars;
            }

            if (totalCharsRead < receivedChars.Count)
            {
                receivedChars.RemoveRange(totalCharsRead, receivedChars.Count - totalCharsRead);
            }

            return((char[])receivedChars.ToArray(typeof(char)));
        }
Example #16
0
        public void TestLargeCapacity()
        {
            //
            //  []  Add a range large enough to increase the capacity of the arrayList by more than a factor of two
            //
            ArrayList arrInsert = new ArrayList();

            for (int i = 0; i < 128; i++)
            {
                arrInsert.Add(-i);
            }

            ArrayList arrList = new ArrayList();

            ArrayList[] arrayListTypes1 =
            {
                (ArrayList)arrList.Clone(),
                (ArrayList)ArrayList.Adapter(arrList).Clone(),
                (ArrayList)arrList.GetRange(0,                arrList.Count).Clone(),
                (ArrayList)ArrayList.Synchronized(arrList).Clone()
            };

            foreach (ArrayList arrayListType in arrayListTypes1)
            {
                arrList = arrayListType;

                arrList.InsertRange(0, arrInsert);

                for (int i = 0; i < arrInsert.Count; i++)
                {
                    Assert.Equal(-i, (int)arrList[i]);
                }
            }
        }
Example #17
0
        /// <summary>
        /// Returns an array of absolute file paths of all of the files in the project where the
        /// BuildAction = Compile.
        /// </summary>
        /// <returns>.</returns>
        private string[] GetAllCompileBuildActionSourceFiles()
        {
            StringCollection sourceFiles    = new StringCollection();
            ArrayList        nodesToProcess = new ArrayList(this.Project.RootNode.Children);

            while (nodesToProcess.Count > 0)
            {
                Node       node       = (Node)nodesToProcess[0];
                FolderNode folderNode = node as FolderNode;
                string     sourceFile = node.AbsolutePath;

                // Remove the node that we are processing.
                nodesToProcess.RemoveAt(0);

                // If we have a sub-folder (that's not the library folder), then add all of its children to the process array.
                if (folderNode != null)
                {
                    if (!(folderNode is ReferenceFolderNode))
                    {
                        nodesToProcess.InsertRange(0, folderNode.Children);
                    }
                }
                else if (node.BuildAction == BuildAction.Compile)
                {
                    sourceFiles.Add(sourceFile);
                }
            }

            return(ToStringArray(sourceFiles));
        }
Example #18
0
        static void Main(string[] args)
        {
            ArrayList mylist = new ArrayList();

            mylist.Add("merhaba"); //liste sonuna elamanı ekler
            mylist.Add(5);
            mylist.Add(true);
            mylist.Add(5.4);
            mylist.Insert(2, 5);      // Belirli bir indexe eleman ekler

            mylist.Remove("merhaba"); // belirtilen eleman silinir
            mylist.RemoveAt(1);       // Verilen index numarasındaki elaman silinir
            mylist.RemoveRange(0, 2); //Verilen index numaraları arasındaki elamanlar silinir.

            ArrayList mylist2 = new ArrayList()
            {
                "merhaba", 5, true, 5.4
            };

            mylist.InsertRange(1, mylist2); // Verilen index numarasından sonraya liste eklenebilir.

            foreach (var item in mylist)
            {
                Console.WriteLine(item);
            }

            ArrayList sayilar = new ArrayList()
            {
                10, 5, 12, 4, 2, 7, 2
            };

            sayilar.Sort(); // Veri tipleri aynı ise sıralanır.
        }
Example #19
0
        // [WIP] recombine puzzlepieces to get rid of borders
        public PuzzlePiece Combine(PuzzlePiece pp)
        {
            ArrayList list = new ArrayList();
            int       i    = -1;

            ArrayList points1 = new ArrayList(this.PointList);
            ArrayList points2 = new ArrayList(pp.PointList);

            list.AddRange(points1);
            foreach (Point point in points2)
            {
                i = list.IndexOf(point);
                if (i != -1)
                {
                    break;
                }
            }
            list.InsertRange(i, points2);

            PuzzlePiece newPp = new PuzzlePiece();

            newPp.Location = this.Location;
            newPp.Image    = this.Image;
            newPp.points   = (Point[])list.ToArray(typeof(Point));
            return(newPp);
        }
Example #20
0
        static void Main(string[] args)
        {
            ArrayList list = new ArrayList();

            list.Add(1);
            //list.Add(3.14);
            //list.Add("张三");
            //list.Add('男');
            //list.Add(5000m);
            list.Add(true);
            list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            list.AddRange(list);
            //list.Clear();
            //list.Remove(true);
            //list.RemoveAt(1);
            //list.RemoveRange(1, 2);
            list.Insert(2, "插入的");
            list.InsertRange(3, new string[] { "张三", "李四" });

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //ArrayList arryList2 = new ArrayList();
            //arryList2.Add(100);
            //arryList2.Add(200);
            ArrayList arryList1 = new ArrayList();

            Console.WriteLine(arryList1.Add(100));
            arryList1.Add(200);
            Console.WriteLine(arryList1.Capacity);
            Console.WriteLine(arryList1.IsFixedSize);
            Console.WriteLine(arryList1.IsReadOnly);
            ArrayList arryList2 = new ArrayList();

            arryList2.Add(10);
            arryList2.Add(20);
            arryList2.Add(30);

            arryList2.InsertRange(2, arryList1);

            foreach (var item in arryList2)
            {
                Console.WriteLine(item);
            }

            Console.ReadKey();
        }
Example #22
0
        //This function prints the trie depth first
        public void PrintDepthFirst()
        {
            ArrayList toVisit = new ArrayList(root.Children);
            ArrayList Visited = new ArrayList();
            ArrayList AddList = new ArrayList();

            Console.WriteLine("#########");

            while (toVisit.Count != 0)
            {
                ParsedTreeNode node = (ParsedTreeNode)toVisit[0];
                Console.WriteLine(node);
                if (node.IsLeaf() == false)
                {
                    foreach (ParsedTreeNode toAdd in node.Children)
                    {
                        if (!Visited.Contains(toAdd))
                        {
                            AddList.Add(toAdd);
                        }
                    }
                }
                toVisit.Remove(node);
                toVisit.InsertRange(0, AddList);
                Visited.Add(node);
                AddList.Clear();
            }

            Console.WriteLine("#########");
        }
Example #23
0
        private void btpaso_Click(object sender, EventArgs e)
        {
            AcceptButton   = btpaso;
            btpaso.Enabled = false;
            pasos++;
            ArrayList comibles = new ArrayList();

            comibles = (ArrayList)mimanager.quesos.Clone();

            comibles.InsertRange(comibles.Count, mimanager.animales);
            for (int i = 0; i < mimanager.animales.Count; i++)
            {
                ((Animal)mimanager.animales[i]).Mover();
                ((Animal)mimanager.animales[i]).Comer(comibles);
            }

            mimanager.CheckAgua();
            mimanager.checkRatones();
            mimanager.CheckMuerte();


            CargarLista();
            Actualizar();
            btpaso.Enabled = true;
        }
Example #24
0
        static void Main(string[] args)
        {
            ArrayList List = new ArrayList();

            List.Add(1);                                   //集合中放入int类型
            List.Add(3.14);                                //集合中放入double 类型
            List.Add("this is C#");                        //集合中放入字符串
            List.AddRange(new int[] { 1, 2, 3, 4, 5 });    //集合中放入数组
            List.Add(List);                                //输出自己的命名空间
            List.Remove(3.14);                             //移除3.14这个元素
            List.RemoveAt(0);                              //移除下标为0的元素
            List.RemoveRange(0, 3);                        //移除下标为 0 - 3 的所有元素
            //List.Sort();    //排序,元素类型差不多才行,否则抛异常
            List.Reverse();                                //反转List
            List.Insert(0, "hello world");                 //在下标为0的元素前插入一个元素"hello world"
            List.InsertRange(1, new int[] { 1, 2, 3, 4 }); //在下标1的元素前插入数组
            bool Judege = List.Contains("3.14");           //判断是否包含3.14

            if (Judege == true)
            {
                List[1] = 9.99; //如果有3.14则替换为9.99
            }
            else
            {
                List[1] = 3.14;
            }
            for (int i = 0; i < List.Count; i++)
            {
                Console.WriteLine(List[i]); //依次输出集合中的元素
            }
            List.Clear();
        }
Example #25
0
        private void LoadFilters()
        {
            filterListBox.Enabled = false;
            var filters        = new ArrayList();
            var aforgeAssembly = typeof(IFilter).Assembly;
            var filterTypes    = aforgeAssembly.GetTypes().Where(type => !type.IsAbstract &&
                                                                 type.GetConstructor(Type.EmptyTypes) != null &&
                                                                 type.GetInterfaces().Contains(typeof(IFilter)));

            filterTypes.ToList().ForEach(type =>
            {
                var name   = type.Name;
                var filter = Activator.CreateInstance(type);
                filters.Add(new ListBoxItem(name, filter));
            });
            filters.Sort();

            var customFilters = new ArrayList();

            filterTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetInterfaces().Contains(typeof(IFilter)));
            filterTypes.ToList().ForEach(type =>
            {
                var name   = type.Name;
                var filter = Activator.CreateInstance(type);
                customFilters.Add(new ListBoxItem(name, filter));
            });
            filters.InsertRange(0, customFilters);

            foreach (var filter in filters)
            {
                filterListBox.Items.Add(filter);
            }
        }
Example #26
0
        static void Main(string[] args)
        {
            int[]     arr  = new int[] { 22, 8, 51, 6, 5, 33 };
            ArrayList list = new ArrayList(arr);

            Console.WriteLine("原集合");
            foreach (int item in list)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            #region  方法一
            //for (int i = 1; i < 5; i++)
            //{
            //    list.Add(i + arr.Length);
            //}
            //Console.WriteLine("Add方法");
            //foreach (int item in list)
            //{
            //    Console.Write(item + " ");
            //}
            //Console.WriteLine();
            //list.Insert(6, 6);
            //Console.WriteLine("Insert方法");
            //foreach (int item in list)
            //{
            //    Console.Write(item + " ");
            //}
            //Console.WriteLine();
            #endregion

            int[] arr2 = new int[] { 47, 9, 15, 7, 10 };
            list.InsertRange(6, arr2);


            bool b = list.Contains(55);
            if (!list.Contains(55))
            {
                list.Add(55);
            }
            else
            {
                Console.WriteLine("55已存在");
            }
            list.Sort();
            list.Reverse();

            list.Clear();
            foreach (int item in list)
            {
                Console.Write(item + " ");
            }

            int n1 = list.Count;    //表示这个集合中实际包含的元素的个数
            int n2 = list.Capacity; //表示这个集合中可以包含的元素的个数

            Console.WriteLine();
            Console.ReadKey();
        }
Example #27
0
        /// <summary>
        /// Move the given collection of model objects so that they become the siblings of the target.
        /// </summary>
        /// <param name="targetTree"></param>
        /// <param name="sourceTree"></param>
        /// <param name="target"></param>
        /// <param name="toMove"></param>
        /// <param name="siblingOffset">0 indicates that the siblings should appear before the target,
        /// 1 indicates that the siblings should appear after the target</param>
        private void MoveObjectsToSibling(TreeListView targetTree, TreeListView sourceTree, ModelWithChildren target, IList toMove, int siblingOffset)
        {
            // There are lots of things to get right here:
            // - sourceTree and targetTree may be the same
            // - target may be a root (which means that all moved objects will also become roots)
            // - one or more moved objects may be roots (which means the roots of the sourceTree will change)

            ArrayList sourceRoots        = sourceTree.Roots as ArrayList;
            ArrayList targetRoots        = targetTree == sourceTree ? sourceRoots : targetTree.Roots as ArrayList;
            bool      sourceRootsChanged = false;
            bool      targetRootsChanged = false;

            // We want to make the moved objects to be siblings of the target. So, we have to
            // remove the moved objects from their old parent and give them the same parent as the target.
            // If the target is a root, then the moved objects have to become roots too.
            foreach (ModelWithChildren x in toMove)
            {
                if (x.Parent == null)
                {
                    sourceRootsChanged = true;
                    sourceRoots.Remove(x);
                }
                else
                {
                    x.Parent.Children.Remove(x);
                }
                x.Parent = target.Parent;
            }

            // Now add to the moved objects to children of their parent (or to the roots collection
            // if the target is a root)
            if (target.Parent == null)
            {
                targetRootsChanged = true;
                targetRoots.InsertRange(targetRoots.IndexOf(target) + siblingOffset, toMove);
            }
            else
            {
                target.Parent.Children.InsertRange(target.Parent.Children.IndexOf(target) + siblingOffset, toMove.Cast <ModelWithChildren>());
            }
            if (targetTree == sourceTree)
            {
                if (sourceRootsChanged || targetRootsChanged)
                {
                    sourceTree.Roots = sourceRoots;
                }
            }
            else
            {
                if (sourceRootsChanged)
                {
                    sourceTree.Roots = sourceRoots;
                }
                if (targetRootsChanged)
                {
                    targetTree.Roots = targetRoots;
                }
            }
        }
Example #28
0
        private void saveObjTrickDataToFileContent(ObjectTrick objectTrick)
        {
            int startInd = objectTrick.startIndex;
            int endInd   = objectTrick.endIndex;

            fileContent.RemoveRange(startInd, objectTrick.data.Count);
            fileContent.InsertRange(startInd, objectTrick.data);
        }
Example #29
0
        private void saveTextureTrickDataToFileContent(TextureTrick textureTrick)
        {
            int startInd = textureTrick.startIndex;
            int endInd   = textureTrick.endIndex;

            fileContent.RemoveRange(startInd, textureTrick.data.Count);
            fileContent.InsertRange(startInd, textureTrick.data);
        }
        public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
        {
            double    maleConstraint = random.NextDouble();
            int       maleCount      = (int)Math.Ceiling(maleGenes.Count * maleConstraint);
            int       femaleCount    = (int)Math.Floor(femaleGenes.Count * (1 - maleConstraint));
            ArrayList child          = new ArrayList(maleCount + femaleCount);

            child.InsertRange(0, maleGenes.GetRange(0, maleCount));
            child.InsertRange(maleCount, femaleGenes.GetRange(femaleGenes.Count - femaleCount, femaleCount));

            for (int i = 0; i < child.Count; i++)
            {
                child[i] = (child[i] as IGene).Clone();
            }

            return(child);
        }
Example #31
0
 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
     ArrayList arrList = null;
     ArrayList arrInsert = null;
     int ii = 0;
     int start = 3;
     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 [] strInsert =
         {
             "Dr. Fate",
             "Dr. Light",
             "Dr. Manhattan",
             "Hardware",
             "Hawkeye",
             "Icon",
             "Spawn",
             "Spectre",
             "Supergirl",
     };
     String [] strResult =
         {
             "Aquaman",
             "Atom",
             "Batman",
             "Dr. Fate",
             "Dr. Light",
             "Dr. Manhattan",
             "Hardware",
             "Hawkeye",
             "Icon",
             "Spawn",
             "Spectre",
             "Supergirl",
             "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",
     };
     do
     {
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Construct ArrayList" );
         try
         {
             arrList = new ArrayList( (ICollection) strHeroes );
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Construct insert array list" );
         try
         {
             arrInsert = new ArrayList( (ICollection) strInsert );
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_202: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Insert collection into array list" );
         try
         {
             arrList.InsertRange( start, arrInsert );
             for ( ii = 0; ii < strResult.Length; ++ii )
             {
                 if ( strResult[ii].CompareTo( (String)arrList[ii] ) != 0 )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Expected Hero <"+ strResult[ii] + "> ";
                     strInfo = strInfo + "Returned Hero <"+ (String)arrList[ii] + "> ";
                     Console.WriteLine( strTest+ "E_303: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10003: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Attempt bogus InsertRange using negative index" );
         try
         {
             arrList.InsertRange( -1000, arrInsert );
             Console.WriteLine( strTest+ "E_404: Expected ArgumentException" );
             ++iCountErrors;
             break;
         }
         catch (ArgumentException)
         {
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10004: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Attempt bogus InsertRange using out of range index" );
         try
         {
             arrList.InsertRange( 1000, arrInsert );
             Console.WriteLine( strTest+ "E_505: Expected ArgumentException" );
             ++iCountErrors;
             break;
         }
         catch (ArgumentException)
         {
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10005: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Attempt insertion of null collection" );
         try
         {
             arrInsert = new ArrayList( (ICollection) strInsert );
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_606: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
             arrList.InsertRange( start, null );
             Console.WriteLine( strTest+ "E_707: Expected ArgumentException" );
             ++iCountErrors;
             break;
         }
         catch (ArgumentException)
         {
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10006: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         arrList = new ArrayList();
         Queue que = new Queue();
         arrList.InsertRange(0, que);
         if(arrList.Count != 0)
         {
             iCountErrors++;
             Console.WriteLine("Err_742sf! incorrect value returned");
         }
     }
     while ( false );
     Console.Error.Write( strName );
     Console.Error.Write( ": " );
     if ( iCountErrors == 0 )
     {
         Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
         return true;
     }
     else
     {
         Console.WriteLine( strTest+ strPath );
         Console.WriteLine( strTest+ "FAiL" );
         Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
         return false;
     }
 }
Example #32
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 #33
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;
         }
     }
 }
Example #34
0
        public void TestLargeCapacity()
        {
            //
            //  []  Add a range large enough to increase the capacity of the arrayList by more than a factor of two
            //
            ArrayList arrInsert = new ArrayList();

            for (int i = 0; i < 128; i++)
            {
                arrInsert.Add(-i);
            }

            ArrayList arrList = new ArrayList();

            ArrayList[] arrayListTypes1 = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes1)
            {
                arrList = arrayListType;

                arrList.InsertRange(0, arrInsert);

                for (int i = 0; i < arrInsert.Count; i++)
                {
                    Assert.Equal(-i, (int)arrList[i]);
                }
            }
        }
Example #35
0
        public void TestInsertRangeBasic()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            ArrayList arrInsert = null;
            int ii = 0;
            int start = 3;

            //
            // Construct array lists.
            //
            arrList = new ArrayList((ICollection)strHeroes);

            //
            // Construct insert array list.
            //
            arrInsert = new ArrayList((ICollection)strInsert);

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

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

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Insert collection into array list.
                //
                // InsertRange values.
                arrList.InsertRange(start, arrInsert);

                // Verify InsertRange.
                for (ii = 0; ii < strResult.Length; ++ii)
                {
                    Assert.Equal(0, strResult[ii].CompareTo((String)arrList[ii]));
                }

                //
                //  []  Attempt invalid InsertRange using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.InsertRange(-1000, arrInsert));

                //
                //  []  Attempt invalid InsertRange using out of range index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.InsertRange(1000, arrInsert));

                //
                //  []  Attempt insertion of null collection.
                arrInsert = new ArrayList((ICollection)strInsert);
                Assert.Throws<ArgumentNullException>(() => arrList.InsertRange(start, null));

                // []Insert an empty ICollection
                arrList = new ArrayList();
                Queue que = new Queue();
                arrList.InsertRange(0, que);

                Assert.Equal(0, arrList.Count);
            }
        }
Example #36
0
        public void TestInsertItselfWithRange()
        {
            //
            // []  Insert itself into array list. with range
            //
            ArrayList arrList = new ArrayList((ICollection)strHeroes);

            ArrayList[] arrayListTypes = new ArrayList[] {
                            (ArrayList)arrList.Clone(),
                            (ArrayList)ArrayList.Adapter(arrList).Clone(),
                            (ArrayList)ArrayList.Synchronized(arrList).Clone()
            };

            int start = 3;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                // InsertRange values.
                arrList.InsertRange(start, arrList.GetRange(0, arrList.Count));

                // Verify InsertRange.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    string expectedItem;

                    if (ii < start)
                    {
                        expectedItem = strHeroes[ii];
                    }
                    else if (start <= ii && ii - start < strHeroes.Length)
                    {
                        expectedItem = strHeroes[ii - start];
                    }
                    else
                    {
                        expectedItem = strHeroes[(ii - strHeroes.Length)];
                    }

                    Assert.Equal(0, expectedItem.CompareTo((string)arrList[ii]));
                }
            }

        }
Example #37
0
        public void TestInsertItself()
        {
            //
            // []  Insert itself into array list.
            //
            ArrayList arrList = new ArrayList((ICollection)strHeroes);

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

            int start = 3;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                // InsertRange values.
                arrList.InsertRange(start, arrList);

                // Verify InsertRange.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    string expectedItem;

                    if (ii < start)
                    {
                        expectedItem = strHeroes[ii];
                    }
                    else if (start <= ii && ii - start < strHeroes.Length)
                    {
                        expectedItem = strHeroes[ii - start];
                    }
                    else
                    {
                        expectedItem = strHeroes[(ii - strHeroes.Length)];
                    }

                    Assert.Equal(0, expectedItem.CompareTo((string)arrList[ii]));
                }

                //[] Verify that ArrayList does not pass the internal array to CopyTo
                arrList.Clear();
                for (int i = 0; i < 64; ++i)
                {
                    arrList.Add(i);
                }

                ArrayList arrInsert = new ArrayList();

                for (int i = 0; i < 4; ++i)
                {
                    arrInsert.Add(i);
                }

                MyCollection myCollection = new MyCollection(arrInsert);
                arrList.InsertRange(4, myCollection);

                Assert.Equal(0, myCollection.StartIndex);

                Assert.Equal(4, myCollection.Array.Length);
            }
        }