示例#1
0
        public void RemoveAtStart()
        {
            CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b);

            for (int i = 1; i <= 3; i++)
            {
                list.InsertRange(list.Count, 2, i);
            }
            Assert.AreEqual(new[] { 1, 1, 2, 2, 3, 3 }, list.ToArray());
            list.RemoveRange(0, 1);
            Assert.AreEqual(new[] { 1, 2, 2, 3, 3 }, list.ToArray());
        }
        public void TransformRange()
        {
            CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b);

            list.AddRange(new[] { 0, 1, 1, 1, 0, 0 });
            list.TransformRange(2, 3, i => 0);
            Assert.AreEqual(new[] { 0, 1, 0, 0, 0, 0 }, list.ToArray());
        }
        public void AddRepeated()
        {
            CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b);

            list.Add(42);
            list.Add(42);
            list.Add(42);
            list.Insert(0, 42);
            list.Insert(1, 42);
            Assert.AreEqual(new[] { 42, 42, 42, 42, 42 }, list.ToArray());
        }
        public void Transform()
        {
            CompressingTreeList <int> list = new CompressingTreeList <int>((a, b) => a == b);

            list.AddRange(new[] { 0, 1, 1, 0 });
            int calls = 0;

            list.Transform(i => { calls++; return(i + 1); });
            Assert.AreEqual(3, calls);
            Assert.AreEqual(new[] { 1, 2, 2, 1 }, list.ToArray());
        }