forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API Implementation]: Add
Order
and OrderDescending
to `Enumerabl…
…e` and `Queryable` (dotnet#70525) * Implement proposal for `System.Linq` * Implement proposal for `System.Linq.Queryable` * Add documentation * Merge branch 'main' into issue-67194 * Add more test cases * Apply suggestions Co-Authored-By: Eirik Tsarpalis <[email protected]> * Remove unneccesary keyless stuff * Add more Queryable test cases * Eliminate `keySelector` null-check in ctor * Add null checks to `ThenBy` * Revert "Eliminate `keySelector` null-check in ctor" This reverts commit 879421b. * Add tests for CreateOrderedEnumerable * Apply suggestions * Fix null checks * Fix null checks * Update src/libraries/System.Linq/src/System/Linq/OrderBy.cs * Update src/libraries/System.Linq/src/System/Linq/OrderBy.cs Co-authored-by: Eirik Tsarpalis <[email protected]> Co-authored-by: Eirik Tsarpalis <[email protected]>
- Loading branch information
1 parent
bb36771
commit 436ee2e
Showing
13 changed files
with
1,082 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/libraries/System.Linq.Queryable/tests/OrderDescendingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Linq.Tests | ||
{ | ||
public sealed class OrderDescendingTests : EnumerableBasedTests | ||
{ | ||
[Fact] | ||
public void FirstAndLastAreDuplicatesCustomComparer() | ||
{ | ||
string[] source = { "Prakash", "Alpha", "DAN", "dan", "Prakash" }; | ||
string[] expected = { "Prakash", "Prakash", "DAN", "dan", "Alpha" }; | ||
|
||
Assert.Equal(expected, source.AsQueryable().OrderDescending(StringComparer.OrdinalIgnoreCase)); | ||
} | ||
|
||
[Fact] | ||
public void FirstAndLastAreDuplicatesNullPassedAsComparer() | ||
{ | ||
int[] source = { 5, 1, 3, 2, 5 }; | ||
int[] expected = { 5, 5, 3, 2, 1 }; | ||
|
||
Assert.Equal(expected, source.AsQueryable().OrderDescending(null)); | ||
} | ||
|
||
[Fact] | ||
public void NullSource() | ||
{ | ||
IQueryable<int> source = null; | ||
AssertExtensions.Throws<ArgumentNullException>("source", () => source.OrderDescending()); | ||
} | ||
|
||
[Fact] | ||
public void NullSourceComparer() | ||
{ | ||
IQueryable<int> source = null; | ||
AssertExtensions.Throws<ArgumentNullException>("source", () => source.OrderDescending(Comparer<int>.Default)); | ||
} | ||
|
||
[Fact] | ||
public void OrderDescending1() | ||
{ | ||
var count = (new int[] { 0, 1, 2 }).AsQueryable().OrderDescending().Count(); | ||
Assert.Equal(3, count); | ||
} | ||
|
||
[Fact] | ||
public void OrderDescending2() | ||
{ | ||
var count = (new int[] { 0, 1, 2 }).AsQueryable().OrderDescending(Comparer<int>.Default).Count(); | ||
Assert.Equal(3, count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Linq.Tests | ||
{ | ||
public sealed class OrderTests : EnumerableBasedTests | ||
{ | ||
[Fact] | ||
public void FirstAndLastAreDuplicatesCustomComparer() | ||
{ | ||
string[] source = { "Prakash", "Alpha", "dan", "DAN", "Prakash" }; | ||
string[] expected = { "Alpha", "dan", "DAN", "Prakash", "Prakash" }; | ||
|
||
Assert.Equal(expected, source.AsQueryable().Order(StringComparer.OrdinalIgnoreCase)); | ||
} | ||
|
||
[Fact] | ||
public void FirstAndLastAreDuplicatesNullPassedAsComparer() | ||
{ | ||
int[] source = { 5, 1, 3, 2, 5 }; | ||
int[] expected = { 1, 2, 3, 5, 5 }; | ||
|
||
Assert.Equal(expected, source.AsQueryable().Order(null)); | ||
} | ||
|
||
[Fact] | ||
public void NullSource() | ||
{ | ||
IQueryable<int> source = null; | ||
AssertExtensions.Throws<ArgumentNullException>("source", () => source.Order()); | ||
} | ||
|
||
[Fact] | ||
public void NullSourceComparer() | ||
{ | ||
IQueryable<int> source = null; | ||
AssertExtensions.Throws<ArgumentNullException>("source", () => source.Order(Comparer<int>.Default)); | ||
} | ||
|
||
[Fact] | ||
public void Order1() | ||
{ | ||
var count = (new int[] { 0, 1, 2 }).AsQueryable().Order().Count(); | ||
Assert.Equal(3, count); | ||
} | ||
|
||
[Fact] | ||
public void Order2() | ||
{ | ||
var count = (new int[] { 0, 1, 2 }).AsQueryable().Order(Comparer<int>.Default).Count(); | ||
Assert.Equal(3, count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.