Example #1
0
        public void TestGetItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            //
            // Construct array list.
            //
            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 = {
                                        (ArrayList)arrList.Clone(),
                                        (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                        (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                        (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                                        (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                        (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Verify get method.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strHeroes.Length; ++ii)
                {
                    // Verify get.
                    Assert.Equal(0, ((string)arrList[ii]).CompareTo(strHeroes[ii]));
                }

                //
                // []  Invalid Index.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[(int)arrList.Count];
                });

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[-1];
                });
            }
        }
Example #2
0
    public ArrayList CountInversion(ArrayList source)
    {
        if (source.Count == 1)
        {
            return source;
        }
        var split = (int)(source.Count / 2); //GetSplitPLace(to - from);
        ArrayList leftArray = source.GetRange(0, split);
        ArrayList rightArray = source.GetRange(split, source.Count - split);
        ArrayList arrSortedInt = new ArrayList();
        leftArray = CountInversion(leftArray);
        rightArray = CountInversion(rightArray);
        int leftptr = 0;
        int rightptr = 0;
        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftptr == leftArray.Count)
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
            else if (rightptr == rightArray.Count)
            {

                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else if ((int)leftArray[leftptr] < (int)rightArray[rightptr])
            {

                //need the cast above since arraylist returns Type object
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else
            {
                inversionCount += (leftArray.Count - leftptr);
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
        }

        return arrSortedInt;
    }
Example #3
0
    public ArrayList MergeSort( ArrayList arrIntegers )
    {
        if (arrIntegers.Count == 1)
        {
            return arrIntegers;
        }
        ArrayList arrSortedInt = new ArrayList();
        int middle = (int)arrIntegers.Count/2;

        ArrayList leftArray = arrIntegers.GetRange(0, middle);
        ArrayList rightArray = arrIntegers.GetRange(middle, arrIntegers.Count - middle);

        leftArray =  MergeSort(leftArray);
        rightArray = MergeSort(rightArray);

        int leftptr = 0;
        int rightptr=0;

        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftptr==leftArray.Count)
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
            else if (rightptr==rightArray.Count)
            {
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else if ((int)leftArray[leftptr]<(int)rightArray[rightptr])
            {
                //need the cast above since arraylist returns Type object
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
        }
        return arrSortedInt;
    }
Example #4
0
    public static ArrayList Merge(ArrayList inputArray)
    {
        if (inputArray.Count == 1)
        {
            return inputArray;
        }
        ArrayList arraySorted = new ArrayList();
        int leftPart = 0;
        int rightPart = 0;
        int middle = (int)inputArray.Count / 2;

        ArrayList leftArray = inputArray.GetRange(0, middle);
        leftArray = Merge(leftArray);
        ArrayList rightArray = inputArray.GetRange(middle, inputArray.Count - middle);
        rightArray = Merge(rightArray);

        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftPart == leftArray.Count)
            {
                arraySorted.Add(rightArray[rightPart]);
                rightPart++;
            }
            else if (rightPart == rightArray.Count)
            {
                arraySorted.Add(leftArray[leftPart]);
                leftPart++;
            }
            else if ((int)leftArray[leftPart] < (int)rightArray[rightPart])
            {
                arraySorted.Add(leftArray[leftPart]);
                leftPart++;
            }
            else
            {
                arraySorted.Add(rightArray[rightPart]);
                rightPart++;
            }
        }
        return arraySorted;
    }
Example #5
0
        public static string toFraction(double n)
        {
            if (Math.Abs(n % 1) < 0.000000001)
            {
                return(Convert.ToString(n, CultureInfo.InvariantCulture));
            }
            var number       = Convert.ToString(n, CultureInfo.CurrentCulture);
            var numberSpited = Regex.Split(number, "\\.");

            if (numberSpited[1].Length > 9)
            {
                numberSpited[1] = numberSpited[1].Substring(0, 9);
            }
            var whole = long.Parse(numberSpited[0]);
            var a     = long.Parse(numberSpited[1]);
            var b     = (long)Math.Pow(10, numberSpited[1].Length);
            var cf    = new ArrayList();

            while (b != 0 && cf.Count < 100)
            {
                var f = a / b;
                cf.Add(f);
                a -= (f * b);
                var temp = a;
                a = b;
                b = temp;
            }

            long numerator   = 0;
            long denominator = 0;

            for (var i = 1; i <= cf.Count; i++)
            {
                Fraction(cf.GetRange(0, i), out var numeratorActual, out var denominatorActual);
                if (numeratorActual > 2000 || denominatorActual > 2000)
                {
                    break;
                }
                numerator   = numeratorActual;
                denominator = denominatorActual;
            }

            if (whole > 0)
            {
                return($"{(whole * denominator) + numerator}/{denominator}");
            }
            if (whole < 0)
            {
                return($"{(whole * denominator) - numerator}/{denominator}");
            }
            return((n < 0)?$"-{numerator}/{denominator}":$"{numerator}/{denominator}");
        }
Example #6
0
        public override void TestFun()
        {
            //ArrayList对象可以指定初始容量
            //每当容量占满后会重新开辟当前容量2倍的空间(如:5,10,20)
            ArrayList arrayList = new ArrayList(5);

            for (int i = 0; i < 6; i++)
            {
                arrayList.Add(i);
            }
            Console.WriteLine("arrayList大小:{0}", arrayList.Count);
            Console.WriteLine("arrayList容量(可包含的元素数量):{0}", arrayList.Capacity);
            for (int i = 0; i < 6; i++)
            {
                arrayList.Add(i);
            }
            Console.WriteLine("arrayList大小:{0}", arrayList.Count);
            Console.WriteLine("arrayList容量(可包含的元素数量):{0}", arrayList.Capacity);

            arrayList.AddRange(new ArrayList {
                8, 7, 6
            });

            ArrayList list = arrayList.GetRange(6, 3);

            arrayList.IndexOf(6, 0, 9);

            arrayList.Reverse(0, 6);

            arrayList.Clear();

            ArrayList listData = new ArrayList();

            listData.Add(new DataArrayList {
                number = 1, name = "一"
            });
            listData.Add(new DataArrayList {
                number = 4, name = "四"
            });
            listData.Add(new DataArrayList {
                number = 2, name = "二"
            });
            listData.Add(new DataArrayList {
                number = 9, name = "九"
            });
            listData.Sort();
            foreach (var v in listData)
            {
                DataArrayList d = v as DataArrayList;
                Console.WriteLine("number:{0},name:{1}", d.number, d.name);
            }
        }
Example #7
0
        public void Test(int arg)
        {
            ArrayList items = new ArrayList();

            items.Add(1);
            items.AddRange(1, 2, 3);
            items.Clear();
            bool b1 = items.Contains(2);

            items.Insert(0, 1);
            items.InsertRange(1, 0, 5);
            items.RemoveAt(4);
            items.RemoveRange(4, 3);
            items.Remove(1);
            object[] newItems  = items.GetRange(5, 2);
            object[] newItems2 = items.GetRange(5, arg);

            List <int> numbers = new List <int>();

            numbers.Add(1);
            numbers.AddRange(1, 2, 3);
            numbers.Clear();
            bool b2 = numbers.Contains(4);

            numbers.Insert(1, 10);
            numbers.InsertRange(2, 10, 3);
            numbers.RemoveAt(4);
            numbers.RemoveRange(4, 2);
            int[] newNumbers  = items.GetRange(5, 2);
            int[] newNumbers2 = items.GetRange(5, arg);

            string[] words = new string[5];
            words[0] = "hello";
            words[1] = "world";
            bool b3 = words.Contains("hi");

            string[] newWords  = words.GetRange(5, 2);
            string[] newWords2 = words.GetRange(5, arg);
        }
Example #8
0
        public static ArrayList get50Players()
        {
            ArrayList allUsers = UserManager.getAllUsers();

            if (allUsers.Count >= 50)
            {
                return(allUsers.GetRange(0, 50));
            }
            else
            {
                return(allUsers);
            }
        }
Example #9
0
        //
        // SubList
        //

        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="idx1"></param>
        /// <param name="idx2"></param>
        /// <returns></returns>
        public static IList SubList(IList list, int idx1, int idx2)
        {
            ArrayList alist = list as ArrayList;

            if (alist != null)
            {
                return(alist.GetRange(idx1, idx2 - idx1));
            }
            else
            {
                throw new NotImplementedException("SubList(IList list, int idx1, int idx2)");
            }
        }
Example #10
0
        protected override void computeMACInfo()
        {
            if (m_viewStateBase64 == "")
            {
                return;
            }

            // this whole set of steps is a little cludgly, but there doesn't seem to be a better way for now.  We detect MAC info by
            // getting comparing the size of the original viewstate base64 decoded and the original viewstate decoded and then reencoded.  If the two objects
            // don't match in size and the difference between before and after is 20 bytes we assume there is MAC protection.
            byte[] originalViewStateDeserialized = System.Convert.FromBase64String(m_viewStateBase64);
            int    arrowCount = 0;
            int    i          = 0;

            for (i = 0; i < originalViewStateDeserialized.Length; i++)
            {
                if (originalViewStateDeserialized[i] == (byte)'<')
                {
                    arrowCount++;
                }
                else if (originalViewStateDeserialized[i] == (byte)'>')
                {
                    arrowCount--;
                }
                else
                {
                    continue;
                }
                // if we find the closing ">" then we assume we are either at the end of the viewstate or their is trailing MAC info
                if (arrowCount == 0)
                {
                    i++; // we bump the counter up to skip past the final ">"
                    break;
                }
            }
            // if we have 20 bytes left we assume there is MAC protection
            if (originalViewStateDeserialized.Length - i == 20)
            {
                m_MACProtected = true;
                ArrayList tempList  = new ArrayList(originalViewStateDeserialized);
                byte[]    tempArray = new byte[20];                              //the size of the MAC
                int       MACIndex  = originalViewStateDeserialized.Length - 20; // 20 is the size of the MAC
                tempList.GetRange(MACIndex, 20).CopyTo(tempArray);
                String hexString = BitConverter.ToString(tempArray);
                m_MAC = hexString.Replace("-", "");
            }
            else
            {
                m_MACProtected = false;
            }
        }
        private bool PumpQueue(ArrayList queue,
                               SingleFeedAction sfa, MultipleFeedAction mfa)
        {
            PodcastFeedInfo feed  = null;
            ICollection     feeds = null;

            int range_upper = -1;

            lock (queue.SyncRoot)
            {
                if (queue.Count == 0)
                {
                    return(false);
                }

                int queue_count = queue.Count;
                range_upper = (queue_count >= 32) ? 31 : queue_count;

                if (queue_count == 1)
                {
                    feed = queue [0] as PodcastFeedInfo;
                }
                else if (queue_count > 1)
                {
                    feeds = queue.GetRange(0, range_upper);
                }
            }

            if (feed != null)
            {
                sfa(feed);
            }
            else if (feeds != null)
            {
                mfa(feeds);
            }

            lock (queue.SyncRoot)
            {
                queue.RemoveRange(0, range_upper);

                if (queue.Count == 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Example #12
0
        public void TwoConstantArguments()
        {
            MethodCallExpressionVisitor visitor = new MethodCallExpressionVisitor();

            ArrayList collection = new ArrayList();

            Expression <Action> expression = () => collection.GetRange(1, 2);

            visitor.Visit(expression);

            Assert.AreEqual(2, visitor.MethodCallArguments.Count);
            Assert.AreEqual(1, visitor.MethodCallArguments[0]);
            Assert.AreEqual(2, visitor.MethodCallArguments[1]);
        }
Example #13
0
        public static ArrayList CopyAndInsert(ArrayList list, int index, object obj)
        {
            ArrayList newList = new ArrayList((list.Count + 1));

            if (index == 0)
            {
                newList.Add(obj);
                newList.AddRange(list);
            }
            else
            {
                if (index == list.Count)
                {
                    newList.AddRange(list);
                    newList.Add(obj);
                    return(newList);
                }
                newList.AddRange(list.GetRange(0, index));
                newList.Add(obj);
                newList.AddRange(list.GetRange(index, (list.Count - index)));
            }
            return(newList);
        }
Example #14
0
        private String getViewStateStringWithoutMAC()
        {
            int offset = 0;

            if (m_MACProtected)
            {
                offset = 20;
            }
            ArrayList tempList = new ArrayList(System.Convert.FromBase64String(m_viewStateBase64));

            byte[] tempArray = new byte[tempList.Count - offset];  //the size of the MAC
            tempList.GetRange(0, tempList.Count - offset).CopyTo(tempArray);
            return(System.Text.Encoding.UTF8.GetString(tempArray));
        }
Example #15
0
 Object processMacroList(ArrayList args)
 {
     if (RuntimeServer.isMessage(":box", args))
     {
         return(Reflector.numericConvert(RuntimeServer.typeArg(args[1]), args[2]));
     }
     else if (RuntimeServer.isMessage(":vector", args))
     {
         return(reflector.createVector(RuntimeServer.typeArg(args[1])
                                       , args.Count - 2
                                       , args.GetRange(2, args.Count)));
     }
     throw new Exception("unsupported macro sequence");
 }
Example #16
0
        static int Min(ArrayList argumentList)
        {
            var result = (int)argumentList[0];

            foreach (var item in argumentList.GetRange(1, argumentList.Count - 1))
            {
                if (result > (int)item)
                {
                    result = (int)item;
                }
            }

            return(result);
        }
Example #17
0
        /// <summary>
        /// Split the list of sockets.
        /// </summary>
        /// <param name="socketList">The list of sockets to split.</param>
        /// <returns>The list of socket collection.</returns>
        private ArrayList[] GetSocketList(ArrayList socketList)
        {
            List <ArrayList> list = new List <ArrayList>();

            int count            = socketList.Count;
            int totalNumSegments = 0;

            // Get the total number of clients per thread.
            // Initially the same as max number of clients;
            // Add one segiment if a remainder exists.
            if ((count % _socketThreadCount) > 0)
            {
                totalNumSegments = ((int)(count / _socketThreadCount)) + 1;
            }
            else
            {
                totalNumSegments = ((int)(count / _socketThreadCount));
            }

            // If socket number is more than thread count.
            if (count >= _socketThreadCount)
            {
                // For each thread get the number of items.
                for (int i = 0; i < _socketThreadCount; i++)
                {
                    int start  = i * totalNumSegments;
                    int number = totalNumSegments;
                    int left   = count - start;

                    // If the number left is less than
                    // the current start index, then
                    // take what is left.
                    if (left < number)
                    {
                        number = left;
                    }

                    // Get the array list.
                    list.Add(socketList.GetRange(start, number));
                }
            }
            else
            {
                // Return the original array list.
                list.Add(socketList);
            }

            // Return the list.
            return(list.ToArray());
        }
Example #18
0
        public Tuple <ArrayList, bool> GetStranicu(int BrojStranice)
        {
            ArrayList StranicaValues = new ArrayList();
            int       pocetniIndex   = 0;

            if (BrojStranice == 1)
            {
                if (ArrayList.Count > PageSize)
                {
                    StranicaValues = ArrayList.GetRange(pocetniIndex, PageSize);
                    return(Tuple.Create(StranicaValues, false));
                }
                else
                {
                    StranicaValues = ArrayList;
                    //TempData["ZadnjaStranica"] = true;

                    return(Tuple.Create(StranicaValues, true));
                }
            }
            else
            {
                //5 po starnici
                //1 str 0-4 pocetni index 0
                //2 str 5-9 pocedtni index 5 (broj stranice -1)*po stranici =(2-1)*5=1*5=5
                //3 str 10-14 ocedtni index 10 (3-1)*5=2*5=10
                //4 str 15-19 poc ind       15 (4-1)*5=3*5=15
                //5 str 20-24 ind           20
                int max = ArrayList.Count;
                pocetniIndex = (BrojStranice - 1) * PageSize;

                if (pocetniIndex >= max)
                {
                    return(Tuple.Create(StranicaValues, true));//salje null-true
                }

                if (max < pocetniIndex + PageSize)
                {
                    int zadnjaStranicaBrojRedova = (max - pocetniIndex);
                    StranicaValues = ArrayList.GetRange(pocetniIndex, zadnjaStranicaBrojRedova);
                    //TempData["ZadnjaStranica"] = true;
                    return(Tuple.Create(StranicaValues, true));
                }


                StranicaValues = ArrayList.GetRange(pocetniIndex, PageSize);
            }

            return(Tuple.Create(StranicaValues, false));
        }
Example #19
0
 public csDataFrame(ArrayList arrCommBuffer)
 {
     this.m_arrCommBuffer = new ArrayList();
     this.m_arrCommBuffer.Add(arrCommBuffer[0]);
     this.m_arrCommBuffer.AddRange((ICollection)this.Unstuff(arrCommBuffer.GetRange(1, arrCommBuffer.Count - 2)));
     this.m_arrCommBuffer.Add(arrCommBuffer[arrCommBuffer.Count - 1]);
     this.m_bytStartByte          = (byte)this.m_arrCommBuffer[0];
     this.m_bytDestinationAddress = (byte)arrCommBuffer[1];
     this.m_bytCID      = (byte)arrCommBuffer[2];
     this.m_shoCRC      = csTools.BigEndianBytesToShort(this.m_arrCommBuffer.GetRange(this.m_arrCommBuffer.Count - 3, 2));
     this.m_bytStopByte = (byte)this.m_arrCommBuffer[this.m_arrCommBuffer.Count - 1];
     this.m_arrData     = new ArrayList();
     this.m_arrData.AddRange((ICollection)this.m_arrCommBuffer.GetRange(3, this.m_arrCommBuffer.Count - 6));
 }
Example #20
0
    /*static void Main()
     * {
     *  int[] ar = new int[10];
     *  Array.Resize(ref ar, 16);
     *  Console.WriteLine(ar.Length);
     *  Console.ReadLine();
     *
     * }*/
    static void Main()
    {
        ArrayList al = new ArrayList();

        Console.WriteLine(al.Capacity);
        al.Add(100);
        al.Add("Stirg");
        al.Insert(2, 6);
        al.AddRange(al);
// Console.WriteLine(al.BinarySearch("stirg"));
        Console.WriteLine(al.Count);
        Console.WriteLine(al.GetRange(1, 3));
        Console.Read();
    }
Example #21
0
        public override bool Makeframes(ref ArrayList frame, byte[] addr, byte AFN, bool pw, int pwLen, byte[] pn, byte[] fn)
        {
            ArrayList ftp = new ArrayList();

            frame.Clear();
            frame.Add((byte)0x68);
            frame.Add((byte)0x68);

            frame.Add((byte)0x4B);  // 控制码
            /* 集中器地址 */
            frame.AddRange(addr);
            /* 主站编号 */
            frame.Add((byte)0x02);
            /* AFN */
            frame.Add(AFN);
            /* MSTA&SEQ */
            frame.Add((byte)0x70);
            /* PN */
            frame.AddRange(pn);
            /* FN */
            frame.AddRange(fn);
            ///* PW */
            if (pw == true)
            {
                for (int n = 0; n < pwLen; n++)
                {
                    frame.Add((byte)0x00);
                }
            }
            int len = frame.Count;

            if (pwLen == GW_PW_LEN)
            {
                len = ((len - 2) << 2) | 0x02;
            }
            else
            {
                len = ((len - 2) << 2) | 0x01;
            }
            frame.Insert(1, (byte)(len & 0xff));
            frame.Insert(2, (byte)((len >> 8) & 0xff));
            frame.Insert(3, (byte)(len & 0xff));
            frame.Insert(4, (byte)((len >> 8) & 0xff));

            frame.Add(getCS(frame.GetRange(6, frame.Count - 6)));
            frame.Add((byte)0x16);

            return(true);
        }
Example #22
0
    public static void Main()
    {
        // Creates and initializes a new ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("The");
        myAL.Add("quick");
        myAL.Add("brown");
        myAL.Add("fox");
        myAL.Add("jumps");
        myAL.Add("over");
        myAL.Add("the");
        myAL.Add("lazy");
        myAL.Add("dog");

        // Creates and initializes the source ICollection.
        Queue mySourceList = new Queue();

        mySourceList.Enqueue("big");
        mySourceList.Enqueue("gray");
        mySourceList.Enqueue("wolf");

        // Displays the values of five elements starting at index 0.
        ArrayList mySubAL = myAL.GetRange(0, 5);

        Console.WriteLine("Index 0 through 4 contains:");
        PrintValues(mySubAL, '\t');

        // Replaces the values of five elements starting at index 1 with the values in the ICollection.
        myAL.SetRange(1, mySourceList);

        // Displays the values of five elements starting at index 0.
        mySubAL = myAL.GetRange(0, 5);
        Console.WriteLine("Index 0 through 4 now contains:");
        PrintValues(mySubAL, '\t');
    }
Example #23
0
        /*
         * PBKDF2 as described in PKCS #5 v2.0 pp.8-10
         */

        private static byte[] PBKDF2(byte[] passphrase, byte[] salt, int c, int dkLen)
        {
            const int hLen = 20;
            int       l    = (int)Math.Ceiling((double)dkLen / hLen);
            //int r = dkLen - (l - 1)*hLen;

            ArrayList result = new ArrayList(dkLen);

            for (int i = 0; i < l; i++)
            {
                result.AddRange(F(passphrase, salt, c, i));
            }

            return((byte[])result.GetRange(0, dkLen).ToArray(Type.GetType("System.Byte")));
        }
Example #24
0
 public override void In(FlowEventArgs e)
 {
     SetArrayList();
     if (ArrayList != null)
     {
         SetValue(nameof(Index));
         SetValue(nameof(Count));
         Value = ArrayList.GetRange(Index, Count);
         OnSuccess();
     }
     else
     {
         OnFailed();
     }
 }
Example #25
0
        static void Main(string[] args)
        {
            ArrayList names = new ArrayList();

            names.Add("A1");
            names.Add("A2");
            names.Add("A3");
            Console.WriteLine("name list is:");
            foreach (object name in names)
            {
                Console.WriteLine(name);
            }
            Console.WriteLine();

            string[]  newNames  = new string[] { "B1", "B2" };
            ArrayList moreNames = new ArrayList();

            moreNames.Add("C1");
            moreNames.Add("C2");
            moreNames.Add("C3");

            names.InsertRange(0, newNames);
            names.AddRange(moreNames);
            Console.WriteLine("name list is:");
            foreach (object name in names)
            {
                Console.WriteLine(name);
            }

            ArrayList someName = new ArrayList();

            someName = names.GetRange(2, 4);
            Console.WriteLine("someName is: ");
            foreach (object name in someName)
            {
                Console.WriteLine(name);
            }

            object[] arrNames;
            arrNames = names.ToArray();
            Console.WriteLine("arrNames is: ");
            for (int i = 0; i <= arrNames.GetUpperBound(0); i++)
            {
                Console.WriteLine(arrNames[i]);
            }

            Console.ReadKey();
        }
Example #26
0
        private void Complete()
        {
            ArrayList CompEdges = new ArrayList(PredEdges);

            CompEdges = CompEdges.GetRange(0, NoEdges);
            while (CompEdges.Count > 0)
            {
                ArrayList NewEdges = new ArrayList();
                foreach (Edge src in CompEdges)
                {
                    if (src.Needed.Count > 0 && src.End < Words.Count)
                    {
                        foreach (Edge dst in EdgesByStart[src.End])
                        {
                            if ((string)src.Needed[0] == dst.Goal && dst.Needed.Count == 0)
                            {
                                Edge e = MakeEdge(src, dst);
                                NewEdges.Add(e);
                                if (e.Needed.Count > 0 && e.End < Words.Count)
                                {
                                    PredEdges.Push(e);
                                }
                            }
                        }
                    }
                    else if (src.Needed.Count == 0)
                    {
                        foreach (Edge dst in EdgesByEnd[src.Start])
                        {
                            if (dst.Needed.Count > 0 && (string)dst.Needed[0] == src.Goal)
                            {
                                Edge e = MakeEdge(dst, src);
                                NewEdges.Add(e);
                                if (e.Needed.Count > 0 && e.End < Words.Count)
                                {
                                    PredEdges.Push(e);
                                }
                            }
                        }
                    }
                }
                foreach (Edge e in NewEdges)
                {
                    AddEdge(e);
                }
                CompEdges = NewEdges;
            }
        }
Example #27
0
    public static void Main()
    {
        ArrayList week     = new ArrayList(new string[] { "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье" });
        ArrayList workweek = new ArrayList(week.GetRange(0, 5));

        foreach (string day in workweek)
        {
            Console.WriteLine(day);
        }
        Console.WriteLine("//////////////////");
        week.Sort();
        foreach (string day in week)
        {
            Console.WriteLine(day);
        }
    }
Example #28
0
 private void addToListBox(ArrayList list)
 {
     try
     {
         int rango = list.Count - posListBox * 10;
         if (rango > 10)
         {
             rango = 10;
         }
         foreach (Frases item in list.GetRange(posListBox * 10, rango))
         {
             lbFrases.Items.Add(item.Autor + ": \t" + item.Frase);
         }
     }
     catch { }
 }
Example #29
0
        /// <summary>
        /// Joins a new string with the elements of the array.
        /// </summary>
        /// <param name="joiner">The joiner.</param>
        /// <param name="joinees">The joinees.</param>
        /// <returns>The combined string.</returns>
        public static string Join(string joiner, ArrayList joinees)
        {
            if (joinees.Count == 0)
            {
                return(string.Empty);
            }

            string joined = (string)joinees[0];

            foreach (string str in joinees.GetRange(1, joinees.Count - 1))
            {
                joined = joined + joiner + str;
            }

            return(joined);
        }
Example #30
0
        //输入单词进行词频统计分析
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox7.TextLength != 0 && textBox9.TextLength != 0)
            {
                if (click == true && textBox5.TextLength == 0)
                {
                    sumchar = wordCount.characSum(textBox1.Text.ToString());
                    al      = wordCount.Splitwords(textBox1.Text.ToString());
                    //textBox8.AppendText(al.Capacity.ToString());
                    int i = 0;
                    while (i <= (al.Count - CZcount))
                    {
                        var result = al.GetRange(i, CZcount);
                        foreach (var n in result)
                        {
                            textBox8.AppendText(n.ToString() + " ");
                        }

                        textBox8.AppendText("\r\n");
                        i++;
                    }


                    sumword = wordCount.Sumword(al);
                    nary    = wordCount.countWords(al);
                    textBox3.AppendText(sumchar.ToString());
                    textBox4.AppendText(sumword.ToString());
                    foreach (var pair in nary.Take(ZDYcount))
                    {
                        textBox2.AppendText(pair.Key + ":" + pair.Value);
                        textBox2.AppendText("\r\n");
                    }
                }
                else if (textBox1.TextLength == 0 && click == true)
                {
                    MessageBox.Show("已导入");
                }
                else
                {
                    MessageBox.Show("请点击自定义");
                }
            }
            else
            {
                MessageBox.Show("请输入两个需要的数字");
            }
        }
Example #31
0
        static void Combine(ArrayList teams, ArrayList result, int m, ArrayList results)
        {
            if (result.Count == m)
            {
                //Console.WriteLine(String.Join(" ", result.ToArray()));
                results.Add(result);
                return;
            }
            for (int i = 0; i < teams.Count; i++)
            {
                ArrayList new_result = (ArrayList)result.Clone();
                new_result.Add(teams[i]);

                ArrayList rest_teams = teams.GetRange(i + 1, teams.Count - i - 1);
                Combine(rest_teams, new_result, m, results);
            }
        }
Example #32
0
        private OrderList ConvertOrderArrayListToOrderList(ArrayList orderList, object amountPosition, object pricePosition, int?maxSize = null)
        {
            OrderList returnList = new OrderList();

            //If a maximum size was given, only put that number of orders in the asks and bids lists. Otherwise, get them all.
            if (maxSize != null && maxSize < orderList.Count)
            {
                orderList = orderList.GetRange(0, maxSize.Value);
            }

            if (orderList != null && orderList.Count > 0)
            {
                foreach (object order in orderList)
                {
                    decimal amount = 0.0m;
                    decimal price  = 0.0m;

                    if (order != null && order.GetType() == typeof(Dictionary <string, object>))
                    {
                        Dictionary <string, object> orderDict = (Dictionary <string, object>)order;

                        if (orderDict.ContainsKey((string)pricePosition) && orderDict.ContainsKey((string)amountPosition) && orderDict[(string)amountPosition] != null && orderDict[(string)pricePosition] != null)
                        {
                            amount = TypeConversion.ParseStringToDecimalStrict(orderDict[(string)amountPosition].ToString());
                            price  = TypeConversion.ParseStringToDecimalStrict(orderDict[(string)pricePosition].ToString());
                        }
                    }

                    else if (order != null && order.GetType() == typeof(ArrayList))
                    {
                        ArrayList orderArrayList = (ArrayList)order;

                        //Make sure each order has a price and amount
                        if (orderArrayList.Count >= 2)
                        {
                            amount = TypeConversion.ParseStringToDecimalStrict(orderArrayList[(int)amountPosition].ToString());
                            price  = TypeConversion.ParseStringToDecimalStrict(orderArrayList[(int)pricePosition].ToString());
                        }
                    }

                    returnList.Add(new Order(amount, price));
                }
            }

            return(returnList.Count <= 0 ? null : returnList);
        }
 public OperationNotDefinedException(SourceCodeContext line, string op, string op1, ArrayList arglist)
     : base(line, op)
 {
     _msg = String.Format("Operator '{0}' not defined for type '{1}'", op, op1);
     if (arglist.Count > 1)
     {
         _msg += " and type ";
         if (arglist.Count > 2)
         {
             foreach (Var v in arglist.GetRange(1, arglist.Count - 2))
             {
                 _msg += "'" + v.TypeName() + "',";
             }
         }
         _msg += "'" + (arglist[arglist.Count - 1] as Var).TypeName() + "'";
     }
 }
Example #34
0
        public void TestArrayListWrappers()
        {
            ArrayList alst1;
            string    strValue;
            Array     arr1;

            //[] Vanila test case - ToArray returns an array of this. We will not extensively test this method as
            // this is a thin wrapper on Array.Copy which is extensively tested elsewhere
            alst1 = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                alst1.Add(strValue);
            }

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

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                alst1 = arrayListType;
                arr1  = alst1.ToArray(typeof(string));

                for (int i = 0; i < 10; i++)
                {
                    strValue = "String_" + i;
                    Assert.Equal(strValue, (string)arr1.GetValue(i));
                }

                //[] this should be covered in Array.Copy, but lets do it for
                Assert.Throws <InvalidCastException>(() => { arr1 = alst1.ToArray(typeof(int)); });
                Assert.Throws <ArgumentNullException>(() => { arr1 = alst1.ToArray(null); });
            }

            //[]lets try an empty list
            alst1.Clear();
            arr1 = alst1.ToArray(typeof(Object));
            Assert.Equal(0, arr1.Length);
        }
Example #35
0
        public void TestArrayListWrappers()
        {
            ArrayList alst1;
            string strValue;
            Array arr1;

            //[] Vanila test case - ToArray returns an array of this. We will not extensively test this method as
            // this is a thin wrapper on Array.Copy which is extensively tested elsewhere
            alst1 = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                alst1.Add(strValue);
            }

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

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                alst1 = arrayListType;
                arr1 = alst1.ToArray(typeof(string));

                for (int i = 0; i < 10; i++)
                {
                    strValue = "String_" + i;
                    Assert.Equal(strValue, (string)arr1.GetValue(i));
                }

                //[] this should be covered in Array.Copy, but lets do it for
                Assert.Throws<InvalidCastException>(() => { arr1 = alst1.ToArray(typeof(int)); });
                Assert.Throws<ArgumentNullException>(() => { arr1 = alst1.ToArray(null); });
            }

            //[]lets try an empty list
            alst1.Clear();
            arr1 = alst1.ToArray(typeof(Object));
            Assert.Equal(0, arr1.Length);
        }
Example #36
0
        public static void PerformActionOnAllArrayListWrappers(ArrayList arrList, Action<ArrayList> action)
        {
            // Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of ArrayList.
            // The following variable contains each one of these types of array lists
            ArrayList[] arrayListTypes =
            {
                (ArrayList)arrList.Clone(),
                (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                (ArrayList)ArrayList.Adapter(arrList).Clone(),
                (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                (ArrayList)ArrayList.Synchronized(arrList).Clone()
            };  

            foreach (ArrayList arrListType in arrayListTypes)
            {
                action(arrListType);
            }
        }
Example #37
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

            string[] strHeroes = 
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Green Lantern",
                "Hawkman",
                null,
                "Ironman",
                "Nightwing",
                "Robin",
                "SpiderMan",
                "Steel",
                null,
                "Thor",
                "Wildcat",
                null
            };

            //[]  Vanila Contains

            // Construct ArrayList.
            arrList = new ArrayList(strHeroes);

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    Assert.True(arrList.Contains(strHeroes[i]), "Error, Contains returns false but shour return true at position " + i.ToString());
                }

                if (!arrList.IsFixedSize)
                {
                    //[]  Normal Contains which expects false
                    for (int i = 0; i < strHeroes.Length; i++)
                    {
                        // remove element, if element is in 2 times make sure we remove it completely.
                        for (int j = 0; j < strHeroes.Length; j++)
                        {
                            arrList.Remove(strHeroes[i]);
                        }

                        Assert.False(arrList.Contains(strHeroes[i]), "Error, Contains returns true but should return false at position " + i.ToString());
                    }
                }

                if (!arrList.IsFixedSize)
                {
                    //[]  Normal Contains on empty list
                    arrList.Clear();

                    for (int i = 0; i < strHeroes.Length; i++)
                    {
                        Assert.False(arrList.Contains(strHeroes[i]), "Error, Contains returns true but should return false at position " + i.ToString());
                    }
                }
            }
        }
