示例#1
0
        public void ContainsClass()
        {
            const int LoopCount  = 1000;
            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 = i;
                list.Insert(list.Count, value);
                speedyList.Insert(speedyList.Count, 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]);
            }

            int total1 = 0;
            int total2 = 0;

            for (int i = 0; i < LoopCount; i++)
            {
                var value = new TestUserClass();
                value.Name  = i.ToString();
                value.Value = i;
                if (list.Contains(value))
                {
                    total1++;
                }
                if (speedyList.Contains(value))
                {
                    total2++;
                }
            }
            Console.WriteLine("total: " + total1);

            /*
             * for (int i = 0; i < speedyList.Count; i++) {
             *      Console.WriteLine(speedyList[i]);
             * }
             * //*/
            Assert.AreEqual(total1, total2);
        }
示例#2
0
        public void RemoveAt()
        {
            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++)
                {
                    int index = random.Next(list.Count);
                    list.RemoveAt(index);
                    speedyList.RemoveAt(index);
                }
                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);
                    bool contains1 = list.Contains(i);
                    bool contains2 = speedyList.Contains(i);
                    Assert.AreEqual(contains1, contains2);
                }

                for (int i = 0; i < LoopCount / 2; i++)
                {
                    int index  = random.Next(list.Count);
                    int index1 = list.IndexOf(index);
                    int index2 = speedyList.IndexOf(index);
                    Assert.AreEqual(index1, index2);
                }
            }
        }
示例#3
0
        public void ContainsString()
        {
            const int LoopCount  = 1000;
            var       list       = new List <string>();
            var       speedyList = new SpeedyList <string>();
            var       random     = new Random();

            for (int i = 0; i < LoopCount; i++)
            {
                string value = random.Next(LoopCount).ToString();
                list.Insert(list.Count, value);
                speedyList.Insert(speedyList.Count, 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]);
            }

            int total1 = 0;
            int total2 = 0;

            for (int i = 0; i < LoopCount; i++)
            {
                string value = i.ToString();
                if (list.Contains(value))
                {
                    total1++;
                }
                if (speedyList.Contains(value))
                {
                    total2++;
                }
            }
            Assert.AreEqual(total1, total2);
        }
示例#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);
                }
            }
        }