示例#1
0
        public void RemoveAll()
        {
            const int TestCount = 10;
            const int LoopCount = 1248;
            var       random    = new Random();

            for (int n = 0; n < TestCount; n++)
            {
                var list       = new List <int>();
                var speedyList = new SpeedyList <int>();

                for (int i = 0; i < LoopCount; i++)
                {
                    int index = random.Next(list.Count);
                    list.Insert(index, i);
                    speedyList.Insert(index, i);
                }
                Assert.AreEqual(LoopCount, list.Count);
                Assert.AreEqual(list.Count, speedyList.Count);

                int removeIndex = random.Next(list.Count);
                int count1      = list.RemoveAll(x => x < removeIndex);
                int count2      = speedyList.RemoveAll(x => x < removeIndex);
                Assert.AreEqual(count1, count2);
                Assert.AreEqual(list.Count, speedyList.Count);

                for (int i = 0; i < list.Count; i++)
                {
                    Assert.AreEqual(list[i], speedyList[i]);
                    int index1 = list.IndexOf(i);
                    int index2 = speedyList.IndexOf(i);
                    Assert.AreEqual(index1, index2);
                }
            }
        }