Example #38
0
        public void TestArrayListWrappers02()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int ndx = -1;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Batman",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Batman",
                "Green Lantern",
                "Hawkman",
                "Huntress",
                "Ironman",
                "Nightwing",
                "Batman",
                "Robin",
                "SpiderMan",
                "Steel",
                "Superman",
                "Thor",
                "Batman",
                "Wildcat",
                "Wonder Woman",
                "Batman",
                null
            };

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

            //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)};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Obtain index of "Batman" items.
                //
                ndx = 0;

                int startIndex = 0;
                int tmpNdx = 0;
                while (startIndex < arrList.Count && (ndx = arrList.IndexOf("Batman", startIndex, (arrList.Count - startIndex))) != -1)
                {
                    Assert.True(ndx >= startIndex);

                    Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));

                    tmpNdx = arrList.IndexOf("Batman", startIndex, ndx - startIndex + 1);
                    Assert.Equal(ndx, tmpNdx);

                    tmpNdx = arrList.IndexOf("Batman", startIndex, ndx - startIndex);
                    Assert.Equal(-1, tmpNdx);

                    startIndex = ndx + 1;
                }

                //
                // []  Attempt to find null object when a null element exists in the collections
                //
                ndx = arrList.IndexOf(null, 0, arrList.Count);
                Assert.Null(arrList[ndx]);

                //
                //  []  Attempt invalid IndexOf using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.IndexOf("Batman", -1000, arrList.Count));

                //
                //  []  Attempt invalid IndexOf using out of range index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.IndexOf("Batman", 1000, arrList.Count));

                //
                //  []  Attempt invalid IndexOf using index=Count
                //
                Assert.Equal(-1, arrList.IndexOf("Batman", arrList.Count, 0));


                //
                //  []  Attempt invalid IndexOf using endIndex greater than the size.
                //
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.IndexOf("Batman", 3, arrList.Count + 10));


                //[]Team Review feedback - attempt to find non-existent object and confirm that -1 returned
                arrList = new ArrayList();
                for (int i = 0; i < 10; i++)
                    arrList.Add(i);

                Assert.Equal(-1, arrList.IndexOf(50, 0, arrList.Count));
                Assert.Equal(-1, arrList.IndexOf(0, 1, arrList.Count - 1));
            }
        }
