Ejemplo n.º 1
0
        public void TestRemove()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Remove(0));
                Assert.AreEqual((short)(999 - j), list.Count);
            }
            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual((short)(999 - j),
                                list.Remove((short)(999 - j)));
                Assert.AreEqual(999 - j, list.Count);
            }
            try
            {
                list.Remove(0);
                Assert.Fail("should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
        }
Ejemplo n.º 2
0
        public void TestIsEmpty()
        {
            ShortList list1 = new ShortList();
            ShortList list2 = new ShortList(1000);
            ShortList list3 = new ShortList(list1);

            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
            list1.Add((short)1);
            list2.Add((short)2);
            list3 = new ShortList(list2);
            Assert.IsTrue(!list1.IsEmpty());
            Assert.IsTrue(!list2.IsEmpty());
            Assert.IsTrue(!list3.IsEmpty());
            list1.Clear();
            list2.Remove(0);
            list3.RemoveValue((short)2);
            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
        }