Пример #1
0
        public void Clear()
        {
            const int LoopCount  = 10000;
            var       list       = new List <int>();
            var       speedyList = new SpeedyList <int>();

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

            for (int i = 0; i < LoopCount; i++)
            {
                list.Add(i);
                speedyList.Add(i);
            }

            for (int i = 0; i < LoopCount; i++)
            {
                Assert.AreEqual(list[i], speedyList[i]);
            }
        }
Пример #2
0
        public void AddString()
        {
            const int LoopCount  = 10000;
            var       list       = new List <string>();
            var       speedyList = new SpeedyList <string>();

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

            for (int i = 0; i < LoopCount; i++)
            {
                Assert.AreEqual(list[i], speedyList[i]);
            }
        }
Пример #3
0
        public void AddClass()
        {
            const int LoopCount  = 10000;
            var       list       = new List <TestUserClass>();
            var       speedyList = new SpeedyList <TestUserClass>();
            var       random     = new Random();

            for (int i = 0; i < LoopCount; i++)
            {
                var value = new TestUserClass();
                value.Name  = i.ToString();
                value.Value = random.Next(LoopCount);
                list.Add(value);
                speedyList.Add(value);
            }
            Assert.AreEqual(LoopCount, list.Count);
            Assert.AreEqual(list.Count, speedyList.Count);

            for (int i = 0; i < LoopCount; i++)
            {
                Assert.AreEqual(list[i], speedyList[i]);
            }
        }
Пример #4
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);
                }
            }
        }