Example #39
0
        public void TestInvalidIndexOrCount()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            string[] strHeroesUnsorted = null;

            //
            // Test ascending sort.
            //
            // Construct unsorted array.
            strHeroesUnsorted = new String[strHeroes.Length];
            System.Array.Copy(strHeroes, 0, strHeroesUnsorted, 0, strHeroes.Length);

            // Sort ascending the array list.
            System.Array.Sort(strHeroesUnsorted, 0, strHeroesUnsorted.Length, new SortTests_Assending());

            // Verify ascending sort.
            for (int ii = 0; ii < strHeroesUnsorted.Length; ++ii)
            {
                Assert.Equal(0, strHeroesSorted[ii].CompareTo(strHeroesUnsorted[ii]));
            }

            //
            // Test decending sort.
            //
            // Construct unsorted array.
            strHeroesUnsorted = new String[strHeroes.Length];
            System.Array.Copy(strHeroes, 0, strHeroesUnsorted, 0, strHeroes.Length);

            // Sort decending the array list.
            System.Array.Sort(strHeroesUnsorted, 0, strHeroesUnsorted.Length, new SortTests_Decending());

            // Verify descending sort.
            for (int ii = 0; ii < strHeroesUnsorted.Length; ++ii)
            {
                Assert.Equal(0, strHeroesSorted[ii].CompareTo(strHeroesUnsorted[strHeroesUnsorted.Length - ii - 1]));
            }

            arrList = new ArrayList((ICollection)strHeroesUnsorted);

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};


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

                //
                // []  Sort array list using default comparer.
                //
                Assert.NotNull(arrList);

                // Sort decending the array list.
                arrList.Sort(0, arrList.Count, null);

                // Verify sort.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    Assert.Equal(0, strHeroesSorted[ii].CompareTo((string)arrList[ii]));
                }

                //
                // []  Bogus negative index.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.Sort(-1000, arrList.Count, null));

                //
                // []  Bogus out of bounds index.
                //
                Assert.Throws<ArgumentException>(() => arrList.Sort(1000, arrList.Count, null));

                //
                // []  Bogus negative size parmeter.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.Sort(0, -1000, null));

                //
                // []  Bogus out of bounds size parmeter.
                //
                Assert.Throws<ArgumentException>(() => arrList.Sort(0, 1000, null));
            }
        }
Example #40
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 #41
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 #42
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 #43
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 #44
0
 private Boolean runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     ArrayList alst = null;
     ArrayList tst = null;
     IList ilst1 = null;
     IList ilst2 = null;
     String strLoc = null;
     Hashtable hsh1 = null;
     IDictionaryEnumerator idic = null;
     try
     {
         strLoc = "Loc_04872dsf";
         iCountTestcases++;
         alst = new ArrayList();
         tst = ArrayList.Adapter(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         iCountTestcases++;
         if(hsh1.Count>2 
             || ((String)hsh1["Capacity"] != "get") 
             || ((String)hsh1["TrimToSize"] != "Monekeyed, 301 301") 
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_742dsf! Adapter");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<" + idic.Key + "><" + idic.Value + ">");
             }
         }
         strLoc = "Loc_210742wdsfg";
         iCountTestcases++;
         alst = new ArrayList();
         for(int i=0; i<100;i++)
             alst.Add(i);
         tst = ArrayList.Adapter(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>2 
             || ((String)hsh1["Capacity"] != "get") 
             || ((String)hsh1["TrimToSize"] != "Monekeyed, 301 301") 
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_75629ewf! Adapter");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_6927csf";
         iCountTestcases++;
         alst = new ArrayList();
         tst = ArrayList.FixedSize(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
         {
             iCountErrors++;
             Console.WriteLine("Err_0371dsf! Adapter");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_79231";
         alst = new ArrayList();
         for(int i=0; i<100;i++)
             alst.Add(i);
         tst = ArrayList.FixedSize(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         iCountTestcases++;
         if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
         {
             iCountErrors++;
             Console.WriteLine("Err_8427efs! Adapter");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_6792dsf";
         iCountTestcases++;
         ilst1 = new ArrayList();
         ilst2 = ArrayList.FixedSize(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
         {
             iCountErrors++;
             Console.WriteLine("Err_127we! FixedSize, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_7432adf";
         ilst1 = new ArrayList();
         for(int i=0; i<100; i++)
         {
             ilst1.Add(i);
         }
         ilst2 = ArrayList.FixedSize(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("Fixed"))
         {
             iCountErrors++;
             Console.WriteLine("Err_67438dsafsf! FixedSize, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_0452fgf";
         iCountTestcases++;
         alst = new ArrayList();
         tst = ArrayList.ReadOnly(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>2 
             || !hsh1.ContainsKey("IsReadOnly")
             || ((String)hsh1["BinarySearch"] != "Exception not thrown, (Object, IComparer)")  
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_752rw342! ReadOnly, ArrayList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_8342asdf";
         iCountTestcases++;
         alst = new ArrayList();
         for(int i=0; i<100;i++)
             alst.Add(i);
         tst = ArrayList.ReadOnly(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>2
             || !hsh1.ContainsKey("IsReadOnly")
             || ((String)hsh1["BinarySearch"] != "Exception not thrown, (Object, IComparer)")  
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_03482sagfdg! ReadOnly - ArrayList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_67294sf";
         iCountTestcases++;
         ilst1 = new ArrayList();
         ilst2 = ArrayList.ReadOnly(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsReadOnly"))
         {
             iCountErrors++;
             Console.WriteLine("Err_9723dvsf! ReadOnly, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_7432adf";
         iCountTestcases++;
         ilst1 = new ArrayList();
         for(int i=0; i<100; i++)
         {
             ilst1.Add(i);
         }
         ilst2 = ArrayList.ReadOnly(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsReadOnly"))
         {
             iCountErrors++;
             Console.WriteLine("Err_97213sdfs! ReadOnly, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }			
         strLoc = "Loc_945wsd";
         iCountTestcases++;
         alst = new ArrayList();
         tst = ArrayList.Synchronized(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsSynchronized"))
         {
             iCountErrors++;
             Console.WriteLine("Err_0327sdf! Synchronized, ArrayList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_8342asdf";
         alst = new ArrayList();
         for(int i=0; i<100;i++)
             alst.Add(i);
         tst = ArrayList.Synchronized(alst);
         hsh1 = new Hashtable();
         CompareObjects(alst, tst, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsSynchronized"))
         {
             iCountErrors++;
             Console.WriteLine("Err_2874s! Synchronized, ArrayList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_307ens";
         iCountTestcases++;
         ilst1 = new ArrayList();
         ilst2 = ArrayList.Synchronized(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsSynchronized"))
         {
             iCountErrors++;
             Console.WriteLine("Err_735sx! Synchronized, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_7432adf";
         ilst1 = new ArrayList();
         for(int i=0; i<100; i++)
         {
             ilst1.Add(i);
         }
         ilst2 = ArrayList.Synchronized(ilst1);
         hsh1 = new Hashtable();
         DoIListTests(ilst1, ilst2, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("IsSynchronized"))
         {
             iCountErrors++;
             Console.WriteLine("Err_9934sds! Synchronized, IList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_0732fgf";
         iCountTestcases++;
         alst = new ArrayList();
         tst = alst.GetRange(0, 0);
         hsh1 = new Hashtable();
         CompareRangeObjects(alst, tst, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("TrimToSize")
             )
         {
             Console.WriteLine("Err_0784ns! Range");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_045an";
         alst = new ArrayList();
         for(int i=0; i<100;i++)
             alst.Add(i);
         tst = alst.GetRange(0, 100);
         hsh1 = new Hashtable();
         CompareRangeObjects(alst, tst, hsh1);
         if(hsh1.Count>1 || !hsh1.ContainsKey("TrimToSize")
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_297cs! Range");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_47yv7";
         iCountTestcases++;
         Int16 i16;
         Int32 i32;
         Int64 i64;
         UInt16 ui16;
         UInt32 ui32;
         UInt64 ui64;
         Int32 iValue;
         Boolean fPass;
         i16 = 1;
         i32 = 2;
         i64 = 3;
         ui16 = 4;
         ui32 = 5;
         ui64 = 6;
         alst = new ArrayList();
         alst.Add(i16);
         alst.Add(i32);
         alst.Add(i64);
         alst.Add(ui16);
         alst.Add(ui32);
         alst.Add(ui64);
         iCountTestcases++;
         fPass = true;
         for(int i=0; i<alst.Count; i++)
         {
             if(alst.Contains(i) && i!=2)
                 fPass = false;
         }
         if(!fPass)
         {
             iCountErrors++;
             Console.WriteLine("Err_7423dsf! Unexpected value returned");
         }
         iCountTestcases++;
         fPass = true;
         iValue = 1;
         for(int i=0; i<alst.Count; i++)
         {
             if((alst.IndexOf(i)==-1)  && (i==2))
             {
                 Console.WriteLine(iValue + " " + i);
                 fPass = false;
             }
             if((alst.IndexOf(i)!=-1)  && (i!=2))
             {
                 Console.WriteLine(iValue + " " + i);
                 fPass = false;
             }
         }
         if(!fPass)
         {
             iCountErrors++;
             Console.WriteLine("Err_7423dsf! Unexpected value returned");
         }
         iCountTestcases++;
         fPass = true;
         try
         {
             alst.Sort();
             fPass = false;
         }
         catch(InvalidOperationException)
         {
         }
         catch(Exception ex)
         {
             fPass = false;
             Console.WriteLine(ex);
         }
         if(!fPass)
         {
             iCountErrors++;
             Console.WriteLine("Err_7423dsf! Unexpected value returned");
         }
     }
     catch(Exception ex)
     {
         iCountErrors++;
         Console.WriteLine("Err_3452dfsd! Unexpected exception caught! " + strLoc + " Exception, " + ex);
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }		
 }
Example #45
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int start = 3;
            int count = 15;

            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[] strResult =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Superman",
                "Thor",
                "Wildcat",
                "Wonder Woman",
            };

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

            //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;

                //
                // []  Remove range of items from array list.
                //
                // Remove range of items.
                arrList.RemoveRange(start, count);

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

                //
                // []  Attempt remove range using zero count.
                //
                // Remove range of items.
                arrList.RemoveRange(start, 0);

                // Verify size.
                Assert.Equal(strResult.Length, arrList.Count);

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

                //
                //  []  Attempt invalid RemoveRange using very large count.
                //
                Assert.Throws<ArgumentException>(() => arrList.RemoveRange(start, 10005));

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

                //
                //  []  Attempt invalid RemoveRange using negative count
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.RemoveRange(start, -1));

                //
                //  []  Attempt invalid RemoveRange using out of range index
                //
                Assert.Throws<ArgumentException>(() => arrList.RemoveRange(1000, 5));
            }
        }
Example #46
0
        public void TestArrayListWrappers01()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            // no null
            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Batman",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Batman",
                "Green Lantern",
                "Hawkman",
                "Huntress",
                "Ironman",
                "Nightwing",
                "Batman",
                "Robin",
                "SpiderMan",
                "Steel",
                "Superman",
                "Thor",
                "Batman",
                "Wildcat",
                "Wonder Woman",
                "Batman",
            };

            ArrayList arrList = null;
            int ndx = -1;

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

            //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;
                //
                // Construct array lists.
                //
                Assert.NotNull(arrList);

                //
                // []  Obtain index of "Batman" items.
                //
                int startIndex = 0;
                while (startIndex < arrList.Count && (ndx = arrList.IndexOf("Batman", startIndex)) != -1)
                {
                    Assert.True(startIndex <= ndx);

                    Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));

                    //
                    // []  Attempt to find null object.
                    //
                    // Remove range of items.
                    ndx = arrList.IndexOf(null, 0);
                    Assert.Equal(-1, ndx);

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

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

                    // []Team review feedback - query for an existing object after the index. expects -1
                    arrList.Clear();
                    for (int i = 0; i < 10; i++)
                        arrList.Add(i);

                    Assert.Equal(-1, arrList.IndexOf(0, 1));
                }
            }
        }
Example #47
0
        public void TestCopyToWithCount()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            string[] arrCopy = 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",
            };

            //
            // Construct array list.
            //
            arrList = new ArrayList();
            Assert.NotNull(arrList);

            // 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)};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Use CopyTo copy range of items to array.
                //
                int start = 3;
                int count = 15;

                // Allocate sting array.
                arrCopy = new String[100];

                // Obtain string from ArrayList.
                arrList.CopyTo(start, arrCopy, start, count);

                // Verify the items in the array.
                for (int ii = start; ii < start + count; ++ii)
                {
                    Assert.Equal(0, ((String)arrList[ii]).CompareTo(arrCopy[ii]));
                }

                //
                // []  Invalid Arguments
                //

                // 2nd throw ArgumentOutOfRangeException
                // rest throw ArgumentException 
                Assert.ThrowsAny<ArgumentException>( () => arrList.CopyTo(0, arrCopy, -100, 1000) );

                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.CopyTo(-1, arrCopy, 0, 1));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.CopyTo(0, arrCopy, 0, -1));

                // this is valid now
                arrCopy = new String[100];
                arrList.CopyTo(arrList.Count, arrCopy, 0, 0);

                Assert.Throws<ArgumentException>(() =>
                {
                    arrCopy = new String[100];
                    arrList.CopyTo(arrList.Count - 1, arrCopy, 0, 24);
                });

                Assert.Throws<ArgumentNullException>(() => arrList.CopyTo(0, null, 3, 15));

                Assert.Throws<ArgumentException>(() =>
                {
                    arrCopy = new String[1];
                    arrList.CopyTo(0, arrCopy, 3, 15);
                });

                Assert.Throws<ArgumentException>(() => arrList.CopyTo(0, new Object[arrList.Count, arrList.Count], 0, arrList.Count));
                // same as above, some iteration throws different exceptions: ArgumentOutOfRangeException
                Assert.ThrowsAny<ArgumentException>(() => arrList.CopyTo(0, new Object[arrList.Count, arrList.Count], 0, -1));
            }
        }
Example #48
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            String[] arrCopy = null;

            arrList = new ArrayList(strHeroes);

            //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;
                //
                // []  CopyTo an array normal
                //
                arrCopy = new String[strHeroes.Length];
                arrList.CopyTo(arrCopy, 0);

                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Normal Copy Test 2 - copy 0 elements
                arrList.Clear();
                arrList.Add(null);
                arrList.Add(arrList);
                arrList.Add(null);
                arrList.Remove(null);
                arrList.Remove(null);
                arrList.Remove(arrList);

                Assert.Equal(0, arrList.Count);

                arrCopy = new String[strHeroes.Length];
                // put some elements in arrCopy that should not be overriden
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    arrCopy[i] = strHeroes[i];
                }

                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, 1);

                // check to make sure sentinals stay the same
                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Normal Copy Test 3 - copy 0 elements from the end
                arrList.Clear();
                Assert.Equal(0, arrList.Count);

                arrCopy = new String[strHeroes.Length];

                // put some elements in arrCopy that should not be overriden
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    arrCopy[i] = strHeroes[i];
                }

                //copying 0 elements into arrCopy, into last valid index of arrCopy
                arrList.CopyTo(arrCopy, arrCopy.Length - 1);

                // check to make sure sentinals stay the same
                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Copy so that exception should be thrown
                arrList.Clear();
                arrCopy = new String[2];

                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, arrCopy.Length);

                // []  Copy so that exception should be thrown 2
                arrList.Clear();
                Assert.Equal(0, arrList.Count);

                arrCopy = new String[0];
                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, 0);

                // []  CopyTo with negative index
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.CopyTo(arrCopy, -1));

                // []  CopyTo with array with index is not large enough
                Assert.Throws<ArgumentException>(() =>
                    {
                        arrList.Clear();
                        for (int i = 0; i < 10; i++)
                            arrList.Add(i);

                        arrList.CopyTo(new Object[11], 2);
                    });

                // []  CopyTo with null array
                Assert.Throws<ArgumentNullException>(() => arrList.CopyTo(null, 0));

                // []  CopyTo with multidimentional array
                Assert.Throws<ArgumentException>(() => arrList.CopyTo(new Object[10, 10], 1));
            }
        }
Example #49
0
        public void TestDuplicatedItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Green Lantern",
                "Hawkman",
                "Daniel Takacs",
                "Ironman",
                "Nightwing",
                "Robin",
                "SpiderMan",
                "Steel",
                "Gene",
                "Thor",
                "Wildcat",
                null
            };

            // Construct ArrayList.
            arrList = new ArrayList(strHeroes);

            //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;
                //
                // []  IndexOf an array normal
                //
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    Assert.Equal(i, arrList.IndexOf(strHeroes[i]));
                }


                //[]  Check IndexOf when element is in list twice
                arrList.Clear();
                arrList.Add(null);
                arrList.Add(arrList);
                arrList.Add(null);

                Assert.Equal(0, arrList.IndexOf(null));

                //[]  check for something which does not exist in a list
                arrList.Clear();
                Assert.Equal(-1, arrList.IndexOf(null));
            }
        }
Example #50
0
        public void TestGetRange()
        {
            string strValue = string.Empty;

            ArrayList list;
            ArrayList range;

            //[]vanila
            list = new ArrayList();

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

            //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)list.Clone(),
                                    (ArrayList)ArrayList.Adapter(list).Clone(),
                                    (ArrayList)ArrayList.FixedSize(list).Clone(),
                                    (ArrayList)list.GetRange(0, list.Count).Clone(),
                                    (ArrayList)ArrayList.ReadOnly(list).Clone(),
                                    (ArrayList)ArrayList.Synchronized(list).Clone()
                                  };

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                list = arrayListType;

                range = list.GetRange(10, 50);
                Assert.Equal(50, range.Count);

                for (int i = 0; i < range.Count; i++)
                {
                    Assert.Equal(i + 10, (int)range[i]);
                }

                Assert.Equal(list.IsFixedSize, range.IsFixedSize);

                Assert.Equal(list.IsReadOnly, range.IsReadOnly);

                //[]we can change the underlying collection through the range and this[int index]
                if (!range.IsReadOnly)
                {

                    for (int i = 0; i < 50; i++)
                        range[i] = ((int)range[i]) + 1;

                    for (int i = 0; i < 50; i++)
                    {
                        Assert.Equal((i + 10) + 1, (int)range[i]);
                    }

                    for (int i = 0; i < 50; i++)
                        range[i] = (int)range[i] - 1;
                }

                //[]we can change the underlying collection through the range and Add
                if (!range.IsFixedSize)
                {

                    for (int i = 0; i < 100; i++)
                        range.Add(i + 1000);

                    Assert.Equal(150, range.Count);
                    Assert.Equal(200, list.Count);

                    for (int i = 0; i < 50; i++)
                    {
                        Assert.Equal(i + 10, (int)range[i]);
                    }

                    for (int i = 0; i < 100; i++)
                    {
                        Assert.Equal(i + 1000, (int)range[50 + i]);
                    }
                }

                ////[]if we change the underlying collection through set this[int index] range will start to throw
                if (list.IsReadOnly)
                {
                    Assert.Throws<NotSupportedException>(() =>
                        {
                            list[list.Count - 1] = -1;
                        });

                    Int32 iTemp = range.Count;
                }
                else
                {
                    list[list.Count - 1] = -1;

                    Assert.Throws<InvalidOperationException>(() =>
                    {
                        Int32 iTemp = range.Count;
                    });
                }

                //[]if we change the underlying collection through add range will start to throw
                range = list.GetRange(10, 50);
                if (list.IsFixedSize)
                {
                    Assert.Throws<NotSupportedException>(() =>
                    {
                        list.Add(list.Count + 1000);
                    });

                    Int32 iTemp = range.Count;
                }
                else
                {
                    list.Add(list.Count + 1000);
                    Assert.Throws<InvalidOperationException>(() =>
                    {
                        Int32 iTemp = range.Count;
                    });
                }

                //[]parm tests
                Assert.Throws<ArgumentException>(() =>
                {
                    range = list.GetRange(0, 500);
                });

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    range = list.GetRange(0, -1);
                });

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    range = list.GetRange(-1, 50);
                });

                Assert.Throws<ArgumentException>(() =>
                {
                    range = list.GetRange(list.Count, 1);
                });

                //[]we should be able to get a range of 0!
                list = new ArrayList();
                range = list.GetRange(0, 0);
                Assert.Equal(0, range.Count);
            }
        }
