Problem with LazyOrderBy with multiple ThenBy #17

Closed
GranBurguesa opened this Issue Nov 21, 2012 · 1 comment

2 participants

@GranBurguesa

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 bgrainger closed this in 0a2811b Nov 28, 2012
@bgrainger
Logos Bible Software member

You were correct: ElementComparer.Append was implemented incorrectly. If multiple ThenBy operators were chained, it would drop the initial OrderBy comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment