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 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 #3
0
        static void Main(string[] args)
        {
            // Create an ArrayList of sets of numbers and populate it.

            ArrayList<Set<int>> array = new ArrayList<Set<int>>(
                new Set<int>[] {
                    new Set<int>(new int[] { 1, 3, 5 }),
                    new Set<int>(new int[] { 2, 4, 6 }),
                    new Set<int>(new int[] { 1, 2, 3 }) });
            Console.WriteLine(array);
            // Output: ( { 1 3 5 } { 2 4 6 } { 1 2 3 } )

            // Create a shallow clone. This means that the array is
            // duplicated but the contained sets are merely referenced.
            // Modifications to a set from the clone thus reflect in the
            // original instance as demonstrated below.

            ArrayList<Set<int>> shallowClone = array.Clone();
            Console.WriteLine(shallowClone);
            // Output: ( { 1 3 5 } { 2 4 6 } { 1 2 3 } )
            shallowClone.Add(new Set<int>(new int[] { 2, 3, 5 }));
            shallowClone[0].Add(7);
            Console.WriteLine(shallowClone);
            // Output: ( { 1 3 5 7 } { 2 4 6 } { 1 2 3 } { 2 3 5 } )
            Console.WriteLine(array);
            // Output: ( { 1 3 5 7 } { 2 4 6 } { 1 2 3 } )

            // Now create a deep clone. The array and its contents are
            // all duplicated.

            ArrayList<Set<int>> deepClone = array.DeepClone();
            Console.WriteLine(deepClone);
            // Output: ( { 1 3 5 7 } { 2 4 6 } { 1 2 3 } )
            deepClone.Add(new Set<int>(new int[] { 2, 3, 5 }));
            deepClone[0].Add(9);
            Console.WriteLine(deepClone);
            // Output: ( { 1 3 5 7 9 } { 2 4 6 } { 1 2 3 } { 2 3 5 } )
            Console.WriteLine(array);
            // Output: ( { 1 3 5 7 } { 2 4 6 } { 1 2 3 } )
        }
Example #4
0
        /// <summary>
        /// Cancels all list effects
        /// </summary>
        public void CancelAll(bool leaveself)
        {
            ArrayList spells = null;

            if (m_concSpells == null)
            {
                return;
            }
            spells = (ArrayList)m_concSpells.Clone();
            BeginChanges();
            if (spells != null)
            {
                foreach (IConcentrationEffect fx in spells)
                {
                    if (!leaveself || leaveself && fx.OwnerName != m_owner.Name)
                    {
                        fx.Cancel(false);
                    }
                }
            }
            CommitChanges();
        }
Example #5
0
        /// <summary> This method splits the node into four branch, and disperses
        /// the items into the branch. The split only happens if the
        /// boundary size of the node is larger than the minimum size (if
        /// we care). The items in this node are cleared after they are put
        /// into the branch.
        /// </summary>
        protected internal void split()
        {
            // Make sure we're bigger than the minimum, if we care,
            if (minSize != NO_MIN_SIZE)
            {
                if (Math.Abs(bounds.Top - bounds.Bottom) < minSize &&
                    Math.Abs(bounds.Right - bounds.Left) < minSize &&
                    Math.Abs(bounds.Front - bounds.Back) < minSize)
                {
                    return;
                }
            }

            float nsHalf = (float)(bounds.Top - (bounds.Top - bounds.Bottom) * 0.5);
            float ewHalf = (float)(bounds.Right - (bounds.Right - bounds.Left) * 0.5);
            float fbHalf = (float)(bounds.Front - (bounds.Front - bounds.Back) * 0.5);

            branch = new OctreeNode[8];

            branch[0] = new OctreeNode(ewHalf, bounds.Left, bounds.Front, fbHalf, bounds.Top, nsHalf, maxItems); //left-front-top
            branch[1] = new OctreeNode(bounds.Right, ewHalf, bounds.Front, fbHalf, bounds.Top, nsHalf, maxItems);
            branch[2] = new OctreeNode(ewHalf, bounds.Left, bounds.Front, fbHalf, nsHalf, bounds.Bottom, maxItems);
            branch[3] = new OctreeNode(bounds.Right, ewHalf, bounds.Front, fbHalf, nsHalf, bounds.Bottom, maxItems);

            branch[4] = new OctreeNode(ewHalf, bounds.Left, fbHalf, bounds.Back, bounds.Top, nsHalf, maxItems); //left-back-top
            branch[5] = new OctreeNode(bounds.Right, ewHalf, fbHalf, bounds.Back, bounds.Top, nsHalf, maxItems);
            branch[6] = new OctreeNode(ewHalf, bounds.Left, fbHalf, bounds.Back, nsHalf, bounds.Bottom, maxItems);
            branch[7] = new OctreeNode(bounds.Right, ewHalf, fbHalf, bounds.Back, nsHalf, bounds.Bottom, maxItems);

            ArrayList temp = (ArrayList)items.Clone();

            items.Clear();
            IEnumerator things = temp.GetEnumerator();

            while (things.MoveNext())
            {
                AddNode((OctreeLeaf)things.Current);
            }
        }
Example #6
0
        public static ArrayList getPossibleRoomsRelTimeSlot(ArrayList possibleRooms, int indexRow, int indexCol)
        {
            ArrayList possibleRoomsCopy = (ArrayList)possibleRooms.Clone();

            foreach (Room room in possibleRooms)
            {
                if (room.getAllowedTimeSlots()[indexRow, indexCol] == true)
                {
                    foreach (EduProgramGroup epg in AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes)
                    {
                        foreach (EduProgram ep in epg.Nodes)
                        {
                            ArrayList [,] eptt = ep.getTimetable();
                            ArrayList lessonsInOneTimeSlot = eptt[indexRow, indexCol];
                            if (lessonsInOneTimeSlot != null)
                            {
                                foreach (Object [] courseAndRoomPair in lessonsInOneTimeSlot)
                                {
                                    Room roomFromModel = (Room)courseAndRoomPair[1];
                                    if (roomFromModel == room)
                                    {
                                        possibleRoomsCopy.Remove(room);
                                        goto stop;
                                    }
                                }
                            }
                        }
                    }

                    stop :;
                }
                else
                {
                    possibleRoomsCopy.Remove(room);
                }
            }

            return(possibleRoomsCopy);
        }
Example #7
0
        public GameState getMove(GameState state, int x, int y)
        {
            GameState  retVal   = null;
            XYLocation loc      = new XYLocation(x, y);
            ArrayList  moves    = getMoves(state);
            ArrayList  newMoves = (ArrayList)moves.Clone();

            if (moves.Contains(loc))
            {
                //int index = newMoves.indexOf(loc);
                int index = newMoves.IndexOf(loc);
                //newMoves.Remove(index);
                //.remove function is not overloaded in .net like it is in java
                //in .NET .remove only removes the instance of the parameter,
                //not the object at the index
                newMoves.RemoveAt(index);

                retVal = new GameState();

                retVal.put("moves", newMoves);
                TicTacToeBoard newBoard = getBoard(state).cloneBoard();
                if (getPlayerToMove(state) == "X")
                {
                    newBoard.markX(x, y);
                    retVal.put("player", "O");
                }
                else
                {
                    newBoard.markO(x, y);
                    retVal.put("player", "X");
                }
                retVal.put("board", newBoard);
                retVal.put("utility", computeUtility(newBoard,
                                                     getPlayerToMove(getState())));
                retVal.put("level", getLevel(state) + 1);
                //presentState = retVal;
            }
            return(retVal);
        }
Example #8
0
    protected internal void Split()
    {
        // Make sure we're bigger than the minimum, if we care,
        if (MinSize != NoMinSize)
        {
            if (Math.Abs(Bounds.Top - Bounds.Bottom) < MinSize &&
                Math.Abs(Bounds.Right - Bounds.Left) < MinSize &&
                Math.Abs(Bounds.Front - Bounds.Back) < MinSize)
            {
                return;
            }
        }

        var nsHalf = (float)(Bounds.Top - (Bounds.Top - Bounds.Bottom) * 0.5);
        var ewHalf = (float)(Bounds.Right - (Bounds.Right - Bounds.Left) * 0.5);
        var fbHalf = (float)(Bounds.Front - (Bounds.Front - Bounds.Back) * 0.5);

        Branch = new OctreeNode[8];

        Branch[0] = new OctreeNode(ewHalf, Bounds.Left, Bounds.Front, fbHalf, Bounds.Top, nsHalf, MaxItems); //left-front-top
        Branch[1] = new OctreeNode(Bounds.Right, ewHalf, Bounds.Front, fbHalf, Bounds.Top, nsHalf, MaxItems);
        Branch[2] = new OctreeNode(ewHalf, Bounds.Left, Bounds.Front, fbHalf, nsHalf, Bounds.Bottom, MaxItems);
        Branch[3] = new OctreeNode(Bounds.Right, ewHalf, Bounds.Front, fbHalf, nsHalf, Bounds.Bottom, MaxItems);

        Branch[4] = new OctreeNode(ewHalf, Bounds.Left, fbHalf, Bounds.Back, Bounds.Top, nsHalf, MaxItems); //left-back-top
        Branch[5] = new OctreeNode(Bounds.Right, ewHalf, fbHalf, Bounds.Back, Bounds.Top, nsHalf, MaxItems);
        Branch[6] = new OctreeNode(ewHalf, Bounds.Left, fbHalf, Bounds.Back, nsHalf, Bounds.Bottom, MaxItems);
        Branch[7] = new OctreeNode(Bounds.Right, ewHalf, fbHalf, Bounds.Back, nsHalf, Bounds.Bottom, MaxItems);

        var temp = (ArrayList)Items.Clone();

        Items.Clear();
        var things = temp.GetEnumerator();

        while (things.MoveNext())
        {
            AddNode((OctreeLeaf)things.Current);
        }
    }
Example #9
0
    void Update()
    {
        if (ExceptionsReporting)
        {
            if (_handledLogEvents.Count > 0)
            {
                var eventsToReport = (ArrayList)_handledLogEvents.Clone();
                foreach (LogEvent handledLog in eventsToReport)
                {
                    Instance.ReportError(handledLog.Condition, handledLog.StackTrace);
                    _handledLogEvents.Remove(handledLog);
                }
            }

            var reports = CrashReport.reports;
            foreach (var report in reports)
            {
                Instance.ReportError(report.text, string.Format("Time: {0}", report.time));
                report.Remove();
            }
        }
    }
Example #10
0
        static void Main()
        {
            ArrayList onj = new ArrayList();

            // List<string> onj = new List<string>();

            onj.Add("onj");
            onj.Add("OracleJava");
            onj.Add("Community");

            Console.WriteLine("onj list");
            Console.WriteLine("Count :     {0}", onj.Count);
            Console.WriteLine("Capacity :  {0}", onj.Capacity);

            Console.WriteLine("onj values");
            PrintValue(onj);

            ArrayList onj2 = (ArrayList)onj.Clone();

            Console.Write("onj2 values");
            PrintValue(onj2);
        }
Example #11
0
 public void SimulateTornament(ArrayList participants)
 {
     playersLeft = (System.Collections.ArrayList)participants.Clone();
     setupTornament(playersLeft);
     while (playersLeft.Count > 1)
     {
         playHand();
         if (handsCurrentLevel < playersLeft.Count)
         {
             handsCurrentLevel++;
         }
         else
         {
             blindLevel       *= 2;
             handsCurrentLevel = 0;
         }
     }
     if (1 == playersLeft.Count)
     {
         ((Participant)playersLeft[0]).bustedOut(1, (int)prizeStructure[0]);
     }
 }
Example #12
0
        /// <summary>
        /// Create iFolders
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        private static ArrayList CreateiFolders(ArrayList users)
        {
            ArrayList ifolders = new ArrayList();

            // personal ifolders
            foreach (string user in users)
            {
                string id = CreateiFolder("Personal", user);
                if (id != null)
                {
                    ifolders.Add(id);
                }
            }

            // shared ifolders
            ArrayList temp = (ArrayList)users.Clone();

            temp.Sort();
            Stack stack = new Stack(temp);

            int count = (users.Count / ifolderNames.Length) - 2;

            foreach (string name in ifolderNames)
            {
                string id = CreateiFolder(name, (string)stack.Pop());
                if (id != null)
                {
                    ifolders.Add(id);
                }

                for (int i = 0; i < count; i++)
                {
                    ShareiFolder(id, (string)stack.Pop());
                }
            }

            return(ifolders);
        }
Example #13
0
    private void startFiltering()
    {
        shownArray.Clear();
        if (!filteringToggle)
        {
            for (int i = 0; i < notificationArray.Count; i++)
            {
                Notification temp = (Notification)notificationArray[i];
                if (!filter.Equals(temp.getApplicationString(), StringComparison.OrdinalIgnoreCase))
                {
                    shownArray.Add(temp);
                }
            }
            filteringToggle = !filteringToggle;
        }
        else
        {
            shownArray      = (ArrayList)notificationArray.Clone();
            filteringToggle = !filteringToggle;
        }
        if (sortApplicationAsc)
        {
            shownArray.Sort(new notifcationApplicationAscendingComparer());

            if (sortMessage)
            {
                shownArray.Sort(new notificationMessageAscendingComparer());
            }
        }
        else
        {
            shownArray.Sort(new notifcationApplicationDescendingComparer());
            if (sortMessage)
            {
                shownArray.Sort(new notificationMessageDescendingComparer());
            }
        }
    }