Example #51
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);
            }
        }
Example #52
0
        public void Test02()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            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",
            };

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

            //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)ArrayList.FixedSize(arrList).Clone(),
                                        (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                        (ArrayList)ArrayList.Synchronized(arrList).Clone()};

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

                //
                // []  Reverse entire array list.
                //
                // Reverse entire array list.
                arrList.Reverse();

                // Verify items have been reversed.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    Assert.Equal(0, strHeroes[ii].CompareTo((String)arrList[arrList.Count - ii - 1]));
                }

                //[]Team review feedback - Reversing lists of varying sizes inclusing 0
                arrList = new ArrayList();
                arrList.Reverse();

                arrList = new ArrayList();
                for (int i = 0; i < 1; i++)
                    arrList.Add(i);

                arrList.Reverse();
            }
        }
Example #53
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 #54
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 #55
0
    public void TestRange()
    {
        //[]Range
        //ArrayList changes in any way for all operation in the Range ArrayList.
        //Rather than change CompareObjects which is working for all the other collections, we will implement our version
        //of ComapreObjects for Range
        ArrayList alst = new ArrayList();
        ArrayList tst = alst.GetRange(0, 0);

        Hashtable hsh1 = new Hashtable();
        CompareRangeObjects(alst, tst, hsh1);
        Assert.True(hsh1.Count < 2);
        Assert.True(hsh1.ContainsKey("TrimToSize"));

        alst = new ArrayList();
        for (int i = 0; i < 100; i++)
            alst.Add(i);
        tst = alst.GetRange(0, 100);

        hsh1 = new Hashtable();
        CompareRangeObjects(alst, tst, hsh1);
        Assert.True(hsh1.Count < 2);
        Assert.True(hsh1.ContainsKey("TrimToSize"));
    }
