示例#1
0
        public void ToArray()
        {
            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[] array1 = list.ToArray();
                int[] array2 = speedyList.ToArray();
                Assert.AreEqual(array1.Length, array2.Length);

                for (int i = 0; i < array1.Length; i++)
                {
                    Assert.AreEqual(array1[i], array2[i]);
                }
            }
        }
示例#2
0
        public void TrueForAll()
        {
            const int TestCount = 1000;
            const int LoopCount = 1248;
            var       random    = new Random();

            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 n = 0; n < TestCount; n++)
            {
                int  checkIndex = random.Next(list.Count);
                bool result1    = list.TrueForAll(x => x < checkIndex);
                bool result2    = speedyList.TrueForAll(x => x < checkIndex);
                Assert.AreEqual(result1, result2);
            }
        }
示例#3
0
        public void Sort()
        {
            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);

                list.Sort();
                speedyList.Sort();
                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);
                }
            }
        }
示例#4
0
        public void Enumerator()
        {
            const int LoopCount  = 1000;
            var       list       = new List <int>();
            var       speedyList = new SpeedyList <int>();
            var       random     = new Random();

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

            int total1 = 0;
            int total2 = 0;

            foreach (int i in list)
            {
                total1 += i;
            }
            foreach (int i in speedyList)
            {
                total2 += i;
            }
            Assert.AreNotEqual(0, total1);
            Assert.AreEqual(total1, total2);
        }
示例#5
0
        public void LastIndexOf3()
        {
            const int LoopCount  = 1000;
            var       list       = new List <int>();
            var       speedyList = new SpeedyList <int>();
            var       random     = new Random();

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

            for (int i = 0; i < LoopCount; i++)
            {
                int index  = random.Next(1, list.Count);
                int count  = random.Next(1, index);
                int index1 = list.LastIndexOf(i, index, count);
                int index2 = speedyList.LastIndexOf(i, index, count);
                Assert.AreEqual(index1, index2);
            }
        }
示例#6
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]);
            }
        }
示例#7
0
        public void CopyTo()
        {
            const int LoopCount  = 1000;
            var       list       = new List <int>();
            var       speedyList = new SpeedyList <int>();
            var       random     = new Random();

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

            var array1 = new int[LoopCount];
            var array2 = new int[LoopCount];

            list.CopyTo(array1, 0);
            speedyList.CopyTo(array2, 0);

            for (int i = 0; i < LoopCount; i++)
            {
                Assert.AreNotEqual(0, array1[i]);
                Assert.AreEqual(array1[i], array2[i]);
            }
        }
示例#8
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);
        }
示例#9
0
        public void Constructor()
        {
            var list1 = new SpeedyList <int>();
            var list2 = new SpeedyList <string>();
            var list3 = new SpeedyList <TestUserClass>();

            var list4 = new SpeedyList <int>(10);

            var list  = new List <int>();
            var list5 = new SpeedyList <int>(list);

            for (int i = 0; i < 100; i++)
            {
                list.Add(i);
            }
            list5 = new SpeedyList <int>(list);
            Assert.AreEqual(100, list5.Count);
        }
示例#10
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]);
            }
        }
示例#11
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);
        }
示例#12
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]);
            }
        }
示例#13
0
        public void Insert()
        {
            const int LoopCount  = 1000;
            var       list       = new List <int>();
            var       speedyList = new SpeedyList <int>();
            var       random     = new Random();

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

            list.Clear();
            speedyList.Clear();
            for (int i = 0; i < LoopCount; i++)
            {
                int index = random.Next(list.Count);
                int value = random.Next(LoopCount) + 1;
                list.Insert(index, value);
                speedyList.Insert(index, value);
            }
            Assert.AreEqual(LoopCount, list.Count);
            Assert.AreEqual(list.Count, speedyList.Count);
        }
示例#14
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);
                }
            }
        }
示例#15
0
        public string Start()
        {
            List <int> list = new List <int>();

            for (int i = 0; i < 20000; i++)
            {
                list.Add(i / 1);
            }
            TestUtility.Shuffle(list);

            SpeedyList <int> speedyList = new SpeedyList <int>(list);

            StringBuilder text = new StringBuilder();

            text.AppendLine("[int test]");
            text.AppendLine();
            text.AppendLine("Generic List =====================");

            long time  = 0;
            long start = 0;
            long end   = 0;

            ///*
            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = AddTest(new List <int>());
            }, 1);
            text.Append(TestUtility.FormatResult("AddTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = InsertTest(new List <int>());
            }, 1);
            text.Append(TestUtility.FormatResult("InsertTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = IndexOfTest(list);
            }, 1);
            text.Append(TestUtility.FormatResult("IndexOfTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = ContainsTest(list);
            }, 1);
            text.Append(TestUtility.FormatResult("ContainsTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = RemoveTest(list);
            }, 1);
            text.Append(TestUtility.FormatResult("RemoveTest", time, end - start));
            //*/


            text.AppendLine();
            text.AppendLine("SpeedyList =======================");

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = AddTest(new SpeedyList <int>());
            }, 1);
            text.Append(TestUtility.FormatResult("AddTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = InsertTest(new SpeedyList <int>());
            }, 1);
            text.Append(TestUtility.FormatResult("InsertTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = IndexOfTest(speedyList);
            }, 1);
            text.Append(TestUtility.FormatResult("IndexOfTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = ContainsTest(speedyList);
            }, 1);
            text.Append(TestUtility.FormatResult("ContainsTest", time, end - start));

            time = Benchmark.Start(() => {
                start = GC.GetTotalMemory(true);
                end   = RemoveTest(speedyList);
            }, 1);
            text.Append(TestUtility.FormatResult("RemoveTest", time, end - start));

            return(text.ToString());
        }