Example #14
0
        public void Update(long tick)
        {
            ArrayList temp;

            lock (m_actions)
            {
                temp = (ArrayList)m_actions.Clone();
                m_actions.Clear();
            }

            if (temp != null && GameState != eGameState.Stopped)
            {
                if (temp.Count > 0)
                {
                    ArrayList left = new ArrayList();
                    foreach (IAction action in temp)
                    {
                        try
                        {
                            action.Execute(this, tick);
                            if (action.IsFinish() == false)
                            {
                                left.Add(action);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Map update error:", ex);
                        }
                    }
                    AddAction(left);
                }
                else if (m_waitTimer < tick)
                {
                    CheckState(0);
                }
            }
        }
Example #15
0
        /// <summary>
        /// <see cref="CurveItem"/> constructor the pre-specifies the curve label and the
        /// x and y data arrays.  All other properties of the curve are
        /// defaulted to the values in the <see cref="Def"/> class.
        /// </summary>
        /// <param name="label">A string label (legend entry) for this curve</param>
        /// <param name="x">A array of double precision values that define
        /// the independent (X axis) values for this curve</param>
        /// <param name="y">A array of double precision values that define
        /// the dependent (Y axis) values for this curve</param>
        public CurveItem(string label, ArrayList x, ArrayList y, ArrayList cl, ArrayList sym)
        {
            this.line     = new Line();
            this.symbol   = new Symbol();
            this.label    = label;
            this.isY2Axis = false;
            //-		-----------------
            this.X   = new ArrayList();
            this.Y   = new ArrayList();
            this.CL  = new ArrayList();
            this.SYM = new ArrayList();
            this.mblnIsScatteredPointsCurve = false;
            this.ScatteredPoints            = new ArrayList();

            //-		-----------------
            if (x.Count > 0)
            {
                this.X = (ArrayList)x.Clone();
            }
            if (y.Count > 0)
            {
                this.Y = (ArrayList)y.Clone();
            }
            if (cl.Count > 0)
            {
                this.CL = (ArrayList)cl.Clone();
            }
            if (sym.Count > 0)
            {
                this.SYM = (ArrayList)sym.Clone();
            }

            //----- Added by Sachin Dokhale
            IsHighPeakLine = false;
            HighPeakXValue = 0.0;
            HighPeakYValue = 0.0;
            //-----
        }
Example #16
0
    public RoadNode(int idx, Transform prevChunk, float prevRotY, int prevCost, RoadCreator creator, ArrayList pathUntilNow, Transform destiny)
    {
        this.creator = creator;

        this.chunkIdx=idx;

        this.destination = destiny;

        this.pathUntilNow = (ArrayList)pathUntilNow.Clone();
        this.pathUntilNow.Add(chunkIdx);

        GameObject currentChunk = UnityEngine.Object.Instantiate (creator.roadChunks[chunkIdx]) as GameObject;
        currentChunk.collider.enabled=false;
        currentChunk.name= "Astar";
        currentChunk.tag="starchunk";
        this.overlap = creator.putChunk(prevChunk, prevRotY, currentChunk);

        this.mountPoint = currentChunk.GetComponent<RoadChunk>().mountPoint;

        this.costSoFar = prevCost + Mathf.Abs((int)(this.mountPoint.transform.localPosition.x)) + Mathf.Abs((int)(this.mountPoint.transform.localPosition.z));

        this.rotY = prevRotY + mountPoint.localRotation.eulerAngles.y;
    }
Example #17
0
File: Matrix.cs Project: ikvm/test
        public object Clone()
        {
            object obj2;

            try
            {
                Matrix matrix = (Matrix)base.MemberwiseClone();
                matrix.arrayList_0 = (ArrayList)this.arrayList_0.Clone();
                for (int i = 0; i < this.arrayList_0.Count; i++)
                {
                    ArrayList list = (ArrayList)this.arrayList_0[i];
                    //matrix.arrayList_0[i];
                    matrix.arrayList_0[i] = list.Clone();
                }
                Matrix matrix2 = matrix;
                obj2 = matrix2;
            }
            catch (Exception exception)
            {
                throw new ReportError(exception.Message, exception);
            }
            return(obj2);
        }
        public virtual void  fireEvents(int type, ArrayList listeners)
        {
            ArrayList targets = null;
            Listener  l       = null;

            lock (this)
            {
                if (listeners == null)
                {
                    return;
                }
                targets = (ArrayList)listeners.Clone();
            }

            if (targets != null)
            {
                for (var i = 0; i < targets.Count; i++)
                {
                    l = (Listener)targets[i];
                    fireEvent(type, l);
                }
            }
        }
Example #19
0
        public void Clone()
        {
            lista.Add(2);
            lista.Add(3);
            lista.Add(4);
            lista.Add(7.5);
            lista.Add(4);
            lista.Add("H");
            lista.Add("U");
            lista.Add("J");
            lista.Add(67);
            lista.Add(23);
            lista.Add(9);
            lista.Add(80);

            ArrayList nuevaList = (ArrayList)lista.Clone();

            Console.WriteLine("Imprimiendo desde la nueva lista generada\n");
            foreach (var item in nuevaList)
            {
                Console.WriteLine(item);
            }
        }
Example #20
0
        private void cmdShuffle_Click(object sender, EventArgs e)
        {
            bmpsave1 = new Bitmap(pnlSort1.Width, pnlSort1.Height);
            g1       = Graphics.FromImage(bmpsave1);

            bmpsave2 = new Bitmap(pnlSort2.Width, pnlSort2.Height);
            g2       = Graphics.FromImage(bmpsave2);

            pnlSort1.Image = bmpsave1;
            pnlSort2.Image = bmpsave2;


            array1 = new ArrayList(tbSamples.Value);
            array2 = new ArrayList(tbSamples.Value);
            for (int i = 0; i < array1.Capacity; i++)
            {
                int y = (int)((double)i / array1.Capacity * pnlSort1.Height);
                array1.Add(y);
            }
            Randomize(array1);
            array2 = (ArrayList)array1.Clone();
            DrawSamples();
        }
Example #21
0
        //devuelve el contenido de cada fila en un arraylist. cada posicion del arraylist es otro arraylist
        public ArrayList tomarFilas()
        {
            ArrayList data     = new ArrayList();
            int       numfilas = Rows.Count;

            if (numfilas == 0)
            {
                return(data); //array vacio
            }
            for (int i = 0; i < numfilas; i++)
            {
                DataGridViewRow r         = (DataGridViewRow)this.Rows[i].Clone();
                int             numceldas = r.Cells.Count;
                ArrayList       datatmp   = new ArrayList();
                for (int j = 0; j < numceldas; j++)
                {
                    datatmp.Add(r.Cells[j].Value);
                }
                ArrayList data2 = (ArrayList)datatmp.Clone();
                data.Add(data2);
            }
            return(data); //array con valores
        }
Example #22
0
        public void TestArrayList()
        {
            ArrayList oriList = new ArrayList {
                "cheka", "KGB", "Stasi"
            };
            int       oriCount = oriList.Count;
            ArrayList cpyList  = (ArrayList)oriList.Clone();

            Assert.AreNotSame(cpyList, oriList);
            Assert.AreEqual(oriCount, cpyList.Count);

            // just a shallow copy for each element
            for (int index = 0; index < oriList.Count; ++index)
            {
                Assert.AreSame(cpyList[index], oriList[index]);
            }

            // but the two list it self pointing to different place
            // so remove or add one will not affect the other
            cpyList.RemoveAt(cpyList.Count - 1);
            Assert.AreEqual(oriCount - 1, cpyList.Count);
            Assert.AreEqual(oriCount, oriList.Count);
        }
        private Lua GetLua()
        {
            Lua lua = new Lua();

            lua.DoString($"POS_X = {StartPoint.X}");
            lua.DoString($"POS_Y = {StartPoint.Y}");
            lua.DoString($"TARGET_X = {EndPoint.X}");
            lua.DoString($"TARGET_Y = {EndPoint.Y}");
            lua.DoString($"FRAME = {PointCount}");
            lua.DoString($"MODE = {(int)MoveType}");
            lua.DoString("yield = coroutine.yield");
            lua.DoString("POINTLIST = {}");
            var t     = lua.GetTable("POINTLIST");
            var index = 1;

            foreach (Point p in (ArrayList)PointList.Clone())
            {
                t[index]     = p.X;
                t[index + 1] = p.Y;
                index       += 2;
            }
            return(lua);
        }
Example #24
0
        public void Begin()
        {
            pendingUrlDownloads = downloads.Count;

            foreach (string fileId in downloads)
            {
                RequestAndAddDownload(fileId);
            }

                        #if UNITY_STANDALONE
            //Remove downloadeds
            ArrayList tmpDownloads = (ArrayList)downloads.Clone();
            downloads.Clear();
            foreach (string fileId in tmpDownloads)
            {
                if (!downloadeds.Contains(fileId))
                {
                    downloads.Add(fileId);
                }
            }
            downloadeds.Clear();
                        #endif
        }
Example #25
0
        private ArrayList GetParseTrees()
        {
            ArrayList rootEdges  = null;
            ArrayList parseRoots = null;
            ArrayList parseTrees = null;

            if (SearchEdge(0, Words.Count, Words.Count, "S'", out rootEdges))
            {
                parseRoots = ParseTreesOf((Edge)rootEdges[0]);
            }
            if (parseRoots == null)
            {
                return(null);
            }
            parseTrees = new ArrayList();
            for (int i = 0; i < parseRoots.Count; i++)
            {
                ParseNode root = (ParseNode)((ParseNode)parseRoots[i]).Children[0];
                LinkParents(root);
                parseTrees.Add(new ParseTree(root, (ArrayList)Words.Clone()));
            }
            return(parseTrees);
        }
Example #26
0
        private static bool Pump()
        {
            ArrayList MyMessageFilters = new ArrayList();

            // there are, so get the top one
            if (NativeMethods.GetMessage(out msg, IntPtr.Zero, 0, 0))
            {
                process          = true;
                MyMessageFilters = (ArrayList)(messageFilters.Clone());
                // iterate any filters
                lock (messageFilters.SyncRoot)
                {
                    foreach (NativeMethods.IMessageFilter mf in MyMessageFilters)
                    {
#if !NDOC && !DESIGN
                        Message m = Message.Create(msg.hwnd, msg.message, msg.wParam, msg.lParam);

                        // if *any* filter says not to process, we won't
                        process = process ? !(mf.PreFilterMessage(ref m)) : false;
#endif
                    }

                    // if we're supposed to process the message, do so
                    if (process)
                    {
                        NativeMethods.TranslateMessage(out msg);
                        NativeMethods.DispatchMessage(ref msg);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #27
0
        public override void Update(GameTime gameTime)
        {
            var collidables2      = (ArrayList)collidables.Clone();
            var finishedColliding = new ArrayList();

            foreach (Basic c in collidables2)
            {
                if (!c.IsCollidable)
                {
                    continue;
                }
                foreach (Basic c2 in collidables2)
                {
                    var t = new Tuple <Basic, Basic>(c, c2);
                    if (finishedColliding.Contains(t))
                    {
                        continue;
                    }
                    finishedColliding.Add(new Tuple <Basic, Basic>(c, c2));
                    finishedColliding.Add(new Tuple <Basic, Basic>(c2, c));

                    if (c == c2 || !c.IsCollidable || !c2.IsCollidable)
                    {
                        continue;
                    }

                    if (!c.BoundingSphere.Intersects(c2.BoundingSphere))
                    {
                        continue;
                    }

                    c.CollidesWith(c2);
                    c2.CollidesWith(c);
                }
            }
            base.Update(gameTime);
        }
Example #28
0
        static void Main(string[] args)
        {
            //treba napisati program koji ce traziti unos 10 elemenata
            //zatim ih ispisuje naopako
            Console.WriteLine("Unesite 10 elemenata!");
            ArrayList arr = new ArrayList();

            for (int i = 0; i < 10; i++)
            {
                arr.Add(Console.ReadLine());
            }
            ArrayList arr2 = new ArrayList();


            Console.WriteLine("Vaša originalna lista: ");
            foreach (var item in arr)
            {
                Console.Write(item + " ");
            }
            arr2 = (ArrayList)arr.Clone();
            arr.Reverse();

            Console.WriteLine("");
            Console.WriteLine("Vaša originalna lista okrenuta naopako: ");
            foreach (var item in arr)
            {
                Console.Write(item + " ");
            }
            Console.ReadLine();

            Console.WriteLine("Klonirana");
            foreach (var item in arr2)
            {
                Console.Write(item + " ");
            }
            Console.ReadLine();
        }
Example #29
0
        private void tryDownloading()
        {
            int totalDownloads = this.getPendingDownloads();

            if (totalDownloads == 0)
            {
                this.informDelegateThatDownloadsAreDone();
                return;
            }

            if (this.countUnstartedDownloads() > 0 && this.countActiveDownloads() < this._maxConcurrentDownloads)
            {
                foreach (Download download in _downloads)
                {
                    if (!download.isDownloading())
                    {
                        download.Start();
                    }
                }

                                #if UNITY_STANDALONE
                //Remove downloadeds
                ArrayList tmpDownloads = (ArrayList)_downloads.Clone();
                _downloads.Clear();
                foreach (Download download in tmpDownloads)
                {
                    if (!_downloadeds.Contains(download))
                    {
                        _downloads.Add(download);
                    }
                }
                _downloadeds.Clear();

                this.tryDownloading();
                                #endif
            }
        }
Example #30
0
 private void CheckStopLevel()
 {
     if (chkShowCurrentLevel.Checked)
     {
         SetText("Current Level=" + CurrentLevel.ToString() + "  With only " + NotUniqueSetsPrevLevel.Count + " Not Unique Starting sets  were found in level" + (CurrentLevel - 1).ToString() + " and nonesense sets=" + NrOfNonesenseSets.ToString() + " with percentage=" + (100 * (double)NrOfNonesenseSets / (double)NotUniqueSetsPrevLevel.Count).ToString() + "  At Time:" + DateTime.Now.ToString() + Environment.NewLine);
         System.Diagnostics.Debug.Write("Current Level=" + CurrentLevel.ToString() + "  With only " + NotUniqueSetsPrevLevel.Count + " Not Unique Starting sets  were found in level" + (CurrentLevel - 1).ToString() + " and nonesense sets=" + NrOfNonesenseSets.ToString() + " with percentage=" + (100 * (double)NrOfNonesenseSets / (double)NotUniqueSetsPrevLevel.Count).ToString() + "  At Time:" + DateTime.Now.ToString() + Environment.NewLine);
         NrOfNonesenseSets = 0;
     }
     PublicNotUniq.Clear();
     tmpNUList = (ArrayList)NotUniqueSetsPrevLevel.Clone();
     NrOfNotUniqueThatWillBeChecked = 0;
     NotUniqueSetsPrevLevel.Clear();
     for (int k = 0; k < tmpNUList.Count; k++)
     {
         List <NotUniqueSet> temp = new List <NotUniqueSet>();
         PublicNotUniq.Add(temp);
         ArrayList tt = new ArrayList();
         PublicUniq.Add(tt);
     }
     Parallel.For(0, tmpNUList.Count, new ParallelOptions {
         MaxDegreeOfParallelism = 32
     }, i =>
     {
         //for (int i = 0; i < tmpNUList.Count; i++)
         //{
         NotUniqueSet pl1        = (NotUniqueSet)tmpNUList[i];
         ArrayList OldSetIndices = (ArrayList)pl1._NotUniqueSetIndexes.Clone();
         for (int j = SkipperListComplement.IndexOf(pl1._NotUniqueSet[pl1._NotUniqueSet.Count - 1]) + 1; j < SkipperListComplement.Count; j++)
         {
             pl1._NotUniqueSet.Add(SkipperListComplement[j]);
             pl1._NotUniqueSetIndexes = (ArrayList)OldSetIndices.Clone();
             IsUnique(pl1, i);
             pl1._NotUniqueSet.RemoveAt(pl1._NotUniqueSet.Count - 1);
         }
         tmpNUList[i] = null;
     });
 }
        public virtual void Characters(char[] ch, int start, int length)
        {
            StringBuilder chars = new StringBuilder(length);

            chars.Append(ch, start, length);
            String word = ReadToken(chars);

            while (word != null)
            {
                switch (currElement)
                {
                case ELEM_CLASSES: {
                    // System.out.println("\"" + word + "\"");
                    consumer.AddClass(word);
                    break;
                }

                case ELEM_EXCEPTIONS: {
                    exception.Add(word);
                    exception = NormalizeException(exception);
                    consumer.AddException(GetExceptionWord(exception), (ArrayList)exception.Clone());
                    exception.Clear();
                    break;
                }

                case ELEM_PATTERNS: {
                    consumer.AddPattern(GetPattern(word), GetInterletterValues(word));
                    break;
                }

                default: {
                    break;
                }
                }
                word = ReadToken(chars);
            }
        }
Example #32
0
        private void PrivateTestReverse(ArrayList arrayList)
        {
            ArrayList arrayList2;

            for (int x = 1; x < 100; x++)
            {
                arrayList2 = (ArrayList)arrayList.Clone();

                for (int i = 0; i < x; i++)
                {
                    arrayList2.Add(i);
                }

                arrayList2.Reverse();

                bool ok = true;

                // Check that reverse did reverse the adapter.

                for (int i = 0; i < x; i++)
                {
                    if ((int)arrayList2[i] != x - i - 1)
                    {
                        ok = false;

                        break;
                    }
                }

                Assertion.Assert
                (
                    String.Format("Reverse on arrayList failed on list with {0} items.", x),
                    ok
                );
            }
        }
Example #33
0
        /// <summary>
        /// accepts the connection of the given socket
        /// </summary>
        /// <param name="sock">the socket to accept</param>
        private static void AcceptConnections(Object sock)
        {
            Socket socket = (Socket)sock;

            try
            {
                while (true)
                {
                    //blocking call
                    Socket     clientSocket = socket.Accept();
                    Connection session      = new Connection(clientSocket);
                    RegisterConnection(session);
                }
            }
            catch
            {
                //prevent problems when sessions unregister themselves from the list during close
                ArrayList tmpList = (ArrayList)connectionList.Clone();
                foreach (Connection session in tmpList)
                {
                    session.Close();
                }
            }
        }
Example #34
0
        /// <summary> Multicast a message request to all members in <code>dests</code> and receive responses via the RspCollector
        /// interface. When done receiving the required number of responses, the caller has to call done(req_id) on the
        /// underlyinh RequestCorrelator, so that the resources allocated to that request can be freed.
        ///
        /// </summary>
        /// <param name="dests"> The list of members from which to receive responses. Null means all members
        /// </param>
        /// <param name="req_id">The ID of the request. Used by the underlying RequestCorrelator to correlate responses with
        /// requests
        /// </param>
        /// <param name="msg">   The request to be sent
        /// </param>
        /// <param name="coll">  The sender needs to provide this interface to collect responses. Call will return immediately if
        /// this is null
        /// </param>
        public virtual void  castMessage(ArrayList dests, long req_id, Message msg, RspCollector coll)
        {
            ArrayList real_dests;

            if (msg == null)
            {
                NCacheLog.Error("MsgDispatcher.castMessage()", "request is null");
                return;
            }

            if (coll == null)
            {
                NCacheLog.Error("MessageDispatcher.castMessage()", "response collector is null (must be non-null)");
                return;
            }

            // we need to clone because we don't want to modify the original
            // (we remove ourselves if LOCAL is false, see below) !
            real_dests = dests != null?(ArrayList)dests.Clone():(ArrayList)channel.View.Members.Clone();

            // if local delivery is off, then we should not wait for the message from the local member.
            // therefore remove it from the membership
            if (channel != null && channel.getOpt(Channel.LOCAL).Equals(false))
            {
                real_dests.Remove(channel.LocalAddress);
            }

            // don't even send the message if the destination list is empty
            if (real_dests.Count == 0)
            {
                NCacheLog.Debug("MsgDispatcher.castMessage()", "destination list is empty, won't send message");
                return;
            }

            corr.sendRequest(req_id, real_dests, msg, coll);
        }
Example #35
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 #36
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]));
                }
            }
        }
