当前位置: 首页>>代码示例>>C#>>正文


C# SortableCollection.ToArray方法代码示例

本文整理汇总了C#中SortableCollection.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.ToArray方法的具体用法?C# SortableCollection.ToArray怎么用?C# SortableCollection.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortableCollection的用法示例。


在下文中一共展示了SortableCollection.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestWithEmptyCollectionShouldReturnMissingElement

        public void TestWithEmptyCollectionShouldReturnMissingElement()
        {
            var collection = new SortableCollection<int>();
            var elements = collection.ToArray();
            var result = collection.InterpolationSearch(ref elements, 0);
            var expected = Array.BinarySearch(collection.ToArray(), 0);

            Assert.AreEqual(expected, result, "No elements are present in an empty collection; method should return -1.");
        }
开发者ID:stoian2662,项目名称:Data-Structures-And-Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例2: TestWithItemToTheRightOfMidpoint

        public void TestWithItemToTheRightOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
            var elements = collection.ToArray();
            var result = collection.InterpolationSearch(ref elements, 4);
            var expected = Array.BinarySearch(collection.ToArray(), 4);

            Assert.AreEqual(expected, result);
        }
开发者ID:stoian2662,项目名称:Data-Structures-And-Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例3: TestWithItemToTheLeftOfMidpoint

        public void TestWithItemToTheLeftOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var sorter = new Quicksorter<int>();
            collection.Sort(sorter);
            var result = collection.InterpolationSearch(collection.ToArray(), 2);
            var expected = Array.BinarySearch(collection.ToArray(), 2);

            Assert.AreEqual(expected, result);
        }
开发者ID:pkanev,项目名称:Data.Structures,代码行数:11,代码来源:InterpolationSearchTests.cs

示例4: TestSortWithMultipleElementsMultipleTimes

        public void TestSortWithMultipleElementsMultipleTimes()
        {
            const int NumberOfAttempts = 10000;
            const int MaxNumberOfElements = 1000;

            for (int i = 0; i < NumberOfAttempts; i++)
            {
                var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);

                List<int> originalElements = new List<int>(MaxNumberOfElements);

                for (int j = 0; j < numberOfElements; j++)
                {
                    originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
                }

                var collection = new SortableCollection<int>(originalElements);

                originalElements.Sort();
                collection.Sort(TestSorter);

                CollectionAssert.AreEqual(
                    originalElements,
                    collection.ToArray(),
                    "Sort method should sort the elements in ascending order.");
            }
        }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:27,代码来源:SortTests.cs

示例5: TestWithMissingElement

        public void TestWithMissingElement()
        {
            var collection = new SortableCollection<int>(-1, 1, 5, 12, 50);
            var elements = collection.ToArray();
            var result = collection.InterpolationSearch(ref elements, 0);
            var expected = -1;

            Assert.AreEqual(expected, result, "Missing element should return -1.");
        }
开发者ID:stoian2662,项目名称:Data-Structures-And-Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例6: InterpolationTest1

        public void InterpolationTest1()
        {
            var collection = new SortableCollection<int>();

            var result = collection.InterpolationSearch(0);
            var expected = Array.BinarySearch(collection.ToArray(), 0);

            Assert.AreEqual(expected, result, "No elements are present in an empty collection; method should return -1.");
        }
开发者ID:sideroff,项目名称:Softuni,代码行数:9,代码来源:InterpolationSearchTests.cs

示例7: TestWithItemToTheLeftOfMidpoint

        public void TestWithItemToTheLeftOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var result = collection.BinarySearch(2);
            var expected = Array.BinarySearch(collection.ToArray(), 2);

            Assert.AreEqual(expected, result);
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:9,代码来源:BinarySearchTests.cs

示例8: InterpolationTest5

        public void InterpolationTest5()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var result = collection.InterpolationSearch(4);
            var expected = Array.BinarySearch(collection.ToArray(), 4);

            Assert.AreEqual(expected, result);
        }
开发者ID:sideroff,项目名称:Softuni,代码行数:9,代码来源:InterpolationSearchTests.cs

示例9: TestWithItemAtMidpoint

        public void TestWithItemAtMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var result = collection.InterpolationSearch(3);
            var expected = Array.BinarySearch(collection.ToArray(), 3);

            Assert.AreEqual(expected, result);
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例10: TestSortWithNoElements

        public void TestSortWithNoElements()
        {
            var emptyCollection = new SortableCollection<int>();
            emptyCollection.Sort(TestSorter);

            CollectionAssert.AreEqual(
                new int[0],
                emptyCollection.ToArray(),
                "Sorting empty collection should have no effect.");
        }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:10,代码来源:SortTests.cs

示例11: TestWithItemToTheLeftOfMidpoint

        public void TestWithItemToTheLeftOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
            this.ApplyDelegates(ref collection);

            var result = collection.InterpolationSearch(2);
            var expected = Array.BinarySearch(collection.ToArray(), 2);

            Assert.AreEqual(expected, result);
        }
开发者ID:EBojilova,项目名称:Algorithms-CSharp,代码行数:10,代码来源:InterpolationSearchTests.cs

示例12: TestWithEmptyCollectionShouldReturnMissingElement

        public void TestWithEmptyCollectionShouldReturnMissingElement()
        {
            var collection = new SortableCollection<int>();
            // the idea for the delegates is given from ttitto
            this.ApplyDelegates(ref collection);
            var result = collection.InterpolationSearch(0);
            var expected = Array.BinarySearch(collection.ToArray(), 0);

            Assert.AreEqual(
                expected,
                result,
                "No elements are present in an empty collection; method should return -1.");
        }
开发者ID:EBojilova,项目名称:Algorithms-CSharp,代码行数:13,代码来源:InterpolationSearchTests.cs

示例13: TestSortWithMultipleElements

        public void TestSortWithMultipleElements()
        {
            var collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
            var copy = new[] { 3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48 };

            collection.Sort(TestSorter);
            Array.Sort(copy);

            CollectionAssert.AreEqual(
                copy,
                collection.ToArray(),
                "Sort method should sort the elements in ascending order.");
        }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:13,代码来源:SortTests.cs

示例14: TestSortWithMultipleRandomElements

        public void TestSortWithMultipleRandomElements()
        {
            for (int i = 0; i < NumberOfTests; i++)
            {
                int numberOfElements = Random.Next(MinNumberOfElementsToSort, MaxNumberOfElementsToSort + 1);
                int maxValue = Random.Next(MaxValueCeiling);

                int[] elements = new int[numberOfElements];

                for (int j = 0; j < numberOfElements; j++)
                {
                    elements[j] = Random.Next(maxValue);
                }

                var collection = new SortableCollection<int>(elements);

                Array.Sort(elements);
              //  collection.Sort(new BucketSorter { Max = maxValue });

                CollectionAssert.AreEqual(elements, collection.ToArray());
            }
        }
开发者ID:mirko123,项目名称:Sorting-Algorithms,代码行数:22,代码来源:BucketSortTests.cs

示例15: TestWithRepeatingItemShouldReturnFirstDiscoveredIndex

        public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
        {
            var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
            var elements = collection.ToArray();
            var result = collection.InterpolationSearch(ref elements, 3);

            Assert.AreEqual(4, result);
        }
开发者ID:stoian2662,项目名称:Data-Structures-And-Algorithms,代码行数:8,代码来源:InterpolationSearchTests.cs


注:本文中的SortableCollection.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。