Пример #1
0
        public void TestRemove()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Remove(0));
                Assert.AreEqual(999 - j, list.Count);
            }
            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(999 - j, list.Remove(999 - j));
                Assert.AreEqual(999 - j, list.Count);
            }
            try
            {
                list.Remove(0);
                Assert.Fail("should have caught IndexOutOfBoundsException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
        }
Пример #2
0
        public void TestIsEmpty()
        {
            IntList list1 = new IntList();
            IntList list2 = new IntList(1000);
            IntList list3 = new IntList(list1);

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