RemoveAt() публичный Метод

public RemoveAt ( int index ) : void
index int
Результат void
Пример #1
0
		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
Пример #2
0
        public void CountTests()
        {
            var d = new OrderedDictionary();
            Assert.Equal(0, d.Count);

            for (int i = 0; i < 1000; i++)
            {
                d.Add(i, i);
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.Remove(i);
                Assert.Equal(1000 - i - 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d[(object)i] = i;
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
Пример #3
0
        public void RemoveAtTests()
        {
            var d = new OrderedDictionary();

            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(0));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(-1));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(5));

            Assert.Throws<ArgumentNullException>(() => d.Remove(null));

            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.RemoveAt(1000 - i - 1);
                Assert.Equal(1000 - i - 1, d.Count);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                Assert.Equal("bar_" + i, d[0]);
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
Пример #4
0
		public void ReadOnly_RemoveAt ()
		{
			OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
			od.RemoveAt (0);
		}
Пример #5
0
        private void RandomizeDictionary(ref OrderedDictionary dict)
        {
            OrderedDictionary newDict = new OrderedDictionary();

            int i = 0;
            while (dict.Count > 0)
            {
                object[] keys = new object[dict.Count];
                dict.Keys.CopyTo(keys, 0);
                object[] values = new object[dict.Count];
                dict.Values.CopyTo(values, 0);

                i = rand.Next(0, dict.Count - 1);
                newDict.Add(keys[i], values[i]);
                dict.RemoveAt(i);
            }

            dict = newDict;
        }
Пример #6
0
        public void AsReadOnly_AttemptingToModifyDictionary_Throws()
        {
            OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
            Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
            Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
        }