2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Collections . Generic ;
5
+ using System . Diagnostics ;
5
6
using Xunit ;
6
7
7
8
namespace System . Linq . Tests
@@ -189,8 +190,9 @@ public void FollowingVariousOperators()
189
190
Assert . True ( transform ( source . Concat ( source ) ) . Distinct ( ) . Contains ( 2 ) ) ;
190
191
Assert . False ( transform ( source . Concat ( source ) ) . Distinct ( ) . Contains ( 4 ) ) ;
191
192
Assert . True ( transform ( source . Concat ( source ) ) . Distinct ( ) . Contains ( 1 ) ) ;
192
- Assert . True ( transform ( source . Concat ( source ) ) . Distinct ( EqualityComparer < int > . Create ( ( x , y ) => true ) ) . Contains ( 2 ) ) ;
193
- Assert . False ( transform ( source . Concat ( source ) ) . Distinct ( EqualityComparer < int > . Create ( ( x , y ) => true ) ) . Contains ( 0 ) ) ;
193
+ Assert . True ( transform ( source . Concat ( source ) ) . Distinct ( EqualityComparer < int > . Create ( ( x , y ) => true , x => 0 ) ) . Contains ( 1 ) ) ;
194
+ Assert . False ( transform ( source . Concat ( source ) ) . Distinct ( EqualityComparer < int > . Create ( ( x , y ) => true , x => 0 ) ) . Contains ( 2 ) ) ;
195
+ Assert . False ( transform ( source . Concat ( source ) ) . Distinct ( EqualityComparer < int > . Create ( ( x , y ) => true , x => 0 ) ) . Contains ( 0 ) ) ;
194
196
195
197
// OrderBy
196
198
Assert . True ( transformedSource . OrderBy ( x => x ) . Contains ( 2 ) ) ;
@@ -246,13 +248,21 @@ public void FollowingVariousOperators()
246
248
247
249
// Union
248
250
Assert . True ( transformedSource . Union ( transform ( [ 4 ] ) ) . Contains ( 4 ) ) ;
251
+ Assert . True ( transformedSource . Union ( transform ( [ 4 ] ) , EqualityComparer < int > . Create ( ( x , y ) => true , x => 0 ) ) . Contains ( 1 ) ) ;
252
+ Assert . False ( transformedSource . Union ( transform ( [ 4 ] ) , EqualityComparer < int > . Create ( ( x , y ) => true , x => 0 ) ) . Contains ( 4 ) ) ;
249
253
Assert . False ( transformedSource . Union ( transform ( [ 3 ] ) ) . Contains ( 4 ) ) ;
250
254
}
251
255
252
256
// DefaultIfEmpty
253
257
Assert . True ( Enumerable . Empty < int > ( ) . DefaultIfEmpty ( 1 ) . Contains ( 1 ) ) ;
254
258
Assert . False ( Enumerable . Empty < int > ( ) . DefaultIfEmpty ( 1 ) . Contains ( 0 ) ) ;
255
259
260
+ // Distinct
261
+ Assert . True ( new string [ ] { "a" , "A" } . Distinct ( ) . Contains ( "a" ) ) ;
262
+ Assert . True ( new string [ ] { "a" , "A" } . Distinct ( ) . Contains ( "A" ) ) ;
263
+ Assert . True ( new string [ ] { "a" , "A" } . Distinct ( StringComparer . OrdinalIgnoreCase ) . Contains ( "a" ) ) ;
264
+ Assert . False ( new string [ ] { "a" , "A" } . Distinct ( StringComparer . OrdinalIgnoreCase ) . Contains ( "A" ) ) ;
265
+
256
266
// Repeat
257
267
Assert . True ( Enumerable . Repeat ( 1 , 5 ) . Contains ( 1 ) ) ;
258
268
Assert . False ( Enumerable . Repeat ( 1 , 5 ) . Contains ( 2 ) ) ;
@@ -268,6 +278,12 @@ public void FollowingVariousOperators()
268
278
Assert . False ( new object [ ] { 1 , "2" , 3 } . OfType < int > ( ) . Contains ( 2 ) ) ;
269
279
Assert . True ( new object [ ] { 1 , "2" , 3 } . OfType < string > ( ) . Contains ( "2" ) ) ;
270
280
Assert . False ( new object [ ] { 1 , "2" , 3 } . OfType < string > ( ) . Contains ( "4" ) ) ;
281
+
282
+ // Union
283
+ Assert . True ( new string [ ] { "a" } . Union ( new string [ ] { "A" } ) . Contains ( "a" ) ) ;
284
+ Assert . True ( new string [ ] { "a" } . Union ( new string [ ] { "A" } ) . Contains ( "A" ) ) ;
285
+ Assert . True ( new string [ ] { "a" } . Union ( new string [ ] { "A" } , StringComparer . OrdinalIgnoreCase ) . Contains ( "a" ) ) ;
286
+ Assert . False ( new string [ ] { "a" } . Union ( new string [ ] { "A" } , StringComparer . OrdinalIgnoreCase ) . Contains ( "A" ) ) ;
271
287
}
272
288
}
273
289
}
0 commit comments