本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# List.Sort方法的具体用法?C# List.Sort怎么用?C# List.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenericComparerAsIComparer
public void GenericComparerAsIComparer()
{
List<int> ints = new List<int>(new[] { 10, 5, 2, 23, 7, 5, 3, 45, 23, 64, 25 });
ints.Sort(new GenericComparer<int>());
Assert.AreEqual(ints.Min(), ints.First());
Assert.AreEqual(ints.Max(), ints.Last());
ints.Sort(new GenericComparer<int>((i, i1) => Math.Sin(i) > Math.Sin(i1) ? -1 : Math.Sin(i) < Math.Sin(i1) ? 1 : 0));
Assert.AreEqual(64, ints.First());
Assert.AreEqual(5, ints.Last());
}
示例2: createRandomProblem
public static Problem createRandomProblem(int numClasses) {
Problem prob = new Problem();
prob.bias = -1;
prob.l = random.Next(100) + 1;
prob.n = random.Next(100) + 1;
prob.x = new Feature[prob.l][];
prob.y = new double[prob.l];
for (int i = 0; i < prob.l; i++) {
prob.y[i] = random.Next(numClasses);
ISet<int> randomNumbers = new HashSet<int>();
int num = random.Next(prob.n) + 1;
for (int j = 0; j < num; j++) {
randomNumbers.Add(random.Next(prob.n) + 1);
}
List<int> randomIndices = new List<int>(randomNumbers);
randomIndices.Sort();
prob.x[i] = new Feature[randomIndices.Count];
for (int j = 0; j < randomIndices.Count; j++) {
prob.x[i][j] = new Feature(randomIndices[j], random.NextDouble());
}
}
return prob;
}
示例3: ListPersonsByNameReversedAndThenByAge
public void ListPersonsByNameReversedAndThenByAge()
{
// Arrange
var persons = new List<Person>
{
new Person {Age = 30, Name = "Martin"},
new Person {Age = 32, Name = "Martin"},
new Person {Age = 34, Name = "Audrey"},
new Person {Age = 14, Name = "Julien"},
new Person {Age = 24, Name = "Michal"},
new Person {Age = 94, Name = "Pierre"},
new Person {Age = 34, Name = "Catherine"},
new Person {Age = 74, Name = "Luca"},
new Person {Age = 34, Name = "Sophie"}
};
// Act
persons.Sort(Person.ByName.Reversed().ThenBy(Person.ByAge));
// Assert
foreach (var person in persons)
{
Console.Out.WriteLine($"{person.Name}\t\t {person.Age}");
}
}
示例4: EventsAreListedSorted
public void EventsAreListedSorted()
{
EventsManagerFast manager = new EventsManagerFast();
// Unsorted events
var events = new List<Event>
{
new Event(DateTime.Parse("2010-01-01"), "testB", "foo"),
new Event(minDate, "test", null),
new Event(minDate, "test", "bar"),
new Event(minDate, "test", "foo"),
new Event(minDate, "testB", "foo")
};
// Events are added unsorted
foreach (var ev in events)
{
manager.AddEvent(ev);
}
var managerEvents = manager.ListEvents(minDate, 5).ToList();
// Assert 5 are added
Assert.AreEqual(5, managerEvents.Count);
events.Sort();
CollectionAssert.AreEqual(events, managerEvents);
}
示例5: GenerateParenthesis
public string[] GenerateParenthesis(int n)
{
List<string> answer = new List<string>();
GenerateParenthesisRecursive(n, n, answer, "");
answer.Sort();
return answer.ToArray();
}
示例6: ExpectAddingCarsInRepoThenReturnSortedByYearToHaveCorrectResults
public void ExpectAddingCarsInRepoThenReturnSortedByYearToHaveCorrectResults()
{
byte specialCounter = 20;
short[] years = { 2013, 2001, 2004, 2000, 2010 };
List<int> expectedResultYears = new List<int>();
this.fakeCarsData.Remove(new Car());
for (var i = 0; i < specialCounter; i++)
{
var vartburg = new Car()
{
Id = (i + 1) * 1945,
Make = "GDR2",
Model = "Kombi" + i,
Year = years[i % years.Length]
};
this.controller.Add(vartburg);
expectedResultYears.Add(vartburg.Year);
}
var collection = (IList<Car>)this.GetModel(() => this.controller.Sort("year"));
expectedResultYears.Sort();
for (int car = 0; car < expectedResultYears.Count; car++)
{
Assert.AreEqual(expectedResultYears[car], collection[car].Year);
}
}
示例7: RouteInfoComparisonTest
public void RouteInfoComparisonTest()
{
// Create route infos and add them to a list out of order.
RouteInfo r101Both = new RouteInfo {
Name = "101",
LrsTypes = LrsTypes.Both
};
RouteInfo r005Both = new RouteInfo
{
Name = "005",
LrsTypes = LrsTypes.Both
};
RouteInfo r005Inc = new RouteInfo
{
Name = "005",
LrsTypes = LrsTypes.Increase
};
List<RouteInfo> routeInfo = new List<RouteInfo>();
routeInfo = new List<RouteInfo>(3);
routeInfo.Add(r101Both);
routeInfo.Add(r005Both);
routeInfo.Add(r005Inc);
// Sort the list and test for the expected order.
routeInfo.Sort();
Assert.AreEqual(routeInfo[0], r005Inc);
Assert.AreEqual(routeInfo[1], r005Both);
Assert.AreEqual(routeInfo[2], r101Both);
}
示例8: Unit_TehaiDaiminkanTest
public void Unit_TehaiDaiminkanTest()
{
Tehai testTehai = new Tehai(new List<string> { "1m", "2m", "3m", "4m", "5m", "6m", "7m", "8m", "9m", "1s", "2s", "3s", "1m" });
testTehai.Tsumo(new Pai("1m"));
//chi
var actor = 0;
var target = 3;
var furopai = new Pai("1m");
var consumed = new List<Pai> { new Pai("1m"), new Pai("1m"), new Pai("1m") };
consumed.Sort();
Assert.IsTrue(testTehai.tehai.Contains(new Pai("1m")));
//実施
testTehai.Daiminkan(actor, target, furopai, consumed);
//フーロオブジェクトの構成が正しいか
Assert.AreEqual(testTehai.furos[0].furoType, MJUtil.TartsuType.MINKANTSU);
Assert.AreEqual(testTehai.furos[0].furopai, furopai);
CollectionAssert.AreEqual(testTehai.furos[0].consumed, consumed);
//晒した牌が手配に残っていないか
Assert.IsFalse(testTehai.tehai.Contains(new Pai("1m")));
}
示例9: Can_Sort_Cards_in_a_Hand_in_Ascending_Order_By_Value
public void Can_Sort_Cards_in_a_Hand_in_Ascending_Order_By_Value()
{
#region "Arrange"
var cards = new List<Card>
{
new Card('7', 'C'),
new Card('2', 'C'),
new Card('5', 'H'),
new Card('3', 'S'),
new Card('4', 'C'),
};
#endregion
#region "Act"
cards.Sort();
#endregion
#region "Assert"
Assert.AreEqual(2, cards[0].Value);
Assert.AreEqual(3, cards[1].Value);
Assert.AreEqual(4, cards[2].Value);
Assert.AreEqual(5, cards[3].Value);
Assert.AreEqual(7, cards[4].Value);
#endregion
}
示例10: SimpleList
public void SimpleList()
{
var list = new List<string>
{
"0.12",
"12",
"Potato",
"a0.012",
"10",
"potato",
"b1.2",
"a1",
"1.2E-4",
"0.0012",
};
list.Sort(new NaturalSortComparer<string>());
Assert.AreEqual("1.2E-4", list[0]);
Assert.AreEqual("0.0012", list[1]);
Assert.AreEqual("0.12", list[2]);
Assert.AreEqual("10", list[3]);
Assert.AreEqual("12", list[4]);
Assert.AreEqual("Potato", list[5]);
Assert.AreEqual("a0.012", list[6]);
Assert.AreEqual("a1", list[7]);
Assert.AreEqual("b1.2", list[8]);
Assert.AreEqual("potato", list[9]);
}
示例11: ValidationErrors_Fields
public void ValidationErrors_Fields()
{
List<int> list;
int nextValue;
int numFields;
list = new List<int>();
numFields = 0;
foreach (FieldInfo field in typeof(ValidationError).GetFields(BindingFlags.Static | BindingFlags.NonPublic))
{
// Don't store the special values.
if ((field.Name != "BaseValue") && (field.Name != "LastUsedOffset"))
{
list.Add((int)field.GetValue(null));
numFields++;
}
}
Assert.AreNotEqual(0, numFields, "No fields were tested.");
list.Sort();
// Test that values are sequential and aren't duplicated.
nextValue = ValidationError.BaseValue + 1;
foreach (int value in list)
{
Assert.AreEqual(nextValue, value, "Value was not expected.");
nextValue++;
}
Assert.AreEqual(nextValue - 1,
ValidationError.BaseValue + ValidationError.LastUsedOffset,
"LastUsedOffset is incorrect.");
}
示例12: TrieTests_EnumerateInOrder2
public void TrieTests_EnumerateInOrder2()
{
Trie<char> trie = new Trie<char>();
List<string> items = new List<string>();
Random r = new Random();
for (int i = 0; i < 100000; i++)
{
char[] word = new char[r.Next(10) + 1];
for (int j = 0; j < word.Length; j++)
{
word[j] = (char)(97 + r.Next(26));
}
string sword = new string(word);
items.Add(sword);
trie.Insert(sword);
}
items.Sort();
var actualOrder = trie.EnumerateInOrder().Select(sequence => new string(sequence.ToArray())).ToList();
Assert.IsTrue(items.Except(actualOrder).Count() == 0);
Assert.IsTrue(actualOrder.Except(items).Count() == 0);
}
示例13: GetSortedDateTimes_ReturnsCorrectList
public void GetSortedDateTimes_ReturnsCorrectList()
{
DateTime dateNow = DateTime.Now;
var orderedDateRanges = new List<DateRange>();
orderedDateRanges.Add( new DateRange( dateNow, dateNow.AddMinutes( 100 ))); // +-----------------------------------------------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(10), dateNow.AddMinutes(10))); // +
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(10), dateNow.AddMinutes(10))); // +
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(10), dateNow.AddMinutes(20))); // +---+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(10), dateNow.AddMinutes(30))); // +-------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(20), dateNow.AddMinutes(60))); // +----------------------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(30), dateNow.AddMinutes(60))); // +------------------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(40), dateNow.AddMinutes(50))); // +------------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(42), dateNow.AddMinutes(47))); // +-----+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(45), dateNow.AddMinutes(45))); // +
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(70), dateNow.AddMinutes(75))); // +---+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(90), dateNow.AddMinutes(110))); // +--------------+
orderedDateRanges.Add(new DateRange(dateNow.AddMinutes(120), dateNow.AddMinutes(140))); // +-----------+
var result = orderedDateRanges.GetSortedDateTimes();
var correctDateTimes = new List<DateTime>();
orderedDateRanges.ForEach(x => correctDateTimes.AddRange(new List<DateTime> { x.StartTime, x.EndTime }));
correctDateTimes.Sort();
Assert.Equal( correctDateTimes, result);
}
示例14: 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.");
}
}
示例15: MomTest
public void MomTest()
{
Random r = new Random();
List<int> x = new List<int>(5000);
List<int> result = new List<int>(5000);
int size = 5000;
for (int i = 0; i < size; i++)
{
x.Add(r.Next(0, 100));
}
for (int i = 0; i < size; i++)
{
result.Add(x.Mom(i, Comparer<int>.Default));
}
x.Sort();
for (int i = 0; i < size; i++)
{
if (result[i] != x[i])
Assert.Fail($"{x[i]} != {result[i]}");
}
Assert.IsTrue(true);
}