Example #37
0
    private bool rExistsPathFromPosToPos(Position start, Position end, ref ArrayList positions, ref ArrayList visited, ref ArrayList allPossiblePaths, ref int shortestPathLength)
    {
        __nCalls++;
        if (positions.Count >= shortestPathLength) {
            return false;
        }

        bool isValid = false;

        // CASES TO IGNORE
        int mapRows = MapScript.sharedInstance ().getNRows ();
        int mapColumns = MapScript.sharedInstance ().getNColumns ();
        bool ignore = (!start.isInRange (mapRows, mapColumns));
        if (!ignore) {
            ignore = (this.positionIsBlocked (start));
            if (!ignore) {
                int i = 0;
                while (!ignore && i<visited.Count) {
                    Position visitedPos = (Position)visited [i];
                    ignore = (visitedPos.isEqualTo (start));
                    i++;
                }
            }
        }

        int v = visited.Count;
        visited.Add (start);

        if (ignore) {
            isValid = false;
        } else {
            // POSITION MAY BE VALID

            int p = positions.Count;
            positions.Add (start);

            bool isFinished = (start.isEqualTo (end));

            if (isFinished) {
                isValid = true;
                if (positions.Count < shortestPathLength) {
                    shortestPathLength = positions.Count;
                    allPossiblePaths.Add (positions.Clone ());
                }

            } else {

                Position next;

                ArrayList directions = new ArrayList (4);
                directions.Add (Direction.kRight);
                directions.Add (Direction.kUp);
                directions.Add (Direction.kLeft);
                directions.Add (Direction.kDown);

                int i = 0;
                while (i < directions.Count) {
                    Direction dir = (Direction)directions [i];
                    next = start.move (dir);
                    isValid |= this.rExistsPathFromPosToPos (next, end, ref positions, ref visited, ref allPossiblePaths, ref shortestPathLength);
                    i++;
                }

            }

            positions.RemoveAt (p);

        }
        visited.RemoveAt (v);
        return isValid;
    }
