示例#1
0
        public void Remove()
        {
            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);

                for (int i = 0; i < LoopCount / 2; i++)
                {
                    list.Remove(i);
                    speedyList.Remove(i);
                }
                Assert.AreEqual(LoopCount / 2, list.Count);
                Assert.AreEqual(list.Count, speedyList.Count);

                for (int i = 0; i < LoopCount / 2; i++)
                {
                    Assert.AreEqual(list[i], speedyList[i]);
                    int index1 = list.IndexOf(i);
                    int index2 = speedyList.IndexOf(i);
                    Assert.AreEqual(index1, index2);
                }
            }
        }
示例#2
0
        public void ComplexTestString()
        {
            const int TestCount = 20;
            const int LoopCount = 999;
            var       random    = new Random();

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

                for (int i = 0; i < LoopCount + 1; i++)
                {
                    var value = i.ToString();
                    list.Add(value);
                    speedyList.Add(value);
                }
                Assert.AreNotEqual(0, list.Count);
                Assert.AreEqual(list.Count, speedyList.Count);

                for (int i = 0; i < LoopCount; i++)
                {
                    int method = random.Next(6);
                    int index  = random.Next(list.Count);
                    var value  = random.Next(LoopCount).ToString();
                    switch (method)
                    {
                    case 0:
                        list.Add(value);
                        speedyList.Add(value);
                        break;

                    case 1:
                        list.Insert(index, value);
                        speedyList.Insert(index, value);
                        break;

                    case 2:
                        list.Remove(value);
                        speedyList.Remove(value);
                        break;

                    case 3:
                        list.RemoveAt(index);
                        speedyList.RemoveAt(index);
                        break;

                    case 4:
                        list.Insert(index, null);
                        speedyList.Insert(index, null);
                        break;

                    case 5:
                        list.Remove(null);
                        speedyList.Remove(null);
                        break;

                    default:
                        Assert.IsTrue(false);
                        break;
                    }
                }
                Assert.AreNotEqual(0, list.Count);
                Assert.AreEqual(list.Count, speedyList.Count);

                for (int i = 0; i < list.Count; i++)
                {
                    Assert.AreEqual(list[i], speedyList[i]);
                    var value  = i.ToString();
                    int index1 = list.IndexOf(value);
                    int index2 = speedyList.IndexOf(value);
                    Assert.AreEqual(index1, index2);
                    bool contains1 = list.Contains(value);
                    bool contains2 = speedyList.Contains(value);
                    Assert.AreEqual(contains1, contains2);
                }
            }
        }