public void Count_1()
        {
            Collection col = new Collection();

            Assert.AreEqual(0,col.Count);

            col.Add("a",null,null,null);
            Assert.AreEqual(1,col.Count);

            col.Add("b",null,null,null);
            Assert.AreEqual(2,col.Count);

            col.Add("c",null,null,null);
            Assert.AreEqual(3,col.Count);

            col.Add("d",null,null,null);
            Assert.AreEqual(4,col.Count);

            col.Remove(1);
            col.Remove(1);

            Assert.AreEqual(2,col.Count);

            col.Remove(1);
            col.Remove(1);

            Assert.AreEqual(0,col.Count);
        }
        public void Exception()
        {
            Collection c = new Collection ();

            try
            {
                // nothing in Collection yet
                object o = c[0];
                Assert.Fail ("#E02");
            }
            catch (IndexOutOfRangeException)
            {
            }

            c.Add ("Baseball", "Base", null, null);
            c.Add ("Football", "Foot", null, null);
            c.Add ("Basketball", "Basket", null, null);
            c.Add ("Volleyball", "Volley", null, null);

            try
            {
                // only 4 elements
                object o = c[5];
                Assert.Fail ("#E04");
            }
            catch (IndexOutOfRangeException)
            {
            }

            try
            {
                // Collection class is 1-based
                object o = c[0];
                Assert.Fail ("#E06");
            }
            catch (IndexOutOfRangeException)
            {
            }

            try
            {
                // no member with Key == "Kick"
                object o = c["Kick"];
                Assert.Fail ("#E08");
            }
            catch (ArgumentException)
            {
                // FIXME
                // VB Language Reference says IndexOutOfRangeException
                // here, but MS throws ArgumentException
            }

            try
            {
                // Even though Indexer is an object, really it's a string
                object o = c[typeof (int)];
                Assert.Fail ("#E10");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // can't specify both Before and After
                c.Add ("Kickball", "Kick", "Volley", "Foot");
                Assert.Fail ("#E12");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // Key "Foot" already exists
                c.Add ("Kickball", "Foot", null, null);
                Assert.Fail ("#E14");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // Even though Before is object, it's really a string
                c.Add ("Dodgeball", "Dodge", typeof (int), null);
                Assert.Fail ("#E16");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // Even though After is object, it's really a string
                c.Add ("Wallyball", "Wally", null, typeof (int));
                Assert.Fail ("#E18");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // have to pass a legitimate value to remove
                c.Remove (null);
                Assert.Fail ("#E20");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                // no Key "Golf" exists
                c.Remove ("Golf");
                Assert.Fail ("#E22");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // no Index 10 exists
                c.Remove (10);
                Assert.Fail ("#E24");
            }
            catch (IndexOutOfRangeException)
            {
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();

                // Must MoveNext before Current
                object item = e.Current;
                Assert.IsNull (item, "#E25");
            }
            catch (IndexOutOfRangeException)
            {
                Assert.Fail ("#E27");
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();
                e.MoveNext ();

                c.Add ("Paintball", "Paint", null, null);

                // Can't MoveNext if Collection has been modified
                e.MoveNext ();

                // FIXME
                // On-line help says this should throw an error. MS doesn't.
            }
            catch (Exception)
            {
                Assert.Fail ("#E28");
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();
                e.MoveNext ();

                c.Add ("Racketball", "Racket", null, null);

                // Can't Reset if Collection has been modified
                e.Reset ();

                // FIXME
                // On-line help says this should throw an error. MS doesn't.
            }
            catch (InvalidOperationException)
            {
                Assert.Fail ("#E30");
            }
        }
        public void Remove_6()
        {
            // Argument 'Key' is not a valid value.
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove("keyd");
        }
        public void Remove_7()
        {
            // Key cannot be null
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove(null);
        }
        public void Remove_2()
        {
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);
            col.Add(s2 + s1,"keyd",null,null);
            col.Add(s1 + s1,"keye",null,null);
            col.Add(s3 + s1,"keyf",null,null);

            col.Remove("keya");

            Assert.AreEqual(5,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("ba",col[3]);
            Assert.AreEqual("aa",col[4]);
            Assert.AreEqual("ca",col[5]);

            col.Remove("keyd");

            Assert.AreEqual(4,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);
            Assert.AreEqual("ca",col[4]);

            col.Remove("keyf");

            Assert.AreEqual(3,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);

            col.Remove("keyc");

            Assert.AreEqual(2,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("aa",col[2]);

            col.Remove("keyb");

            Assert.AreEqual(1,col.Count);
            Assert.AreEqual("aa",col[1]);

            col.Remove("keye");

            Assert.AreEqual(0,col.Count);
        }
        public void Remove_5()
        {
            // Collection index must be in the range 1 to the size of the collection.
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove(4);
        }
        public void RemoveNoKey()
        {
            Collection c;

            c = new Collection ();

            c.Add (typeof (int), null, null, null);
            c.Add (typeof (double), null, null, null);
            c.Add (typeof (string), null, null, null);
            c.Add (typeof (object), null, null, null);

            Assert.AreEqual (4, c.Count, "#RNK01");

            c.Remove (3);

            Assert.AreEqual (3, c.Count, "#RNK02");

            // Collection class is 1-based
            Assert.AreEqual (typeof (object), c[3], "#RNK03");

            c.Remove (1);

            Assert.AreEqual (2, c.Count, "#RNK04");
            Assert.AreEqual (typeof (double), c[1], "#RNK05");
            Assert.AreEqual (typeof (object), c[2], "#RNK06");

            c.Remove (2);

            Assert.AreEqual (1, c.Count, "#RNK07");
            Assert.AreEqual (typeof (double), c[1], "#RNK08");

            c.Remove (1);

            Assert.AreEqual (0, c.Count, "#RNK09");
        }
Exemple #8
0
        /// <summary>
        /// Sorts the collection.
        /// </summary>
        /// <param name="col">The col.</param>
        /// <param name="psSortPropertyName">Name of the ps sort property.</param>
        /// <param name="pbAscending">if set to <c>true</c> [pb ascending].</param>
        /// <param name="psKeyPropertyName">Name of the ps key property.</param>
        private void SortCollection(Microsoft.VisualBasic.Collection col, string psSortPropertyName, bool pbAscending, string psKeyPropertyName = "")
        {
            object obj            = null;
            int    i              = 0;
            int    j              = 0;
            int    iMinMaxIndex   = 0;
            object vMinMax        = null;
            object vValue         = null;
            bool   bSortCondition = false;
            bool   bUseKey        = false;
            string sKey           = null;

            bUseKey = (!string.IsNullOrEmpty(psKeyPropertyName));

//INSTANT C# NOTE: The ending condition of VB 'For' loops is tested only on entry to the loop. Instant C# has created a temporary variable in order to use the initial value of col.Count for every iteration:
            int tempVar = col.Count;

            for (i = 1; i < tempVar; i++)
            {
                obj          = col[i];
                vMinMax      = Interaction.CallByName(obj, psSortPropertyName, Microsoft.VisualBasic.Constants.vbGet);
                iMinMaxIndex = i;

                for (j = i + 1; j <= col.Count; j++)
                {
                    obj    = col[j];
                    vValue = Interaction.CallByName(obj, psSortPropertyName, Microsoft.VisualBasic.Constants.vbGet);

                    if (pbAscending)
                    {
                        bSortCondition = (Convert.ToSingle(vValue) < Convert.ToSingle(vMinMax));
                    }
                    else
                    {
                        bSortCondition = (Convert.ToSingle(vValue) > Convert.ToSingle(vMinMax));
                    }

                    if (bSortCondition)
                    {
                        vMinMax      = vValue;
                        iMinMaxIndex = j;
                    }

                    obj = null;
                }

                if (iMinMaxIndex != i)
                {
                    obj = col[iMinMaxIndex];

                    col.Remove(iMinMaxIndex);
                    if (bUseKey)
                    {
                        sKey = Convert.ToString(Interaction.CallByName(obj, psKeyPropertyName, Microsoft.VisualBasic.Constants.vbGet));
                        col.Add(obj, sKey, i, null);
                    }
                    else
                    {
                        col.Add(obj, null, i, null);
                    }

                    obj = null;
                }

                obj = null;
            }
        }
        public void GetEnumerator_8()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(3);
            col.Remove(2);

            Assert.AreEqual(o1,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
        public void RemoveKey()
        {
            Collection c;

            c = new Collection ();

            c.Add ("Baseball", "Base", null, null);
            c.Add ("Football", "Foot", null, null);
            c.Add ("Basketball", "Basket", null, null);
            c.Add ("Volleyball", "Volley", null, null);

            Assert.AreEqual (4, c.Count, "#RK01");

            c.Remove ("Foot");

            Assert.AreEqual (3, c.Count, "#RK02");
            Assert.AreEqual ("Basketball", c["Basket"], "#RK03");

            // Collection class is 1-based
            Assert.AreEqual ("Volleyball", c[3], "#RK04");

            c.Remove ("Base");

            Assert.AreEqual (2, c.Count, "#RK05");
            Assert.AreEqual ("Basketball", c[1], "#RK06");
            Assert.AreEqual ("Volleyball", c["Volley"], "#RK07");

            c.Remove (2);

            Assert.AreEqual (1, c.Count, "#RK08");
            Assert.AreEqual ("Basketball", c[1], "#RK09");
            Assert.AreEqual ("Basketball", c["Basket"], "#RK10");

            c.Remove (1);

            Assert.AreEqual (0, c.Count, "#RK11");
        }
        public void GetEnumerator_7()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(1);

            object o = en.Current;
        }
Exemple #12
0
 public void Remove(int index)
 {
     mCol.Remove(System.Convert.ToString(index));
 }
		private void SortCollection(Collection col, string psSortPropertyName, bool pbAscending, string psKeyPropertyName = "")
		{
			object obj = null;
			int i = 0;
			int j = 0;
			int iMinMaxIndex = 0;
			object vMinMax = null;
			object vValue = null;
			bool bSortCondition = false;
			bool bUseKey = false;
			string sKey = null;

			bUseKey = (!string.IsNullOrEmpty(psKeyPropertyName));

			for (i = 1; i <= col.Count - 1; i++) {
				obj = col[i];
				vMinMax = Interaction.CallByName(obj, psSortPropertyName, Constants.vbGet);
				iMinMaxIndex = i;

				for (j = i + 1; j <= col.Count; j++) {
					obj = col[j];
					vValue = Interaction.CallByName(obj, psSortPropertyName, Constants.vbGet);

					if ((pbAscending)) {
						bSortCondition = (Convert.ToSingle(vValue) < Convert.ToSingle(vMinMax));
					} else {
						bSortCondition = (Convert.ToSingle(vValue) > Convert.ToSingle(vMinMax));
					}

					if ((bSortCondition)) {
						vMinMax = vValue;
						iMinMaxIndex = j;
					}

					obj = null;
				}

				if ((iMinMaxIndex != i)) {
					obj = col[iMinMaxIndex];

					col.Remove(iMinMaxIndex);
					if ((bUseKey)) {
						sKey = Convert.ToString(Interaction.CallByName(obj, psKeyPropertyName, Constants.vbGet));
						col.Add(obj, sKey, i);
					} else {
						col.Add(obj, "", i);
					}

					obj = null;
				}

				obj = null;
			}

		}
        public void GetEnumerator_11()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o1,en.Current);

            col.Remove(1);

            object o = en.Current;
            Assert.AreEqual (o1, o, "#01");
        }
        public void Remove_1()
        {
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,null,null,null);
            col.Add(s1,null,null,null);
            col.Add(s3,null,null,null);
            col.Add(s2 + s1,null,null,null);
            col.Add(s1 + s1,null,null,null);
            col.Add(s3 + s1,null,null,null);

            col.Remove(1);

            Assert.AreEqual(5,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("ba",col[3]);
            Assert.AreEqual("aa",col[4]);
            Assert.AreEqual("ca",col[5]);

            col.Remove(3);

            Assert.AreEqual(4,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);
            Assert.AreEqual("ca",col[4]);

            col.Remove(4);

            Assert.AreEqual(3,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);

            col.Remove(2);

            Assert.AreEqual(2,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("aa",col[2]);

            col.Remove(1);

            Assert.AreEqual(1,col.Count);
            Assert.AreEqual("aa",col[1]);

            col.Remove(1);

            Assert.AreEqual(0,col.Count);
        }
        public void GetEnumerator_12()
        {
            Collection col = new Collection();

            string s1 = "e";
            string s2 = "g";
            string s3 = "a";
            string s4 = "f";

            col.Add(s1,null,null,null);
            col.Add(s2,null,null,null);
            col.Add(s3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s1,en.Current);

            col.Remove(1);

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s2,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s3,en.Current);
            Assert.IsFalse(en.MoveNext());

            col.Add(s4,null,null,null);

            Assert.AreEqual(null,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
Exemple #17
0
        /// <summary>
        /// Handles the MouseDown event of the ColorBlender control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void ColorBlender_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Y > TopMargin + BarHeight - 10 && e.Y < TopMargin + BarHeight + 20 && e.X > 5 && e.X < this.Width - 5)
            {
                //Check if the cursor is over a MiddlePointer
                int mOver = IsMouseOverPointer(e.X, e.Y);
                if (mOver > -1)
                {
                    if (!(CurrPointer == mOver))
                    {
                        CurrPointer = mOver;
                        ClearCurrPointer();
                        ((cblPointer)(cblPointer)MiddlePointers[CurrPointer]).pIsCurr = true;
                        UpdateRGBnuds(((cblPointer)(cblPointer)MiddlePointers[CurrPointer]).pColor);
                        lblPos.Text = ((cblPointer)MiddlePointers[CurrPointer]).PosToStrong;
                    }

                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        MouseMoving = true;
                    }
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        MiddlePointers.Remove(CurrPointer);
                        lblPos.Text = "";
                    }
                }
                else
                {
                    //Check if the cursor is over a Start or End Pointer
                    if (IsMouseOverStartPointer(e.X, e.Y))
                    {
                        ClearCurrPointer();
                        CurrPointer          = -1;
                        StartPointer.pIsCurr = true;
                        UpdateRGBnuds(StartPointer.pColor);
                        lblPos.Text = StartPointer.PosToStrong;
                    }
                    else if (IsMouseOverEndPointer(e.X, e.Y))
                    {
                        ClearCurrPointer();
                        CurrPointer        = -1;
                        EndPointer.pIsCurr = true;
                        UpdateRGBnuds(EndPointer.pColor);
                        lblPos.Text = EndPointer.PosToStrong;
                    }
                    else
                    {
                        //If the cursor is not over a cblPointer then Add One
                        if (e.Button == System.Windows.Forms.MouseButtons.Left)
                        {
                            ClearCurrPointer();
                            MiddlePointers.Add(new cblPointer(Convert.ToSingle(((e.X - 10) / (double)(this.Width - 20))), Color.FromArgb(tbarAlpha.Value, Convert.ToInt32(nudRed.Value), Convert.ToInt32(nudGreen.Value), Convert.ToInt32(nudBlue.Value)), true), null, null, null);
                            SortCollection(MiddlePointers, "pPos", true);
                            CurrPointer = FindCurr();
                            lblPos.Text = ((cblPointer)MiddlePointers[CurrPointer]).PosToStrong;
                            this.Invalidate();
                            MouseMoving = true;
                        }
                    }
                }
            }
        }