Example #38
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 #39
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 #40
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 #41
0
        public void TestCloneBasic()
        {
            ArrayList alst1;
            ArrayList alst2;

            String strValue;
            Object oValue;

            //[] Vanila test case - Clone should exactly replicate a collection to another object reference
            //afterwards these 2 should not hold the same object references

            alst1 = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                alst1.Add(strValue);
            }

            alst2 = (ArrayList)alst1.Clone();

            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                Assert.Equal(strValue, (String)alst2[i]);
            }

            //now we remove an object from the original list
            alst1.RemoveAt(9);
            Assert.Throws<ArgumentOutOfRangeException>(() => { oValue = alst1[9]; });

            strValue = "String_" + 9;
            Assert.Equal(strValue, (String)alst2[9]);

            //[]now we try other test cases
            //are all the 'other' properties of the arraylist the same?

            alst1 = new ArrayList(1000);
            alst2 = (ArrayList)alst1.Clone();

            // Capacity is not expected to be the same
            Assert.NotEqual(alst1.Capacity, alst2.Capacity);
            Assert.Equal(alst1.Count, alst2.Count);
            Assert.Equal(alst1.IsReadOnly, alst2.IsReadOnly);
            Assert.Equal(alst1.IsSynchronized, alst2.IsSynchronized);

            //[]Clone is a shallow copy, so the objects of the objets reference should be the same
            alst1 = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                alst1.Add(new Foo());
            }

            alst2 = (ArrayList)alst1.Clone();
            strValue = "Hello World";
            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(strValue, ((Foo)alst2[i]).strValue);
            }

            strValue = "Good Bye";
            ((Foo)alst1[0]).strValue = strValue;
            Assert.Equal(strValue, ((Foo)alst1[0]).strValue);
            Assert.Equal(strValue, ((Foo)alst2[0]).strValue);

            //[]if we change the object, of course, the previous should not happen
            alst2[0] = new Foo();

            strValue = "Good Bye";
            Assert.Equal(strValue, ((Foo)alst1[0]).strValue);

            strValue = "Hello World";
            Assert.Equal(strValue, ((Foo)alst2[0]).strValue);
        }
