Exemplo n.º 1
0
        public void SimpleTests()
        {
            // Tests simple adds and removes from the front of the list. It
            // makes part of its tail immutable, but doesn't make it mutable
            // again. Also, we test operations that don't modify the list.

            FWList <int> list = new FWList <int>();

            Assert.That(list.IsEmpty);

            // create VListBlockOfTwo
            list = new FWList <int>(10, 20);
            ExpectList(list, 10, 20);

            // Add()
            list.Clear();
            list.Add(1);
            Assert.That(!list.IsEmpty);
            list.Add(2);
            Assert.AreEqual(1, list.BlockChainLength);
            list.Add(3);
            Assert.AreEqual(2, list.BlockChainLength);

            ExpectList(list, 3, 2, 1);
            FVList <int> snap = list.ToFVList();

            ExpectList(snap, 3, 2, 1);

            // AddRange(), Push(), Pop()
            list.Push(4);
            list.AddRange(new int[] { 6, 5 });
            ExpectList(list, 6, 5, 4, 3, 2, 1);
            Assert.AreEqual(list.Pop(), 6);
            ExpectList(list, 5, 4, 3, 2, 1);
            list.RemoveRange(0, 2);
            ExpectList(list, 3, 2, 1);

            // Double the list
            list.AddRange(list);
            ExpectList(list, 3, 2, 1, 3, 2, 1);
            list.RemoveRange(0, 3);

            // Fill a third block
            list.AddRange(new int[] { 9, 8, 7, 6, 5, 4 });
            list.AddRange(new int[] { 14, 13, 12, 11, 10 });
            ExpectList(list, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);

            // Remove(), enumerator
            list.Remove(14);
            list.Remove(13);
            list.Remove(12);
            list.Remove(11);
            ExpectListByEnumerator(list, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);

            // IndexOutOfRangeException
            AssertThrows <IndexOutOfRangeException>(delegate() { int i = list[-1]; });
            AssertThrows <IndexOutOfRangeException>(delegate() { int i = list[10]; });
            AssertThrows <IndexOutOfRangeException>(delegate() { list.Insert(-1, -1); });
            AssertThrows <IndexOutOfRangeException>(delegate() { list.Insert(list.Count + 1, -1); });
            AssertThrows <IndexOutOfRangeException>(delegate() { list.RemoveAt(-1); });
            AssertThrows <IndexOutOfRangeException>(delegate() { list.RemoveAt(list.Count); });

            // Front, Contains, IndexOf
            Assert.That(list.First == 10);
            Assert.That(list.Contains(9));
            Assert.That(list[list.IndexOf(2)] == 2);
            Assert.That(list[list.IndexOf(9)] == 9);
            Assert.That(list[list.IndexOf(7)] == 7);
            Assert.That(list.IndexOf(-1) == -1);

            // snap is still the same
            ExpectList(snap, 3, 2, 1);
        }