コード例 #1
0
        private void TestTransform(int count, int[] expect, int commonTailLength, params XfAction[] actions)
        {
            WList <int> list = new WList <int>();

            for (int i = 0; i < count; i++)
            {
                list.Add(i + 1);
            }

            int         counter = 0;
            WList <int> result  =
                list.Transform(delegate(int i, ref int item) {
                if (i >= 0)
                {
                    Assert.AreEqual(list[i], item);
                }
                item *= 10;
                return(actions[counter++]);
            });

            Assert.AreEqual(counter, actions.Length);

            ExpectList(result, expect);

            Assert.That(result.WithoutLast(result.Count - commonTailLength)
                        == list.WithoutLast(list.Count - commonTailLength));

            // Try to ensure there's no shared mutable memory by trashing the
            // result starting at the head, and verifying the original list
            for (int i = result.Count - 1; i >= 0; i--)
            {
                result[i] = -1;
            }
            Assert.AreEqual(count, list.Count);
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i + 1, list[i]);
            }
        }