本文整理汇总了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.");
}
示例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);
}
示例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);
}
示例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.");
}
}
示例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.");
}
示例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.");
}
示例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);
}
示例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);
}
示例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);
}
示例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.");
}
示例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);
}
示例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.");
}
示例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.");
}
示例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());
}
}
示例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);
}