Beispiel #1
0
        public void TestAddRange()
        {
            var list = _newList();

            list.AddRange(Iterable.Range(1, 3));
            list.AddRange(Enumerable.Range(5, 3));
            ExpectList(list, 1, 2, 3, 5, 6, 7);
            list.AddRange(Iterable.Range(10, 2));
            list.AddRange(Enumerable.Range(20, 2));
            ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21);
            list.AddRange(Iterable.Single(30));
            list.AddRange(Enumerable.Range(40, 1));
            ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40);
            list.AddRange(Iterable.Repeat(0, 0));
            list.AddRange(Enumerable.Repeat(0, 0));
            ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40);

            list.AddRange(Iterable.Single(-99));
            if (Enumerable.First(list) == -99)
            {
                // It's a sorted list.
                list.AddRange(Iterable.Single(4));
                ExpectList(list, -99, 1, 2, 3, 4, 5, 6, 7, 10, 11, 20, 21, 30, 40);
                list.AddRange(Enumerable.Range(-2, 3));
                ExpectList(list, -99, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 20, 21, 30, 40);
                list.AddRange(Enumerable.Range(12, 8));
                ExpectList(list, -99, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 30, 40);
            }
            else
            {
                ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40, -99);
            }
        }
Beispiel #2
0
        public void TestPrependMove()
        {
            // Prepend something far larger (taller tree)
            int sizeChange = 0, sizeChangeTemp = 0;
            var list = NewList(920, 80, (l, e) => sizeChange += e.SizeChange);
            var temp = NewList(40, 880, (l, e) => sizeChangeTemp += e.SizeChange);

            list.Prepend(temp, true);
            Assert.AreEqual(sizeChange, 880);
            Assert.AreEqual(temp.Count, 0);
            Assert.AreEqual(list.ImmutableCount, 0);

            // Prepend something far smaller (smaller tree)
            temp = NewList(0, 40, (l, e) => sizeChangeTemp += e.SizeChange);
            list.Prepend(temp, true);
            Assert.AreEqual(temp.Count, 0);
            ExpectList(list, Iterable.Range(0, 1000));
            Assert.AreEqual(sizeChange, 920);
            Assert.AreEqual(sizeChange, -sizeChangeTemp);
            Assert.AreEqual(list.ImmutableCount, 0);
        }