Exemplo n.º 1
0
Arquivo: VList.cs Projeto: murven/Loyc
        public void TestInsertRemove()
        {
            VList <int> list  = new VList <int>(9);
            VList <int> list2 = new VList <int>(10, 11);

            list.Insert(0, 12);
            list.Insert(1, list2[1]);
            list.Insert(2, list2[0]);
            ExpectList(list, 12, 11, 10, 9);
            for (int i = 0; i < 9; i++)
            {
                list.Insert(4, i);
            }
            ExpectList(list, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);

            list2 = list;
            for (int i = 1; i <= 6; i++)
            {
                list2.RemoveAt(i);
            }
            ExpectList(list2, 12, 10, 8, 6, 4, 2, 0);
            ExpectList(list, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);             // unchanged

            Assert.AreEqual(0, list2.Pop());
            list2.Insert(5, -2);
            ExpectList(list2, 12, 10, 8, 6, 4, -2, 2);
            list2.Insert(5, -1);
            ExpectList(list2, 12, 10, 8, 6, 4, -1, -2, 2);

            // Test changing items
            list = list2;
            for (int i = 0; i < list.Count; i++)
            {
                list[i] = i;
            }
            ExpectList(list, 0, 1, 2, 3, 4, 5, 6, 7);
            ExpectList(list2, 12, 10, 8, 6, 4, -1, -2, 2);

            list2.Clear();
            ExpectList(list2);
            Assert.AreEqual(5, list[5]);
        }