Exemplo n.º 1
0
        public void TestAddAll()
        {
            IntList list = new IntList();

            for (int j = 0; j < 5; j++)
            {
                list.Add(j);
            }
            IntList list2 = new IntList(0);

            list2.AddAll(list);
            list2.AddAll(list);
            Assert.AreEqual(2 * list.Count, list2.Count);
            for (int j = 0; j < 5; j++)
            {
                Assert.AreEqual(list2.Get(j), j);
                Assert.AreEqual(list2.Get(j + list.Count), j);
            }
            IntList empty = new IntList();
            int limit = list.Count;

            for (int j = 0; j < limit; j++)
            {
                Assert.IsTrue(list.AddAll(j, empty));
                Assert.AreEqual(limit, list.Count);
            }
            try
            {
                list.AddAll(limit + 1, empty);
                Assert.Fail("should have thrown an exception");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }

            // try add at beginning
            empty.AddAll(0, list);
            //Assert.AreEqual(empty, list);
            Assert.IsTrue(empty.Equals(list));

            // try in the middle
            empty.AddAll(1, list);
            Assert.AreEqual(2 * list.Count, empty.Count);
            Assert.AreEqual(list.Get(0), empty.Get(0));
            Assert.AreEqual(list.Get(0), empty.Get(1));
            Assert.AreEqual(list.Get(1), empty.Get(2));
            Assert.AreEqual(list.Get(1), empty.Get(6));
            Assert.AreEqual(list.Get(2), empty.Get(3));
            Assert.AreEqual(list.Get(2), empty.Get(7));
            Assert.AreEqual(list.Get(3), empty.Get(4));
            Assert.AreEqual(list.Get(3), empty.Get(8));
            Assert.AreEqual(list.Get(4), empty.Get(5));
            Assert.AreEqual(list.Get(4), empty.Get(9));

            // try at the end
            empty.AddAll(empty.Count, list);
            Assert.AreEqual(3 * list.Count, empty.Count);
            Assert.AreEqual(list.Get(0), empty.Get(0));
            Assert.AreEqual(list.Get(0), empty.Get(1));
            Assert.AreEqual(list.Get(0), empty.Get(10));
            Assert.AreEqual(list.Get(1), empty.Get(2));
            Assert.AreEqual(list.Get(1), empty.Get(6));
            Assert.AreEqual(list.Get(1), empty.Get(11));
            Assert.AreEqual(list.Get(2), empty.Get(3));
            Assert.AreEqual(list.Get(2), empty.Get(7));
            Assert.AreEqual(list.Get(2), empty.Get(12));
            Assert.AreEqual(list.Get(3), empty.Get(4));
            Assert.AreEqual(list.Get(3), empty.Get(8));
            Assert.AreEqual(list.Get(3), empty.Get(13));
            Assert.AreEqual(list.Get(4), empty.Get(5));
            Assert.AreEqual(list.Get(4), empty.Get(9));
            Assert.AreEqual(list.Get(4), empty.Get(14));
        }