Example #56
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = 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",
            };

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

            //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 values into array list.
                //
                // Insert values.
                for (ii = 0; ii < strInsert.Length; ++ii)
                {
                    arrList.Insert(start + ii, strInsert[ii]);
                }

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

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

                //
                //  []  Attempt invalid Insert using out of range index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.Insert(1000, "Batman"));
            }
        }
Example #57
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int ndx = -1;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Batman",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Batman",
                "Green Lantern",
                "Hawkman",
                "Huntress",
                "Ironman",
                "Nightwing",
                "Batman",
                "Robin",
                "SpiderMan",
                "Steel",
                "Superman",
                "Thor",
                "Batman",
                "Wildcat",
                "Wonder Woman",
                "Batman",
                null
            };

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

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

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

                //
                // []  Obtain last index of "Batman" items.
                //
                int startIndex = arrList.Count - 1;
                int tmpNdx = 0;
                while (0 < startIndex && (ndx = arrList.LastIndexOf("Batman", startIndex, startIndex + 1)) != -1)
                {
                    Assert.True(ndx <= startIndex);

                    Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));

                    tmpNdx = arrList.LastIndexOf("Batman", startIndex, startIndex - ndx + 1);
                    Assert.Equal(ndx, tmpNdx);

                    tmpNdx = arrList.LastIndexOf("Batman", startIndex, startIndex - ndx);
                    Assert.Equal(-1, tmpNdx);

                    startIndex = ndx - 1;
                }

                //
                // []  Attempt to find null object.
                //
                // Remove range of items.
                ndx = arrList.LastIndexOf(null, arrList.Count - 1, arrList.Count);
                Assert.NotEqual(-1, ndx);
                Assert.Null(arrList[ndx]);

                //
                //  []  Attempt invalid LastIndexOf using negative endindex
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", arrList.Count - 1, -1000));

                //
                //  []  Attempt invalid LastIndexOf using negative startindex
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", -1000, 0));

                //
                //  []  Attempt invalid LastIndexOf using endIndex greater than the size.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", 3, arrList.Count + 10));

                //
                //  []  Attempt invalid LastIndexOf using startIndex greater than the size.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", arrList.Count + 1, arrList.Count));

                //
                //  []  Attempt invalid LastIndexOf using count > starIndex + 1 
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", 3, 5));

                //
                //  []  Attempt LastIndexOf on empty ArrayList 
                //
                if (!arrList.IsFixedSize)
                {
                    arrList.Clear();
                    int index = arrList.LastIndexOf("", 0, 0);
                    Assert.Equal(-1, index);
                }
            }
        }
Example #58
0
        public void TestSetRange()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            ArrayList arrSetRange = null;
            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",
            };//22

            string[] strSetRange =
            {
                "Hardware",
                "Icon",
                "Johnny Quest",
                "Captain Sisko",
                "Captain Picard",
                "Captain Kirk",
                "Agent J",
                "Agent K",
                "Space Ghost",
                "Wolverine",
                "Cyclops",
                "Storm",
                "Lone Ranger",
                "Tonto",
                "Supergirl",
            };//15

            // Construct ArrayList.
            arrList = new ArrayList((ICollection)strHeroes);
            arrSetRange = new ArrayList((ICollection)strSetRange);

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

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

                // SetRange entire array list.
                arrList.SetRange(start, arrSetRange);

                // Verify set.
                for (int ii = 0; ii < arrSetRange.Count; ++ii)
                {
                    Assert.Equal(0, ((string)arrList[start + ii]).CompareTo((String)arrSetRange[ii]));
                }

                //
                // []  Attempt invalid SetRange using collection that exceed valid range.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.SetRange(start, arrList));

                //
                // []  Attempt invalid SetRange using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.SetRange(-100, arrSetRange));

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

                //
                //  []  Attempt SetRange using null collection.
                //
                Assert.Throws<ArgumentNullException>(() => arrList.SetRange(0, null));
            }
        }
Example #59
0
        public void TestSetItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

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

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

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

                //
                // []  Set item in the array list.
                //
                arrList[0] = "Lone Ranger";

                // Verify set.
                Assert.Equal(0, ((string)arrList[0]).CompareTo("Lone Ranger"));

                //
                // []  Attempt invalid Set using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[-100] = "Lone Ranger"; });

                //
                //  []  Attempt Set using out of range index=1000
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[1000] = "Lone Ranger"; });

                //
                //  []  Attempt Set using out of range index=-1
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[-1] = "Lone Ranger"; });

                //
                //  []  Attempt Set using null value.
                //
                arrList[0] = null;
                // Verify set.
                Assert.Null(arrList[0]);
            }
        }
Example #60
0
        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            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",
            };

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

            //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)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

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

                //
                // []  Reverse entire array list.
                //
                arrList.Reverse(0, arrList.Count);

                // Verify items have been reversed.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    Assert.Equal(0, strHeroes[ii].CompareTo((String)arrList[arrList.Count - ii - 1]));
                }

                //
                // []  Attempt invalid Reverse using negative index
                //
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.Reverse(-100, arrList.Count));

                //
                //  []  Attempt Reverse using out of range index
                //
                Assert.Throws<ArgumentException>(() => arrList.Reverse(1000, arrList.Count));

                //
                //  []  Attempt Reverse using negative count.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.Reverse(0, -arrList.Count));

                //
                //  []  Attempt Reverse using zero count.
                //
                arrList.Reverse(0, 0);

                // Verify no reversal (List should still be reveresed of the original.)
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    Assert.Equal(0, strHeroes[ii].CompareTo((string)arrList[arrList.Count - ii - 1]));
                }
            }
        }