Example #42
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 #43
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 #44
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 #45
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 #46
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 #47
0
 public Boolean runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc="123_er";
   Console.Out.Write( s_strClassMethod );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strTFPath + s_strTFName );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strDtTmVer );
   Console.Out.WriteLine( " runTest started..." );
   MyEnum myn1;
   Int32 i32Value;
   MyEnumFlags myn2;
   Enum en1;
   String strValue;
   String strRetValue;
   MyEnumByte myen_b;
   MyEnumSByte myen_sb;
   MyEnumShort myen_sob;
   MyEnumInt myen_i;
   MyEnumLong myen_l;
   MyEnumUShort myen_us;
   MyEnumUInt myen_ui;
   MyEnumULong myen_ul;
   Type[] tpArrEnums = {typeof(MyEnumByte), typeof(MyEnumSByte), typeof(MyEnumShort), typeof(MyEnumInt), 
			typeof(MyEnumLong), typeof(MyEnumUShort), typeof(MyEnumUInt), typeof(MyEnumULong)};
   Object oValue;
   Object[] oArrValues = {(Byte)5, (SByte)5, (Int16)5, 5, (Int64)5, (UInt16)5, (UInt32)5, (UInt64)5};
   ArrayList alst;
   ArrayList alstBackup;
   SpecialFlags spen1;
   NegativeEnum ngEn1;
   NegativeEnumWithFlags gnEnF1;
   try {
   strLoc="Loc_7539fd";
   myn1 = MyEnum.ONE;			
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals("1")) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   strLoc="Loc_57234df";
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("00000001")) {
   iCountErrors++;
   Console.WriteLine("Err_9473fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   i32Value = 4;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "G").Equals("FOUR")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "G"));
   }	
   i32Value = 32;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "G").Equals("32")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "G"));
   }	
   i32Value = 4;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "D").Equals("4")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "D"));
   }	
   i32Value = 4;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "X").Equals("00000004")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "X"));
   }	
   try{
   strValue = "1";
   iCountTestcases++;
   strRetValue = Enum.Format(myn1.GetType(), strValue, "G");
   iCountErrors++;
   Console.WriteLine("Err_758sff! Unexpected exception! This wasn't working before");
   }catch{
   }
   try{
   strValue = "ONE";
   iCountTestcases++;
   strRetValue = Enum.Format(myn1.GetType(), strValue, "G");
   iCountErrors++;
   Console.WriteLine("Err_7352sdg! Unexpected exception! This wasn't working before");
   }catch{
   }
   myn1 = MyEnum.ONE | MyEnum.TWO;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "g").Equals((1 | 2).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "g"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "d").Equals((1 | 2).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "d"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "x").Equals("00000003")) {
   iCountErrors++;
   Console.WriteLine("Err_120753fdf! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "x"));
   }	
   try{
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "f").Equals("ONE, TWO")) {
   iCountErrors++;
   Console.WriteLine("Err_120753fdf! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "f"));
   }	
   }catch{
   }
   i32Value = 3;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "G").Equals("3")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "G"));
   }	
   i32Value = 3;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "D").Equals("3")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "D"));
   }	
   i32Value = 3;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "X").Equals("00000003")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "X"));
   }	
   try{
   i32Value = 3;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), i32Value, "f").Equals("ONE, TWO")) {
   iCountErrors++;
   Console.WriteLine("Err_93752fsdg! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), i32Value, "f"));
   }	
   }catch{
   }
   strLoc="Loc_412ds";
   myn1 = MyEnum.ONE & MyEnum.TWO;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals((1 & 2).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals((1 & 2).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("00000000")) {
   iCountErrors++;
   Console.WriteLine("Err_109753vdf! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   myn1 = MyEnum.FOUR ^ MyEnum.EIGHT;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals((4 ^ 8).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals((4 ^ 8).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("0000000C")) {
   iCountErrors++;
   Console.WriteLine("Err_2193457fvd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   myn1 = ~MyEnum.FOUR;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals((~4).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals((~4).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("FFFFFFFB")) {
   iCountErrors++;
   Console.WriteLine("Err_12935fdvf! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   strLoc="Loc_429ds";
   myn1 = MyEnum.FOUR;
   myn1++;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals((4+1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals((4+1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("00000005")) {
   iCountErrors++;
   Console.WriteLine("Err_324fdsr! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   strLoc="Loc_5423ecsd";
   myn1 = MyEnum.FOUR;
   myn1--;
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "G").Equals((4-1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "D").Equals((4-1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn1.GetType(), myn1, "X").Equals("00000003")) {
   iCountErrors++;
   Console.WriteLine("Err_48dfvbd! Expected value wasn't returned, " + Enum.Format(myn1.GetType(), myn1, "X"));
   }	
   strLoc="Loc_4562fewd";
   myn2 = MyEnumFlags.ONE | MyEnumFlags.TWO;
   iCountTestcases++;
   if(!Enum.Format(myn2.GetType(), myn2, "G").Equals("ONE, TWO")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myn2.GetType(), myn2, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn2.GetType(), myn2, "D").Equals((1 | 2).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myn2.GetType(), myn2, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myn2.GetType(), myn2, "x").Equals("00000003")) {
   iCountErrors++;
   Console.WriteLine("Err_39527fvdg! Expected value wasn't returned, " + Enum.Format(myn2.GetType(), myn2, "x"));
   }	
   strLoc="Loc_53fd";
   myen_b = MyEnumByte.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_b.GetType(), myen_b, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_b.GetType(), myen_b, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_b.GetType(), myen_b, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_b.GetType(), myen_b, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_b.GetType(), myen_b, "X").Equals("01")) {
   iCountErrors++;
   Console.WriteLine("Err_233057fvdg! Expected value wasn't returned, " + Enum.Format(myen_b.GetType(), myen_b, "X"));
   }	
   myen_sb = MyEnumSByte.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_sb.GetType(), myen_sb, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_sb.GetType(), myen_sb, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_sb.GetType(), myen_sb, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_sb.GetType(), myen_sb, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_sb.GetType(), myen_sb, "x").Equals("01")) {
   iCountErrors++;
   Console.WriteLine("Err_23507dfvs! Expected value wasn't returned, " + Enum.Format(myen_sb.GetType(), myen_sb, "x"));
   }	
   myen_sob = MyEnumShort.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_sob.GetType(), myen_sob, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_sob.GetType(), myen_sob, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_sob.GetType(), myen_sob, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_sob.GetType(), myen_sob, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_sob.GetType(), myen_sob, "X").Equals("0001")) {
   iCountErrors++;
   Console.WriteLine("Err_32247vdg! Expected value wasn't returned, " + Enum.Format(myen_sob.GetType(), myen_sob, "X"));
   }	
   myen_i = MyEnumInt.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_i.GetType(), myen_i, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_i.GetType(), myen_i, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_i.GetType(), myen_i, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_i.GetType(), myen_i, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_i.GetType(), myen_i, "x").Equals("00000001")) {
   iCountErrors++;
   Console.WriteLine("Err_20357fdg! Expected value wasn't returned, " + Enum.Format(myen_i.GetType(), myen_i, "x"));
   }	
   myen_l = MyEnumLong.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_l.GetType(), myen_l, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_l.GetType(), myen_l, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_l.GetType(), myen_l, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_l.GetType(), myen_l, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_l.GetType(), myen_l, "x").Equals("0000000000000001")) {
   iCountErrors++;
   Console.WriteLine("Err_21053bdg! Expected value wasn't returned, " + Enum.Format(myen_l.GetType(), myen_l, "x"));
   }	
   myen_us = MyEnumUShort.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_us.GetType(), myen_us, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_us.GetType(), myen_us, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_us.GetType(), myen_us, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_us.GetType(), myen_us, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_us.GetType(), myen_us, "x").Equals("0001")) {
   iCountErrors++;
   Console.WriteLine("Err_2q0753fg! Expected value wasn't returned, " + Enum.Format(myen_us.GetType(), myen_us, "x"));
   }	
   myen_ui = MyEnumUInt.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_ui.GetType(), myen_ui, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_ui.GetType(), myen_ui, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_ui.GetType(), myen_ui, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_ui.GetType(), myen_ui, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_ui.GetType(), myen_ui, "x").Equals("00000001")) {
   iCountErrors++;
   Console.WriteLine("Err_107453fbdg! Expected value wasn't returned, " + Enum.Format(myen_ui.GetType(), myen_ui, "x"));
   }	
   myen_ul = MyEnumULong.ONE;
   iCountTestcases++;
   if(!Enum.Format(myen_ul.GetType(), myen_ul, "G").Equals("ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(myen_ul.GetType(), myen_ul, "G"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_ul.GetType(), myen_ul, "D").Equals((1).ToString())) {
   iCountErrors++;
   Console.WriteLine("Err_12357gsdd! Expected value wasn't returned, " + Enum.Format(myen_ul.GetType(), myen_ul, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(myen_ul.GetType(), myen_ul, "x").Equals("0000000000000001")) {
   iCountErrors++;
   Console.WriteLine("Err_10742dvggfh! Expected value wasn't returned, " + Enum.Format(myen_ul.GetType(), myen_ul, "x"));
   }	
   strLoc="Loc_1639dvs";
   alst = new ArrayList();
   for(int i=0; i<oArrValues.Length;i++){
   alst.Add(oArrValues[i]);
   }
   for(int i=0;i<tpArrEnums.Length;i++){
   alstBackup = (ArrayList)alst.Clone();
   oValue = alstBackup[i];
   iCountTestcases++;
   if(!Enum.Format(tpArrEnums[i], oValue, "D").Equals("5")) {
   iCountErrors++;
   Console.WriteLine("Err_2495gd,! Expected value wasn't returned, " + Enum.Format(tpArrEnums[i], oValue, "D"));
   }	
   alstBackup.RemoveAt(i);
   for(int j=0; j<alstBackup.Count; j++){
   try {
   iCountTestcases++;
   Enum.Format(tpArrEnums[i], alstBackup[j], "G");
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(ArgumentException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }
   }
   }
   try {
   iCountTestcases++;
   Enum.Format(null, 5, "G");
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(ArgumentNullException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }
   try {
   iCountTestcases++;
   Enum.Format(typeof(Int32), 5, "G");
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(ArgumentException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }
   try {
   iCountTestcases++;
   Enum.Format(typeof(MyEnumUInt), null, "G");
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(ArgumentNullException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }
   try {
   iCountTestcases++;
   Enum.Format(typeof(MyEnumInt), 5, null);
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(ArgumentNullException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }
   try {
   iCountTestcases++;
   Enum.Format(typeof(MyEnumInt), 5, "M");
   iCountErrors++;
   Console.WriteLine("Err_4325fds! Exception not thrown");
   }catch(System.FormatException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_9823gdf! wrong Exception thrown, " + ex);
   }												
   spen1 = SpecialFlags.ZERO;
   iCountTestcases++;
   if(!Enum.Format(spen1.GetType(), spen1, "G").Equals("ZERO")) {
   iCountErrors++;
   Console.WriteLine("Err_752vgf! Expected value wasn't returned, " + Enum.Format(spen1.GetType(), spen1, "G").Equals("ZERO"));
   }	
   iCountTestcases++;
   if(!Enum.Format(spen1.GetType(), spen1, "D").Equals("0")) {
   iCountErrors++;
   Console.WriteLine("Err_752vgf! Expected value wasn't returned, " + Enum.Format(spen1.GetType(), spen1, "D"));
   }	
   iCountTestcases++;
   if(!Enum.Format(spen1.GetType(), spen1, "X").Equals("00")) {
   iCountErrors++;
   Console.WriteLine("Err_752vgf! Expected value wasn't returned, " + Enum.Format(spen1.GetType(), spen1, "X"));
   }	
   ngEn1 = NegativeEnum.MINUS_TWO;
   if(!Enum.Format(ngEn1.GetType(), ngEn1, "G").Equals("MINUS_TWO")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(ngEn1.GetType(), ngEn1, "G"));
   }	
   gnEnF1 = NegativeEnumWithFlags.MINUS_TWO | NegativeEnumWithFlags.MINUS_ONE;
   if(!Enum.Format(gnEnF1.GetType(), gnEnF1, "G").Equals("MINUS_ONE")) {
   iCountErrors++;
   Console.WriteLine("Err_648fd! Expected value wasn't returned, " + Enum.Format(gnEnF1.GetType(), gnEnF1, "G"));
   }	
   }catch (Exception exc_general){
   ++iCountErrors;
   Console.WriteLine( s_strTFAbbrev +"Error Err_8888yyy!  strLoc=="+ strLoc +" ,exc_general=="+ exc_general );
   }
   if ( iCountErrors == 0 ){
   Console.Error.WriteLine( "paSs.   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountTestcases=="+ iCountTestcases );
   return true;
   } else {
   Console.Error.WriteLine( "FAiL!   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountErrors=="+ iCountErrors +" ,BugNums?: "+ s_strActiveBugNums );
   return false;
   }
   }
Example #48
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 #49
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 #50
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 #51
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 #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
    private void GatherRootBehaviours()
    {
        // find roots
        ArrayList allBehaviours = new ArrayList(GetComponents(typeof(FishBehaviour)));
        ArrayList allRootBehaviours = (ArrayList)allBehaviours.Clone();
        AllocateActiveBehaviours(allBehaviours.Count);

        foreach(FishBehaviour beh in allBehaviours){
            beh.RemoveChildrenFrom(allRootBehaviours);
        }

        // separate arbitrated and non arbitrated behaviours
        ArrayList tmpRootArbitratedBehaviours =  new ArrayList();
        ArrayList tmpRootNonArbitratedBehaviours =  new ArrayList();
        foreach(System.Object beh in allRootBehaviours){
            if(typeof(FishArbitratedBehaviour).IsInstanceOfType(beh))
                tmpRootArbitratedBehaviours.Add(beh);
            else
                tmpRootNonArbitratedBehaviours.Add(beh);
        }

        rootNonArbitratedBehaviours = (FishBehaviour[])tmpRootNonArbitratedBehaviours.ToArray(typeof(FishBehaviour));
        // group arbitrated behaviours by priorities
        rootArbitratedBehaviours = FishArbitratedBehaviour.GroupByPriorities(tmpRootArbitratedBehaviours);
        // PrintBehaviours();
    }
Example #54
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 #55
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 #56
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));
            }
        }
 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     ArrayList alst1;
     ArrayList alst2;
     String strValue;
     Object oValue;
     try 
     {
         do
         {
             strLoc = "Loc_8345vdfv";
             alst1 = new ArrayList();
             for(int i=0; i<10; i++)
             {
                 strValue = "String_" + i;
                 alst1.Add(strValue);
             }
             alst2 = (ArrayList)alst1.Clone();
             iCountTestcases++;
             for(int i=0; i<10; i++)
             {
                 strValue = "String_" + i;
                 if(!strValue.Equals((String)alst2[i])) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_561dvs_" + i + "! Expected value not returned, " + strValue);
                 }
             }
             alst1.RemoveAt(9);
             try 
             {
                 iCountTestcases++;
                 oValue = alst1[9];
                 iCountErrors++;
                 Console.WriteLine("Err_034cd! exception not thrown");
             }
             catch(ArgumentOutOfRangeException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_03472fd! Unexpected exception, " + ex.ToString());
             }
             strValue = "String_" + 9;
             iCountTestcases++;
             if(!strValue.Equals((String)alst2[9])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_563vdf! Expected value not returned, <<" + alst1[9] + ">>");
             }
             strLoc = "Loc_625fd";
             alst1 = new ArrayList(1000);
             alst2 = (ArrayList)alst1.Clone();
             iCountTestcases++;
             if(alst1.Capacity == alst2.Capacity) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_5234vsfd! Expected value not returned, <<" + alst1.Capacity + ">> <<"+ alst2.Capacity + ">>");
             }
             iCountTestcases++;
             if(alst1.Count != alst2.Count) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_453gfd! Expected value not returned, <<" + alst1.Count + ">> <<"+ alst2.Count + ">>");
             }
             iCountTestcases++;
             if(alst1.IsReadOnly != alst2.IsReadOnly) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_5234vsfd! Expected value not returned, <<" + alst1.IsReadOnly + ">> <<"+ alst2.IsReadOnly + ">>");
             }
             iCountTestcases++;
             if(alst1.IsSynchronized != alst2.IsSynchronized) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_5234vsfd! Expected value not returned, <<" + alst1.IsSynchronized + ">> <<"+ alst2.IsSynchronized + ">>");
             }
             strLoc = "Loc_8345vdfv";
             alst1 = new ArrayList();
             for(int i=0; i<10; i++)
             {
                 alst1.Add(new Foo());
             }
             alst2 = (ArrayList)alst1.Clone();
             iCountTestcases++;
             for(int i=0; i<10; i++)
             {
                 strValue = "Hello World";
                 if(!strValue.Equals(((Foo)alst2[i]).strValue)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_5623rvsdf_" + i + "! Expected value not returned, " + strValue);
                 }
             }
             strValue = "Good Bye";
             ((Foo)alst1[0]).strValue = strValue;
             iCountTestcases++;
             if(!strValue.Equals(((Foo)alst1[0]).strValue)) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7453bvdf! Expected value not returned, " + strValue);
             }
             iCountTestcases++;
             if(!strValue.Equals(((Foo)alst2[0]).strValue)) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7453bvdf! Expected value not returned, " + strValue);
             }
             alst2[0] = new Foo();
             strValue = "Good Bye";
             iCountTestcases++;
             if(!strValue.Equals(((Foo)alst1[0]).strValue)) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_525vdf! Expected value not returned, " + strValue);
             }
             strValue = "Hello World";
             iCountTestcases++;
             if(!strValue.Equals(((Foo)alst2[0]).strValue)) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_54363fgdf! Expected value not returned, " + strValue);
             }
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
Example #58
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);
                }
            }
        }
 public static void SerializeDocument(Document d, out ArrayList<object> treeItemsParam, out ArrayList<object> featuresParam, out ArrayList<object> contentParam)
 {
     Dictionary<string, int> idMapping = new Dictionary<string, int>();
     // GetId
     Func<string, int> GetId = delegate(string name)
     {
         int id;
         if (idMapping.TryGetValue(name, out id)) { return id; }
         idMapping.Add(name, id = idMapping.Count);
         return id;
     };
     ArrayList<AnnotationInfo> data = new ArrayList<AnnotationInfo>();
     Set<string> tabu = new Set<string>();
     ArrayList<Pair<ArrayList<int>, string>> treeItems = new ArrayList<Pair<ArrayList<int>, string>>();
     foreach (Annotation a in d.Annotations)
     {
         if (!tabu.Contains(a.Type))
         {
             tabu.Add(a.Type);
             string[] fullPath = a.Type.Split('/', '\\');
             string path = "";
             ArrayList<int> idList = new ArrayList<int>();
             foreach (string pathItem in fullPath)
             {
                 path += "/" + pathItem;
                 idList.Add(GetId(path));
                 if (!tabu.Contains(path))
                 {
                     tabu.Add(path);
                     treeItems.Add(new Pair<ArrayList<int>, string>(idList.Clone(), path));
                 }
             }
         }
     }
     treeItems.Sort(delegate(Pair<ArrayList<int>, string> a, Pair<ArrayList<int>, string> b)
     {
         int n = Math.Min(a.First.Count, b.First.Count);
         for (int i = 0; i < n; i++)
         {
             if (a.First[i] != b.First[i])
             {
                 return a.First[i].CompareTo(b.First[i]);
             }
         }
         if (a.First.Count > b.First.Count) { return 1; }
         else if (b.First.Count > a.First.Count) { return -1; }
         else { return 0; }
     });
     idMapping.Clear();
     treeItemsParam = new ArrayList<object>();
     foreach (Pair<ArrayList<int>, string> item in treeItems)
     {
         ArrayList<string> pathItems = new ArrayList<string>(item.Second.Split('/'));
         treeItemsParam.Add(new object[] { pathItems.Count - 1, pathItems.Last, GetId(item.Second) });
     }
     foreach (Annotation a in d.Annotations)
     {
         string path = "";
         string[] fullPath = a.Type.Split('/', '\\');
         for (int i = 0; i < fullPath.Length; i++)
         {
             path += "/" + fullPath[i];
             int pathId = GetId(path);
             bool isLeaf = i == fullPath.Length - 1;
             data.Add(new AnnotationInfo(a, pathId, /*isSpanStart=*/true, isLeaf));
             data.Add(new AnnotationInfo(a, pathId, /*isSpanStart=*/false, isLeaf));
         }
     }
     data.Sort(delegate(AnnotationInfo a, AnnotationInfo b)
     {
         int c = a.mIdx.CompareTo(b.mIdx);
         if (c != 0) { return c; }
         return -a.mIsSpanStart.CompareTo(b.mIsSpanStart);
     });
     string text = d.Text;
     Dictionary<int, Set<Annotation>> state = new Dictionary<int, Set<Annotation>>();
     // AddToState
     Action<AnnotationInfo> AddToState = delegate(AnnotationInfo annotInfo)
     {
         Set<Annotation> annots;
         if (!state.TryGetValue(annotInfo.mAnnotationId, out annots))
         {
             state.Add(annotInfo.mAnnotationId, annots = new Set<Annotation>());
         }
         if (annotInfo.mIsLeaf) { annots.Add(annotInfo.mAnnotation); }
     };
     // RemoveFromState
     Action<AnnotationInfo> RemoveFromState = delegate(AnnotationInfo annotInfo)
     {
         Set<Annotation> annots;
         if (state.TryGetValue(annotInfo.mAnnotationId, out annots))
         {
             if (annotInfo.mIsLeaf) { annots.Remove(annotInfo.mAnnotation); }
             if (annots.Count == 0)
             {
                 state.Remove(annotInfo.mAnnotationId);
             }
         }
     };
     featuresParam = new ArrayList<object>();
     foreach (KeyValuePair<string, string> f in d.Features)
     {
         string val = ProcessDocumentFeatureValue(f.Key, f.Value);
         if (val != null)
         {
             featuresParam.Add(new string[] { f.Key, val });
         }
     }
     int cIdx = 0;
     contentParam = new ArrayList<object>();
     foreach (AnnotationInfo item in data)
     {
         if (item.mIsSpanStart)
         {
             string part = text.Substring(cIdx, item.mIdx - cIdx);
             if (part != "") { contentParam.Add(new object[] { part, SerializeState(state) }); }
             cIdx = item.mIdx;
             AddToState(item);
         }
         else
         {
             string part = text.Substring(cIdx, item.mIdx - cIdx + 1);
             if (part != "") { contentParam.Add(new object[] { part, SerializeState(state) }); }
             cIdx = item.mIdx + 1;
             RemoveFromState(item);
         }
     }
     if (text.Length - cIdx > 0)
     {
         contentParam.Add(new object[] { text.Substring(cIdx, text.Length - cIdx), SerializeState(state) });
     }
 }
Example #60
0
        public static void Clone_IsShallowCopy()
        {
            var arrList = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                arrList.Add(new Foo());
            }

            ArrayList clone = (ArrayList)arrList.Clone();

            string stringValue = "Hello World";
            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(stringValue, ((Foo)clone[i]).StringValue);
            }

            // Now we remove an object from the original list, but this should still be present in the clone
            arrList.RemoveAt(9);
            Assert.Equal(stringValue, ((Foo)clone[9]).StringValue);

            stringValue = "Good Bye";
            ((Foo)arrList[0]).StringValue = stringValue;
            Assert.Equal(stringValue, ((Foo)arrList[0]).StringValue);
            Assert.Equal(stringValue, ((Foo)clone[0]).StringValue);

            // If we change the object, of course, the previous should not happen
            clone[0] = new Foo();

            stringValue = "Good Bye";
            Assert.Equal(stringValue, ((Foo)arrList[0]).StringValue);

            stringValue = "Hello World";
            Assert.Equal(stringValue, ((Foo)clone[0]).StringValue);
        }