Problem with LazyOrderBy with multiple ThenBy
Closed this issue · 1 comments
GranBurguesa commented
I haven't figured out the problem exactly, but the following test fails fof me on VS2010, .net 4.0:
[Test]
public void SortFirstAscendingSecondDescendingThirdAscending()
{
Random random = new Random(3);
var data = new Triple[100000];
for (int index = 0; index < data.Length; index++)
data[index] = new Triple(random.Next(100), random.Next(100), random.Next(100));
var sorted1 = data.OrderBy(x => x.First).ThenByDescending(x => x.Second).ThenBy(x => x.Third);
var sorted2 = data.LazyOrderBy(x => x.First).ThenByDescending(x => x.Second).ThenBy(x => x.Third);
CollectionAssert.AreEqual(sorted1, sorted2);
}
I think the problem is in ElementComparer.Append, though I'm not sure how it should be fixed.
bgrainger commented
You were correct: ElementComparer.Append
was implemented incorrectly. If multiple ThenBy
operators were chained, it would drop the initial OrderBy
comparison.