xbuild: use the AdditionalReferencePath items to locate assemblies
[mono.git] / mcs / class / System.Core / Test / System.Linq / EnumerableMoreTest.cs
1 //
2 // EnumerableMoreTest.cs
3 //
4 // Author:
5 //  Andreas Noever <andreas.noever@gmail.com>
6 //
7 // (C) 2007 Andreas Noever
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Linq;
33 using NUnit.Framework;
34
35
36 namespace MonoTests.System.Linq {
37
38         [TestFixture]
39         public class EnumerableMoreTest {
40
41                 class BigEnumerable : IEnumerable<int> {
42                         public readonly ulong Count;
43                         public BigEnumerable (ulong Count)
44                         {
45                                 this.Count = Count;
46                         }
47
48
49                         #region IEnumerable<int> Members
50
51                         public IEnumerator<int> GetEnumerator ()
52                         {
53                                 return new BigEnumerator (this);
54                         }
55
56                         #endregion
57
58                         #region IEnumerable Members
59
60                         IEnumerator IEnumerable.GetEnumerator ()
61                         {
62                                 throw new NotImplementedException ();
63                         }
64
65                         #endregion
66                 }
67
68                 class BigEnumerator : IEnumerator<int> {
69                         BigEnumerable Parent;
70                         private ulong current;
71
72                         public BigEnumerator (BigEnumerable parent)
73                         {
74                                 Parent = parent;
75                         }
76
77                         public int Current
78                         {
79                                 get { return 3; }
80                         }
81
82                         public void Dispose ()
83                         {
84                         }
85
86                         object IEnumerator.Current
87                         {
88                                 get { throw new NotImplementedException (); }
89                         }
90
91                         public bool MoveNext ()
92                         {
93                                 if (current == Parent.Count)
94                                         return false;
95                                 current++;
96                                 return true;
97                         }
98
99                         public void Reset ()
100                         {
101                                 throw new NotImplementedException ();
102                         }
103
104                 }
105
106                 public static void AssertException<T> (Action action) where T : Exception
107                 {
108                         try {
109                                 action ();
110                         }
111                         catch (T) {
112                                 return;
113                         }
114                         Assert.Fail ("Expected: " + typeof (T).Name);
115                 }
116
117                 static void AssertAreSame<K, V> (K expectedKey, IEnumerable<V> expectedValues, IGrouping<K, V> actual)
118                 {
119                         if (expectedValues == null) {
120                                 Assert.IsNull (actual);
121                                 return;
122                         }
123
124                         Assert.IsNotNull (actual);
125
126                         Assert.AreEqual (expectedKey, actual.Key);
127
128                         var ee = expectedValues.GetEnumerator ();
129                         var ea = actual.GetEnumerator ();
130
131                         while (ee.MoveNext ()) {
132                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
133                                 Assert.AreEqual (ee.Current, ea.Current);
134                         }
135
136                         if (ea.MoveNext ())
137                                 Assert.Fail ("Unexpected element: " + ee.Current);
138                 }
139
140                 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, IEnumerable<IGrouping<K, V>> actual)
141                 {
142                         if (expected == null) {
143                                 Assert.IsNull (actual);
144                                 return;
145                         }
146
147                         Assert.IsNotNull (actual);
148
149                         var ee = expected.GetEnumerator ();
150                         var ea = actual.GetEnumerator ();
151
152                         while (ee.MoveNext ()) {
153                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
154                                 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
155                         }
156
157                         if (ea.MoveNext ())
158                                 Assert.Fail ("Unexpected element: " + ee.Current.Key);
159                 }
160
161                 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, ILookup<K, V> actual)
162                 {
163                         if (expected == null) {
164                                 Assert.IsNull (actual);
165                                 return;
166                         }
167
168                         Assert.IsNotNull (actual);
169
170                         var ee = expected.GetEnumerator ();
171                         var ea = actual.GetEnumerator ();
172
173                         while (ee.MoveNext ()) {
174                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
175                                 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
176                         }
177
178                         if (ea.MoveNext ())
179                                 Assert.Fail ("Unexpected element: " + ee.Current.Key);
180                 }
181
182                 static void AssertAreSame<K, V> (IDictionary<K, V> expected, IDictionary<K, V> actual)
183                 {
184                         if (expected == null) {
185                                 Assert.IsNull (actual);
186                                 return;
187                         }
188
189                         Assert.IsNotNull (actual);
190
191                         var ee = expected.GetEnumerator ();
192                         var ea = actual.GetEnumerator ();
193
194                         while (ee.MoveNext ()) {
195                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + ", " + ee.Current.Value + "' expected.");
196                                 Assert.AreEqual (ee.Current.Key, ea.Current.Key);
197                                 Assert.AreEqual (ee.Current.Value, ea.Current.Value);
198                         }
199
200                         if (ea.MoveNext ())
201                                 Assert.Fail ("Unexpected element: " + ee.Current.Key + ", " + ee.Current.Value);
202                 }
203
204                 static void AssertAreSame<T> (IEnumerable<T> expected, IEnumerable<T> actual)
205                 {
206                         if (expected == null) {
207                                 Assert.IsNull (actual);
208                                 return;
209                         }
210
211                         Assert.IsNotNull (actual);
212
213                         IEnumerator<T> ee = expected.GetEnumerator ();
214                         IEnumerator<T> ea = actual.GetEnumerator ();
215
216                         while (ee.MoveNext ()) {
217                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
218                                 Assert.AreEqual (ee.Current, ea.Current);
219                         }
220
221                         if (ea.MoveNext ())
222                                 Assert.Fail ("Unexpected element: " + ea.Current);
223                 }
224
225                 [Test]
226                 public void FirstArgumentNullTest ()
227                 {
228                         string [] data = { "2", "1", "5", "3", "4" };
229
230
231                         // First<TSource> ()
232                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First (); });
233
234                         // First<TSource> (Func<TSource, bool>)
235                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First ((x => true)); });
236                         AssertException<ArgumentNullException> (delegate () { data.First ((Func<string, bool>) null); });
237                 }
238
239                 [Test]
240                 public void FirstTest ()
241                 {
242                         int [] data = { 2, 1, 5, 3, 4 };
243                         int [] empty = { };
244
245                         // First<TSource> ()
246                         Assert.AreEqual (2, data.First ());
247                         AssertException<InvalidOperationException> (delegate () { empty.First (); });
248
249                         // First<TSource> (Func<TSource, bool>)
250                         Assert.AreEqual (5, data.First (x => x == 5));
251                         AssertException<InvalidOperationException> (delegate () { empty.First (x => x == 5); });
252                         AssertException<InvalidOperationException> (delegate () { data.First (x => x == 6); });
253                 }
254
255                 [Test]
256                 public void FirstOrDefaultArgumentNullTest ()
257                 {
258                         string [] data = { "2", "1", "5", "3", "4" };
259
260
261                         // FirstOrDefault<TSource> ()
262                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault (); });
263
264                         // FirstOrDefault<TSource> (Func<string, bool>)
265                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault ((x => true)); });
266                         AssertException<ArgumentNullException> (delegate () { data.FirstOrDefault ((Func<string, bool>) null); });
267                 }
268
269                 [Test]
270                 public void FirstOrDefaultTest ()
271                 {
272                         int [] data = { 2, 1, 5, 3, 4 };
273                         int [] empty = { };
274
275
276                         // FirstOrDefault<TSource> ()
277                         Assert.AreEqual (2, data.FirstOrDefault ());
278                         Assert.AreEqual (0, empty.FirstOrDefault ());
279
280                         // FirstOrDefault<TSource> (Func<TSource, bool>)
281                         Assert.AreEqual (5, data.FirstOrDefault (x => x == 5));
282                         Assert.AreEqual (0, empty.FirstOrDefault (x => x == 5));
283                         Assert.AreEqual (0, data.FirstOrDefault (x => x == 6));
284
285                 }
286
287                 [Test]
288                 public void LastArgumentNullTest ()
289                 {
290                         string [] data = { "2", "1", "5", "3", "4" };
291
292
293                         // Last<TSource> ()
294                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (); });
295
296                         // Last<TSource> (Func<TSource, bool>)
297                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (x => true); });
298                         AssertException<ArgumentNullException> (delegate () { data.Last ((Func<string, bool>) null); });
299                 }
300
301                 [Test]
302                 public void LastTest ()
303                 {
304                         int [] data = { 2, 1, 1, 3, 4, 5 };
305                         int [] empty = { };
306
307                         // Last<TSource> ()
308                         Assert.AreEqual (5, data.Last ());
309                         AssertException<InvalidOperationException> (delegate () { empty.Last (); });
310
311                         // Last<TSource> (Func<TSource, bool>)
312                         Assert.AreEqual (4, data.Last (x => x < 5));
313                         AssertException<InvalidOperationException> (delegate () { empty.Last (x => x == 5); });
314                         AssertException<InvalidOperationException> (delegate () { data.Last (x => x == 6); });
315                 }
316
317                 [Test]
318                 public void LastOrDefaultArgumentNullTest ()
319                 {
320                         string [] data = { "2", "1", "5", "3", "4" };
321
322
323                         // LastOrDefault<TSource> ()
324                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (); });
325
326                         // LastOrDefault<TSource> (Func<TSource, bool>)
327                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (x => true); });
328                         AssertException<ArgumentNullException> (delegate () { data.LastOrDefault ((Func<string, bool>) null); });
329                 }
330
331                 [Test]
332                 public void LastOrDefaultTest ()
333                 {
334                         int [] data = { 2, 1, 5, 3, 4 };
335                         int [] empty = { };
336
337
338                         // LastOrDefault<TSource> ()
339                         Assert.AreEqual (4, data.LastOrDefault ());
340                         Assert.AreEqual (0, empty.LastOrDefault ());
341
342                         // LastOrDefault<TSource> (Func<TSource, bool>)
343                         Assert.AreEqual (3, data.LastOrDefault (x => x < 4));
344                         Assert.AreEqual (0, empty.LastOrDefault (x => x == 5));
345                         Assert.AreEqual (0, data.LastOrDefault (x => x == 6));
346                 }
347
348                 [Test]
349                 public void SingleArgumentNullTest ()
350                 {
351                         string [] data = { "2", "1", "5", "3", "4" };
352
353
354                         // Single<TSource> ()
355                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single (); });
356
357                         // Single<TSource> (Func<TSource, bool>)
358                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single ((x => true)); });
359                         AssertException<ArgumentNullException> (delegate () { data.Single ((Func<string, bool>) null); });
360                 }
361
362                 [Test]
363                 public void SingleTest ()
364                 {
365                         int [] data = { 2 };
366                         int [] data2 = { 2, 3, 5 };
367                         int [] empty = { };
368
369
370                         // Single<TSource> ()
371                         Assert.AreEqual (2, data.Single ());
372                         AssertException<InvalidOperationException> (delegate () { data2.Single (); });
373                         AssertException<InvalidOperationException> (delegate () { empty.Single (); });
374
375                         // Single<TSource> (Func<TSource, bool>)
376                         Assert.AreEqual (5, data2.Single (x => x == 5));
377                         AssertException<InvalidOperationException> (delegate () { data2.Single (x => false); });
378                         AssertException<InvalidOperationException> (delegate () { data2.Single (x => true); });
379                         AssertException<InvalidOperationException> (delegate () { empty.Single (x => true); });
380                 }
381
382                 [Test]
383                 public void SingleOrDefaultArgumentNullTest ()
384                 {
385                         string [] data = { "2", "1", "5", "3", "4" };
386
387
388                         // SingleOrDefault<TSource> ()
389                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (); });
390
391                         // SingleOrDefault<TSource> (Func<TSource, bool>)
392                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (x => true); });
393                         AssertException<ArgumentNullException> (delegate () { data.SingleOrDefault ((Func<string, bool>) null); });
394                 }
395
396                 [Test]
397                 public void SingleOrDefaultTest ()
398                 {
399                         int [] data = { 2 };
400                         int [] data2 = { 2, 3, 5 };
401                         int [] empty = { };
402
403
404                         // SingleOrDefault<TSource> ()
405                         Assert.AreEqual (2, data.SingleOrDefault ());
406                         Assert.AreEqual (0, empty.SingleOrDefault ());
407                         AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (); });
408
409
410                         // SingleOrDefault<TSource> (Func<TSource, bool>)
411                         Assert.AreEqual (3, data2.SingleOrDefault (x => x == 3));
412                         Assert.AreEqual (0, data2.SingleOrDefault (x => false));
413                         AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (x => true); });
414                 }
415
416                 [Test]
417                 public void ElementAtArgumentNullTest ()
418                 {
419                         //string [] data = { "2", "1", "5", "3", "4" };
420
421
422                         // ElementAt<TSource> (int)
423                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAt (0); });
424                 }
425
426                 [Test]
427                 public void ElementAtTest ()
428                 {
429                         int [] data = { 2, 3, 4, 5 };
430
431                         // ElementAt<string> (int)
432                         Assert.AreEqual (2, data.ElementAt (0));
433                         Assert.AreEqual (4, data.ElementAt (2));
434                         AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (-1); });
435                         AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (4); });
436                         AssertException<ArgumentOutOfRangeException> (delegate () { data.ElementAt (6); });
437                 }
438
439                 [Test]
440                 public void ElementAtOrDefaultArgumentNullTest ()
441                 {
442                         //string [] data = { "2", "1", "5", "3", "4" };
443
444
445                         // ElementAtOrDefault<TSource> (int)
446                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAtOrDefault (0); });
447                 }
448
449                 [Test]
450                 public void ElementAtOrDefaultTest ()
451                 {
452                         int [] data = { 2, 3, 4, 5 };
453                         int [] empty = { };
454
455
456                         // ElementAtOrDefault<TSource> (int)
457                         Assert.AreEqual (2, data.ElementAtOrDefault (0));
458                         Assert.AreEqual (4, data.ElementAtOrDefault (2));
459                         Assert.AreEqual (0, data.ElementAtOrDefault (-1));
460                         Assert.AreEqual (0, data.ElementAtOrDefault (4));
461                         Assert.AreEqual (0, empty.ElementAtOrDefault (4));
462                 }
463
464                 [Test]
465                 public void EmptyTest ()
466                 {
467                         IEnumerable<string> empty = Enumerable.Empty<string> ();
468                         Assert.IsFalse (empty.GetEnumerator ().MoveNext ());
469
470                 }
471
472                 [Test]
473                 public void AnyArgumentNullTest ()
474                 {
475                         string [] data = { "2", "1", "5", "3", "4" };
476
477
478                         // Any<TSource> ()
479                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (); });
480
481                         // Any<TSource> (Func<TSource, bool>)
482                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (x => true); });
483                         AssertException<ArgumentNullException> (delegate () { data.Any ((Func<string, bool>) null); });
484                 }
485
486                 [Test]
487                 public void AnyTest ()
488                 {
489                         int [] data = { 5, 2, 3, 1, 6 };
490                         int [] empty = { };
491
492
493                         // Any<TSource> ()
494                         Assert.IsTrue (data.Any ());
495                         Assert.IsFalse (empty.Any ());
496
497                         // Any<TSource> (Func<TSource, bool>)
498                         Assert.IsTrue (data.Any (x => x == 5));
499                         Assert.IsFalse (data.Any (x => x == 9));
500                         Assert.IsFalse (empty.Any (x => true));
501                 }
502
503                 [Test]
504                 public void AllArgumentNullTest ()
505                 {
506                         string [] data = { "2", "1", "5", "3", "4" };
507
508
509                         // All<TSource> (Func<TSource, bool>)
510                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).All (x => true); });
511                         AssertException<ArgumentNullException> (delegate () { data.All ((Func<string, bool>) null); });
512                 }
513
514                 [Test]
515                 public void AllTest ()
516                 {
517                         int [] data = { 5, 2, 3, 1, 6 };
518                         int [] empty = { };
519
520                         // All<TSource> (Func<TSource, bool>)
521                         Assert.IsTrue (data.All (x => true));
522                         Assert.IsFalse (data.All (x => x != 1));
523                         Assert.IsTrue (empty.All (x => false));
524                 }
525
526                 [Test]
527                 public void CountArgumentNullTest ()
528                 {
529                         string [] data = { "2", "1", "5", "3", "4" };
530
531
532                         // Count<TSource> ()
533                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (); });
534
535                         // Count<TSource> (Func<TSource, bool>)
536                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (x => true); });
537                         AssertException<ArgumentNullException> (delegate () { data.Count ((Func<string, bool>) null); });
538                 }
539
540                 [Test]
541                 public void CountTest ()
542                 {
543                         int [] data = { 5, 2, 3, 1, 6 };
544
545                         // Count<TSource> ()
546                         Assert.AreEqual (5, data.Count ());
547
548                         // Count<TSource> (Func<TSource, bool>)
549                         Assert.AreEqual (3, data.Count (x => x < 5));
550                 }
551
552
553                 //[Test]
554                 public void CountOverflowTest ()
555                 {
556                         //BigEnumerable data = new BigEnumerable ((ulong) int.MaxValue + 1);
557
558                         // Count<TSource> ()
559                         //AssertException<OverflowException> (delegate () { data.Count (); });
560
561                         // Count<TSource> (Func<TSource, bool>)
562                         //AssertException<OverflowException> (delegate () { data.Count (x => 3 == x); });
563
564                         // Documentation error: http://msdn2.microsoft.com/en-us/library/bb535181.aspx
565                         // An exception is only rasied if count > int.MaxValue. Not if source contains more than int.MaxValue elements.
566                         // AssertException<OverflowException> (delegate () { data.Count (x => 5 == x); });
567                 }
568
569                 [Test]
570                 public void LongCountArgumentNullTest ()
571                 {
572                         string [] data = { "2", "1", "5", "3", "4" };
573
574
575                         // LongCount<TSource> ()
576                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (); });
577
578                         // LongCount<TSource> (Func<TSource, bool>)
579                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (x => true); });
580                         AssertException<ArgumentNullException> (delegate () { data.LongCount ((Func<string, bool>) null); });
581                 }
582
583                 [Test]
584                 public void LongCountTest ()
585                 {
586                         int [] data = { 5, 2, 3, 1, 6 };
587
588                         //TODO: Overflow test...
589
590                         // LongCount<TSource> ()
591                         Assert.AreEqual (5, data.LongCount ());
592                         Assert.AreEqual (5, Enumerable.Range (0, 5).LongCount ());
593
594                         // LongCount<TSource> (Func<TSource, bool>)
595                         Assert.AreEqual (3, data.LongCount (x => x < 5));
596                 }
597
598                 [Test]
599                 public void ContainsArgumentNullTest ()
600                 {
601                         //string [] data = { "2", "1", "5", "3", "4" };
602
603
604                         // Contains<TSource> (TSource)
605                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2"); });
606
607                         // Contains<TSource> (TSource, IEqualityComparer<TSource>)
608                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2", (IEqualityComparer<string>) EqualityComparer<string>.Default); });
609                 }
610
611                 [Test]
612                 public void ContainsTest ()
613                 {
614                         int [] data = { 5, 2, 3, 1, 6 };
615
616
617                         // Contains<TSource> (TSource)
618                         Assert.IsTrue (data.Contains (2));
619                         Assert.IsFalse (data.Contains (0));
620
621                         // Contains<TSource> (TSource, IEqualityComparer<TSource>)
622                         Assert.IsTrue (data.Contains (2, EqualityComparer<int>.Default));
623                         Assert.IsFalse (data.Contains (0, EqualityComparer<int>.Default));
624                 }
625
626                 [Test]
627                 public void AggregateArgumentNullTest ()
628                 {
629                         string [] data = { "2", "1", "5", "3", "4" };
630
631
632                         // Aggregate<TSource> (Func<TSource, TSource, TSource>)
633                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ((x, y) => "test"); });
634                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ((Func<string, string, string>) null); });
635
636                         // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
637                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test"); });
638                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null); });
639
640                         // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
641                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test", x => "test"); });
642                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null, x => "test"); });
643                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (x, y) => "test", (Func<string, string>) null); });
644                 }
645
646                 [Test]
647                 public void AggregateTest ()
648                 {
649                         string [] data = { "2", "1", "5", "3", "4" };
650                         string [] empty = { };
651
652                         // Aggregate<TSource> (Func<TSource, TSource, TSource>)
653                         Assert.AreEqual ("21534", data.Aggregate ((x, y) => x + y));
654                         AssertException<InvalidOperationException> (delegate () { empty.Aggregate ((x, y) => x + y); }); //only this overload throws
655
656                         // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
657                         Assert.AreEqual ("initial21534", (data.Aggregate ("initial", (x, y) => x + y)));
658
659                         // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
660                         Assert.AreEqual ("INITIAL21534", data.Aggregate ("initial", (x, y) => x + y, (x => x.ToUpper ())));
661                 }
662
663                 [Test]
664                 public void SumArgumentNullTest ()
665                 {
666                         string [] data = { "2", "1", "5", "3", "4" };
667
668
669                         // Sum<TSource> (Func<TSource, int>)
670                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, int>) (x => 0)); });
671                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, int>) null); });
672
673                         // Sum<TSource> (Func<TSource, Nullable<int>>)
674                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
675                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<int>>) null); });
676
677                         // Sum<TSource> (Func<TSource, Int64>)
678                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Int64>) (x => 0L)); });
679                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Int64>) null); });
680
681                         // Sum<TSource> (Func<TSource, Nullable<Int64>>)
682                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
683                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Int64>>) null); });
684
685                         // Sum<TSource> (Func<TSource, Single>)
686                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Single>) (x => 0f)); });
687                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Single>) null); });
688
689                         // Sum<TSource> (Func<TSource, Nullable<Single>>)
690                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
691                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Single>>) null); });
692
693                         // Sum<TSource> (Func<TSource, Double>)
694                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Double>) (x => 0d)); });
695                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Double>) null); });
696
697                         // Sum<TSource> (Func<TSource, Nullable<Double>>)
698                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
699                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Double>>) null); });
700
701                         // Sum<TSource> (Func<TSource, Decimal>)
702                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Decimal>) (x => 0m)); });
703                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Decimal>) null); });
704
705                         // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
706                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
707                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Decimal>>) null); });
708
709                         // Sum (IEnumerable<int>)
710                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Sum (); });
711
712                         // Sum (IEnumerable<int?>)
713                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Sum (); });
714
715                         // Sum (IEnumerable<long>)
716                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Sum (); });
717
718                         // Sum (IEnumerable<long?>)
719                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Sum (); });
720
721                         // Sum (IEnumerable<float>)
722                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Sum (); });
723
724                         // Sum (IEnumerable<float?>)
725                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Sum (); });
726
727                         // Sum (IEnumerable<double>)
728                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Sum (); });
729
730                         // Sum (IEnumerable<double?>)
731                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Sum (); });
732
733                         // Sum (IEnumerable<decimal>)
734                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Sum (); });
735
736                         // Sum (IEnumerable<decimal?>)
737                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Sum (); });
738                 }
739
740                 [Test]
741                 public void SumTest ()
742                 {
743                         string [] data = { "2", "3", "5", "5" };
744
745                         //TODO: OverflowException
746
747                         // Sum<TSource> (Func<TSource, int>)
748                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, int>) (x => int.Parse (x))));
749                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, int>) (x => int.Parse (x))));
750
751                         // Sum<TSource> (Func<TSource, Nullable<int>>)
752                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
753                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
754
755                         // Sum<TSource> (Func<TSource, Int64>)
756                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
757                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
758
759                         // Sum<TSource> (Func<TSource, Nullable<Int64>>)
760                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
761                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
762
763                         // Sum<TSource> (Func<TSource, Single>)
764                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
765                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
766
767                         // Sum<TSource> (Func<TSource, Nullable<Single>>)
768                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
769                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
770
771                         // Sum<TSource> (Func<TSource, Double>)
772                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
773                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
774
775                         // Sum<TSource> (Func<TSource, Nullable<Double>>)
776                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
777                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
778
779                         // Sum<TSource> (Func<TSource, Decimal>)
780                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
781                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
782
783                         // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
784                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
785                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
786
787                         // Sum<> ()
788                         Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
789                         Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
790
791                         // Sum<> ()
792                         Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
793                         Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
794
795                         // Sum<> ()
796                         Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
797                         Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
798
799                         // Sum<> ()
800                         Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
801                         Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
802
803                         // Sum<> ()
804                         Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
805                         Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
806
807                         // Sum<> ()
808                         Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
809                         Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
810
811                         // Sum<> ()
812                         Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
813                         Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
814
815                         // Sum<> ()
816                         Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
817                         Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
818
819                         // Sum<> ()
820                         Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
821                         Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
822
823                         // Sum<> ()
824                         Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
825                         Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
826                 }
827
828                 [Test]
829                 public void MinArgumentNullTest ()
830                 {
831                         string [] data = { "2", "1", "5", "3", "4" };
832
833
834                         // Min<TSource> ()
835                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
836
837                         // Min<TSource> (Func<TSource, int>)
838                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, int>) (x => 0)); });
839                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, int>) null); });
840
841                         // Min<TSource> (Func<TSource, Nullable<int>>)
842                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
843                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<int>>) null); });
844
845                         // Min<TSource> (Func<TSource, Int64>)
846                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Int64>) (x => 0L)); });
847                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Int64>) null); });
848
849                         // Min<TSource> (Func<TSource, Nullable<Int64>>)
850                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
851                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Int64>>) null); });
852
853                         // Min<TSource> (Func<TSource, Single>)
854                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Single>) (x => 0f)); });
855                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Single>) null); });
856
857                         // Min<TSource> (Func<TSource, Nullable<Single>>)
858                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
859                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Single>>) null); });
860
861                         // Min<TSource> (Func<TSource, Double>)
862                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Double>) (x => 0d)); });
863                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Double>) null); });
864
865                         // Min<TSource> (Func<TSource, Nullable<Double>>)
866                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
867                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Double>>) null); });
868
869                         // Min<TSource> (Func<TSource, Decimal>)
870                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Decimal>) (x => 0m)); });
871                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Decimal>) null); });
872
873                         // Min<TSource> (Func<TSource, Nullable<Decimal>>)
874                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
875                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Decimal>>) null); });
876
877                         // Min<TSource,TSource> (Func<TSource, string>)
878                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string, string> ((Func<string, string>) (x => "test")); });
879                         AssertException<ArgumentNullException> (delegate () { data.Min<string, string> ((Func<string, string>) null); });
880
881                         // Min<> ()
882                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
883
884                         // Min<> ()
885                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
886
887                         // Min<> ()
888                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
889
890                         // Min<> ()
891                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
892
893                         // Min<> ()
894                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
895
896                         // Min<> ()
897                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
898
899                         // Min<> ()
900                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
901
902                         // Min<> ()
903                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
904
905                         // Min<> ()
906                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
907
908                         // Min<> ()
909                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
910                 }
911
912                 [Test]
913                 public void MinTest ()
914                 {
915                         string [] data = { "2", "1", "5", "3", "4" };
916
917
918                         // Min<TSource> ()
919                         Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
920
921
922                         // Min<TSource> (Func<TSource, int>)
923                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
924
925                         // Min<TSource> (Func<TSource, Nullable<int>>)
926                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
927
928                         // Min<TSource> (Func<TSource, Int64>)
929                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
930
931                         // Min<TSource> (Func<TSource, Nullable<Int64>>)
932                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
933
934                         // Min<TSource> (Func<TSource, Single>)
935                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
936
937                         // Min<TSource> (Func<TSource, Nullable<Single>>)
938                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
939
940                         // Min<TSource> (Func<TSource, Double>)
941                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
942
943                         // Min<TSource> (Func<TSource, Nullable<Double>>)
944                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
945
946                         // Min<TSource> (Func<TSource, Decimal>)
947                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
948
949                         // Min<TSource> (Func<TSource, Nullable<Decimal>>)
950                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
951
952                         // Min<TSource,TSource> (Func<TSource, TSource>)
953                         Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
954
955                         // Min<> ()
956                         Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
957
958                         // Min<> ()
959                         Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
960
961                         // Min<> ()
962                         Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
963
964                         // Min<> ()
965                         Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
966
967                         // Min<> ()
968                         Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
969
970                         // Min<> ()
971                         Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
972
973                         // Min<> ()
974                         Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
975
976                         // Min<> ()
977                         Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
978
979                         // Min<> ()
980                         Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
981
982                         // Min<> ()
983                         Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
984                 }
985
986                 [Test]
987                 public void MaxArgumentNullTest ()
988                 {
989                         string [] data = { "2", "1", "5", "3", "4" };
990
991
992                         // Max<TSource> ()
993                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
994
995                         // Max<TSource> (Func<TSource, int>)
996                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, int>) (x => 0)); });
997                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, int>) null); });
998
999                         // Max<TSource> (Func<TSource, Nullable<int>>)
1000                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
1001                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<int>>) null); });
1002
1003                         // Max<TSource> (Func<TSource, Int64>)
1004                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Int64>) (x => 0L)); });
1005                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Int64>) null); });
1006
1007                         // Max<TSource> (Func<TSource, Nullable<Int64>>)
1008                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
1009                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Int64>>) null); });
1010
1011                         // Max<TSource> (Func<TSource, Single>)
1012                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Single>) (x => 0f)); });
1013                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Single>) null); });
1014
1015                         // Max<TSource> (Func<TSource, Nullable<Single>>)
1016                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
1017                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Single>>) null); });
1018
1019                         // Max<TSource> (Func<TSource, Double>)
1020                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Double>) (x => 0d)); });
1021                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Double>) null); });
1022
1023                         // Max<TSource> (Func<TSource, Nullable<Double>>)
1024                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
1025                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Double>>) null); });
1026
1027                         // Max<TSource> (Func<TSource, Decimal>)
1028                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Decimal>) (x => 0m)); });
1029                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Decimal>) null); });
1030
1031                         // Max<TSource> (Func<TSource, Nullable<Decimal>>)
1032                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
1033                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Decimal>>) null); });
1034
1035                         // Max<TSource,TSource> (Func<TSource, TSource>)
1036                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string, string> ((Func<string, string>) (x => "test")); });
1037                         AssertException<ArgumentNullException> (delegate () { data.Max<string, string> ((Func<string, string>) null); });
1038
1039                         // Max<> ()
1040                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
1041
1042                         // Max<> ()
1043                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
1044
1045                         // Max<> ()
1046                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
1047
1048                         // Max<> ()
1049                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
1050
1051                         // Max<> ()
1052                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
1053
1054                         // Max<> ()
1055                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
1056
1057                         // Max<> ()
1058                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
1059
1060                         // Max<> ()
1061                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
1062
1063                         // Max<> ()
1064                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
1065
1066                         // Max<> ()
1067                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
1068                 }
1069
1070                 [Test]
1071                 public void MaxTest ()
1072                 {
1073                         string [] data = { "2", "1", "5", "3", "4" };
1074
1075
1076                         // Max<string> ()
1077                         Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
1078
1079                         // Max<TSource> (Func<TSource, int>)
1080                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
1081
1082                         // Max<TSource> (Func<TSource, Nullable<int>>)
1083                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
1084
1085                         // Max<TSource> (Func<TSource, Int64>)
1086                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
1087
1088                         // Max<TSource> (Func<TSource, Nullable<Int64>>)
1089                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
1090
1091                         // Max<TSource> (Func<TSource, Single>)
1092                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
1093
1094                         // Max<TSource> (Func<TSource, Nullable<Single>>)
1095                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
1096
1097                         // Max<TSource> (Func<TSource, Double>)
1098                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
1099
1100                         // Max<TSource> (Func<TSource, Nullable<Double>>)
1101                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
1102
1103                         // Max<TSource> (Func<TSource, Decimal>)
1104                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
1105
1106                         // Max<TSource> (Func<TSource, Nullable<Decimal>>)
1107                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
1108
1109                         // Max<TSource,TSource> (Func<TSource, TSource>)
1110                         Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
1111
1112                         // Max<> ()
1113                         Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
1114
1115                         // Max<> ()
1116                         Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
1117
1118                         // Max<> ()
1119                         Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
1120
1121                         // Max<> ()
1122                         Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
1123
1124                         // Max<> ()
1125                         Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
1126
1127                         // Max<> ()
1128                         Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
1129
1130                         // Max<> ()
1131                         Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
1132
1133                         // Max<> ()
1134                         Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
1135
1136                         // Max<> ()
1137                         Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
1138
1139                         // Max<> ()
1140                         Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
1141                 }
1142
1143                 [Test]
1144                 public void AverageArgumentNullTest ()
1145                 {
1146                         string [] data = { "2", "1", "5", "3", "4" };
1147
1148
1149                         // Average<TSource> (Func<TSource, int>)
1150                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, int>) (x => 0)); });
1151                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, int>) null); });
1152
1153                         // Average<TSource> (Func<TSource, Nullable<int>>)
1154                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
1155                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<int>>) null); });
1156
1157                         // Average<TSource> (Func<TSource, Int64>)
1158                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Int64>) (x => 0L)); });
1159                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Int64>) null); });
1160
1161                         // Average<TSource> (Func<TSource, Nullable<Int64>>)
1162                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
1163                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Int64>>) null); });
1164
1165                         // Average<TSource> (Func<TSource, Single>)
1166                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Single>) (x => 0f)); });
1167                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Single>) null); });
1168
1169                         // Average<TSource> (Func<TSource, Nullable<Single>>)
1170                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
1171                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Single>>) null); });
1172
1173                         // Average<TSource> (Func<TSource, Double>)
1174                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Double>) (x => 0d)); });
1175                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Double>) null); });
1176
1177                         // Average<TSource> (Func<TSource, Nullable<Double>>)
1178                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
1179                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Double>>) null); });
1180
1181                         // Average<TSource> (Func<TSource, Decimal>)
1182                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Decimal>) (x => 0m)); });
1183                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Decimal>) null); });
1184
1185                         // Average<TSource> (Func<TSource, Nullable<Decimal>>)
1186                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
1187                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Decimal>>) null); });
1188
1189                         // Average<> ()
1190                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
1191
1192                         // Average<> ()
1193                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
1194
1195                         // Average<> ()
1196                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
1197
1198                         // Average<> ()
1199                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
1200
1201                         // Average<> ()
1202                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
1203
1204                         // Average<> ()
1205                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
1206
1207                         // Average<> ()
1208                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
1209
1210                         // Average<> ()
1211                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
1212
1213                         // Average<> ()
1214                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
1215
1216                         // Average<> ()
1217                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
1218                 }
1219
1220                 [Test]
1221                 public void AverageTest ()
1222                 {
1223                         string [] data = { "2", "1", "5", "3", "4" };
1224                         string [] empty = { };
1225
1226                         // Average<string> (Func<string, int>)
1227                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, int>) (x => int.Parse (x))));
1228                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, int>) (x => int.Parse (x))); });
1229
1230                         // Average<TSource> (Func<TSource, Nullable<int>>)
1231                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
1232
1233                         // Average<TSource> (Func<TSource, Int64>)
1234                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long>) (x => int.Parse (x))));
1235                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, long>) (x => int.Parse (x))); });
1236
1237                         // Average<TSource> (Func<TSource, Nullable<Int64>>)
1238                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
1239
1240                         // Average<TSource> (Func<TSource, Single>)
1241                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float>) (x => int.Parse (x))));
1242                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, float>) (x => int.Parse (x))); });
1243
1244                         // Average<TSource> (Func<TSource, Nullable<Single>>)
1245                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
1246
1247                         // Average<TSource> (Func<TSource, Double>)
1248                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double>) (x => int.Parse (x))));
1249                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, double>) (x => int.Parse (x))); });
1250
1251                         // Average<TSource> (Func<TSource, Nullable<Double>>)
1252                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
1253
1254                         // Average<TSource> (Func<TSource, Decimal>)
1255                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal>) (x => int.Parse (x))));
1256                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, decimal>) (x => int.Parse (x))); });
1257
1258                         // Average<TSource> (Func<TSource, Nullable<Decimal>>)
1259                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
1260
1261
1262                         // Average<> ()
1263                         Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
1264                         AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
1265
1266                         // Average<> ()
1267                         Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
1268
1269                         // Average<> ()
1270                         Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
1271                         AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
1272
1273                         // Average<> ()
1274                         Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
1275
1276                         // Average<> ()
1277                         Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
1278                         AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
1279
1280                         // Average<> ()
1281                         Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
1282
1283                         // Average<> ()
1284                         Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
1285                         AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
1286
1287                         // Average<> ()
1288                         Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
1289
1290                         // Average<> ()
1291                         Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
1292                         AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
1293
1294                         // Average<> ()
1295                         Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
1296                 }
1297
1298                 [Test]
1299                 public void WhereArgumentNullTest ()
1300                 {
1301                         string [] data = { "2", "1", "5", "3", "4" };
1302
1303                         // Where<TSource> (Func<TSource, bool>)
1304                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where (x => true); });
1305                         AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, bool>) null); });
1306
1307                         // Where<TSource> (Func<TSource, int, bool>)
1308                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where ((x, y) => true); });
1309                         AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, int, bool>) null); });
1310                 }
1311
1312                 [Test]
1313                 public void WhereTest ()
1314                 {
1315                         int [] data = { 2, 1, 5, 3, 4 };
1316                         int [] expected1 = { 2, 1 };
1317                         int [] expected2 = { 2 };
1318
1319                         // Where<TSource> (Func<TSource, bool>)
1320                         AssertAreSame (expected1, data.Where (x => x < 3));
1321
1322                         // Where<TSource> (Func<TSource, int, bool>)
1323                         AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
1324                 }
1325
1326                 [Test]
1327                 public void SelectArgumentNullTest ()
1328                 {
1329                         string [] data = { "2", "1", "5", "3", "4" };
1330
1331
1332                         // Select<TSource,TResult> (Func<TSource, TResult>)
1333                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select (x => "test"); });
1334                         AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, string>) null); });
1335
1336                         // Select<TSource,TResult> (Func<TSource, int, TResult>)
1337                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select ((x, y) => "test"); });
1338                         AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, int, string>) null); });
1339                 }
1340
1341                 [Test]
1342                 public void SelectTest ()
1343                 {
1344                         string [] data = { "2", "1", "5", "3", "4" };
1345                         string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
1346                         string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
1347
1348
1349                         // Select<TSource,TResult> (Func<TSource, TResult>)
1350                         AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
1351
1352                         // Select<TSource,TResult> (Func<TSource, int, TResult>)
1353                         AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
1354                 }
1355
1356                 [Test]
1357                 public void SelectManyArgumentNullTest ()
1358                 {
1359                         string [] data = { "2", "1", "5", "3", "4" };
1360
1361
1362                         // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
1363                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data); });
1364                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null); });
1365
1366                         // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
1367                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data); });
1368                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null); });
1369
1370                         // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1371                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data, (x, y) => "test"); });
1372                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null, (x, y) => "test"); });
1373                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((x, y) => data, (Func<string, string, string>) null); });
1374
1375                         // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1376                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data, (x, y) => "test"); });
1377                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null, (x, y) => "test"); });
1378                         AssertException<ArgumentNullException> (delegate () { data.SelectMany (x => data, (Func<string, string, string>) null); });
1379                 }
1380
1381                 [Test]
1382                 public void SelectManyTest ()
1383                 {
1384                         string [] data = { "0", "1" };
1385                         string [] expected = { "0", "00", "1", "11" };
1386
1387                         // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
1388                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
1389
1390                         // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
1391                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
1392
1393                         // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1394                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }, (x, y) => y));
1395
1396                         // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1397                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }, (x, y) => y));
1398                 }
1399
1400                 [Test]
1401                 public void TakeArgumentNullTest ()
1402                 {
1403                         //string [] data = { "2", "1", "5", "3", "4" };
1404
1405
1406                         // Take<TSource> (int)
1407                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
1408                 }
1409
1410                 [Test]
1411                 public void TakeTest ()
1412                 {
1413                         int [] data = { 2, 1, 5, 3, 1 };
1414                         int [] expected = { 2, 1 };
1415                         int [] empty = { };
1416
1417                         // Take<TSource> (int)
1418                         AssertAreSame (expected, data.Take (2));
1419                         AssertAreSame (empty, data.Take (-2));
1420                 }
1421
1422                 [Test]
1423                 public void TakeWhileArgumentNullTest ()
1424                 {
1425                         string [] data = { "2", "1", "5", "3", "4" };
1426
1427
1428                         // TakeWhile<TSource> (Func<TSource, bool>)
1429                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile (x => true); });
1430                         AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, bool>) null); });
1431
1432                         // TakeWhile<TSource> (Func<TSource, int, bool>)
1433                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile ((x, y) => true); });
1434                         AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, int, bool>) null); });
1435                 }
1436
1437                 [Test]
1438                 public void TakeWhileTest ()
1439                 {
1440                         int [] data = { 2, 1, 5, 3, 1 };
1441                         int [] expected = { 2, 1 };
1442
1443
1444                         // TakeWhile<TSource> (Func<TSource, bool>)
1445                         AssertAreSame (expected, data.TakeWhile (x => x != 5));
1446
1447                         // TakeWhile<TSource> (Func<TSource, int, bool>)
1448                         AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
1449                 }
1450
1451                 [Test]
1452                 public void SkipArgumentNullTest ()
1453                 {
1454                         //string [] data = { "2", "1", "5", "3", "4" };
1455
1456
1457                         // Skip<TSource> (int)
1458                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
1459                 }
1460
1461                 [Test]
1462                 public void SkipTest ()
1463                 {
1464                         int [] data = { 2, 1, 5, 3, 1 };
1465                         int [] expected = { 5, 3, 1 };
1466
1467                         // Skip<string> (TSource)
1468                         AssertAreSame (expected, data.Skip (2));
1469                         AssertAreSame (data, data.Skip (-2));
1470                 }
1471
1472                 [Test]
1473                 public void SkipWhileArgumentNullTest ()
1474                 {
1475                         string [] data = { "2", "1", "5", "3", "4" };
1476
1477
1478                         // SkipWhile<TSource> (Func<TSource, bool>)
1479                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile (x => true); });
1480                         AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, bool>) null); });
1481
1482                         // SkipWhile<TSource> (Func<TSource, int, bool>)
1483                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile ((x, y) => true); });
1484                         AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, int, bool>) null); });
1485                 }
1486
1487                 [Test]
1488                 public void SkipWhileTest ()
1489                 {
1490                         int [] data = { 2, 1, 5, 3, 1 };
1491                         int [] expected = { 5, 3, 1 };
1492
1493
1494
1495                         // SkipWhile<TSource> (Func<TSource, bool>)
1496                         AssertAreSame (expected, data.SkipWhile (x => x != 5));
1497
1498                         // SkipWhile<TSource> (Func<TSource, int, bool>)
1499                         AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
1500                 }
1501
1502                 [Test]
1503                 public void JoinArgumentNullTest ()
1504                 {
1505                         string [] data = { "2", "1", "5", "3", "4" };
1506
1507
1508                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
1509                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test"); });
1510                         AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
1511                         AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
1512                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
1513                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null); });
1514
1515                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
1516                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1517                         AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1518                         AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1519                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
1520                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null, EqualityComparer<string>.Default); });
1521                 }
1522
1523                 [Test]
1524                 public void JoinTest ()
1525                 {
1526                         string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1527                         string [] dataInner1 = { "7", "3", "5", "8", "9" };
1528                         string [] expected1 = { "55", "33" };
1529
1530                         string [] dataOuter2 = { "2", "1", "3", "4" };
1531                         string [] dataInner2 = { "7", "5", "8", "9" };
1532                         string [] expected2 = { };
1533
1534
1535                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
1536                         AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y));
1537                         AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y));
1538
1539                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
1540                         AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
1541                         AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
1542                 }
1543
1544                 [Test]
1545                 public void GroupJoinArgumentNullTest ()
1546                 {
1547                         string [] data = { "2", "1", "5", "3", "4" };
1548
1549
1550                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
1551                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test"); });
1552                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
1553                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
1554                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
1555                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null); });
1556
1557                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
1558                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1559                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1560                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1561                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
1562                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null, EqualityComparer<string>.Default); });
1563                 }
1564
1565                 [Test]
1566                 public void GroupJoinTest ()
1567                 {
1568                         string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1569                         string [] dataInner1 = { "7", "3", "5", "3", "9" };
1570                         string [] expected1 = { "2", "1", "55", "333", "4" };
1571
1572                         string [] dataOuter2 = { "2", "1", "5", "8", "4" };
1573                         string [] dataInner2 = { "7", "3", "6", "3", "9" };
1574                         string [] expected2 = { "2", "1", "5", "8", "4" };
1575
1576
1577                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
1578                         AssertAreSame (expected1, (dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
1579                         AssertAreSame (expected2, (dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
1580
1581                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
1582                         AssertAreSame (expected1, dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1583                         AssertAreSame (expected2, dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1584                 }
1585
1586                 [Test]
1587                 public void OrderByArgumentNullTest ()
1588                 {
1589                         string [] data = { "2", "1", "5", "3", "4" };
1590
1591
1592                         // OrderBy<TSource,TKey> (Func<TSource, TKey>)
1593                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test"); });
1594                         AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null); });
1595
1596                         // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1597                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test", Comparer<string>.Default); });
1598                         AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null, Comparer<string>.Default); });
1599                 }
1600
1601                 [Test]
1602                 public void OrderByTest ()
1603                 {
1604                         int [] data = { 2, 1, 5, 3, 4 };
1605                         int [] expected = { 1, 2, 3, 4, 5 };
1606
1607
1608                         // OrderBy<TSource,TKey> (Func<TSource, TKey>)
1609                         AssertAreSame (expected, data.OrderBy (x => x));
1610
1611                         // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1612                         AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
1613                 }
1614
1615                 [Test]
1616                 public void OrderByDescendingArgumentNullTest ()
1617                 {
1618                         string [] data = { "2", "1", "5", "3", "4" };
1619
1620
1621                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
1622                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test"); });
1623                         AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null); });
1624
1625                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1626                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test", Comparer<string>.Default); });
1627                         AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null, Comparer<string>.Default); });
1628                 }
1629
1630                 [Test]
1631                 public void OrderByDescendingTest ()
1632                 {
1633                         int [] data = { 2, 1, 5, 3, 4 };
1634                         int [] expected = { 5, 4, 3, 2, 1 };
1635
1636
1637                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
1638                         AssertAreSame (expected, data.OrderByDescending (x => x));
1639
1640                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1641                         AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
1642                 }
1643
1644                 [Test]
1645                 public void ThenByArgumentNullTest ()
1646                 {
1647                         string [] data = { "2", "1", "5", "3", "4" };
1648
1649
1650                         // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1651                         AssertException<ArgumentNullException> (delegate () {
1652                                 ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
1653                         });
1654                         AssertException<ArgumentNullException> (delegate () {
1655                                 data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
1656                         });
1657
1658                         // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1659                         AssertException<ArgumentNullException> (delegate () {
1660
1661                                 ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
1662                         });
1663                         AssertException<ArgumentNullException> (delegate () {
1664
1665                                 data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
1666                         });
1667                 }
1668
1669                 [Test]
1670                 public void ThenByTest ()
1671                 {
1672                         int [] data = { 2, 1, 5, 3, 4 };
1673                         int [] expected = { 1, 2, 3, 4, 5 };
1674
1675
1676                         // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1677                         AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
1678
1679                         // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1680                         AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
1681                 }
1682
1683                 [Test]
1684                 public void ThenByDescendingArgumentNullTest ()
1685                 {
1686                         string [] data = { "2", "1", "5", "3", "4" };
1687
1688
1689                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1690                         AssertException<ArgumentNullException> (delegate () {
1691                                 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
1692                         });
1693                         AssertException<ArgumentNullException> (delegate () {
1694                                 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
1695                         });
1696
1697                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1698                         AssertException<ArgumentNullException> (delegate () {
1699
1700                                 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
1701                         });
1702                         AssertException<ArgumentNullException> (delegate () {
1703
1704                                 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
1705                         });
1706                 }
1707
1708                 [Test]
1709                 public void ThenByDescendingTest ()
1710                 {
1711                         int [] data = { 2, 1, 5, 3, 4 };
1712                         int [] expected = { 5, 4, 3, 2, 1 };
1713
1714
1715                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1716                         AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
1717
1718                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1719                         AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
1720                 }
1721
1722                 [Test]
1723                 public void GroupByArgumentNullTest ()
1724                 {
1725                         string [] data = { "2", "1", "5", "3", "4" };
1726
1727
1728                         // GroupBy<string,string> (Func<string, string>)
1729                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test")); });
1730                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null); });
1731
1732                         // GroupBy<string,string> (Func<string, string>, IEqualityComparer<string>)
1733                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1734                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1735
1736                         // GroupBy<string,string,string> (Func<string, string>, Func<string, string>)
1737                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
1738                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
1739                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
1740
1741                         // GroupBy<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
1742                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1743                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1744                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1745
1746                         // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>)
1747                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1748                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1749                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
1750
1751                         // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>)
1752                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1753                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1754                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1755                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
1756
1757                         // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
1758                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1759                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1760                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1761
1762                         // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
1763                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1764                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1765                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1766                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1767                 }
1768
1769                 [Test]
1770                 public void GroupByTest ()
1771                 {
1772                         string [] data = { "2", "1", "5", "3", "4", "3" };
1773
1774                         Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
1775                         expected.Add ("2", new List<string> () { "2" });
1776                         expected.Add ("1", new List<string> () { "1" });
1777                         expected.Add ("5", new List<string> () { "5" });
1778                         expected.Add ("3", new List<string> () { "3", "3" });
1779                         expected.Add ("4", new List<string> () { "4" });
1780
1781                         Dictionary<string, IEnumerable<string>> expected2 = new Dictionary<string, IEnumerable<string>> ();
1782                         expected2.Add ("2", new List<string> () { "22" });
1783                         expected2.Add ("1", new List<string> () { "11" });
1784                         expected2.Add ("5", new List<string> () { "55" });
1785                         expected2.Add ("3", new List<string> () { "33", "33" });
1786                         expected2.Add ("4", new List<string> () { "44" });
1787
1788                         string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
1789
1790                         // GroupBy<int,int> (Func<int, int>)
1791                         AssertAreSame (expected, data.GroupBy (x => x));
1792
1793                         // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
1794                         AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
1795
1796                         // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
1797                         AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
1798
1799                         // GroupBy<int,int,int> (Func<int, int>, Func<int, int>, IEqualityComparer<int>)
1800                         AssertAreSame (expected2, data.GroupBy (x => x, x => x + x, EqualityComparer<string>.Default));
1801
1802                         // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>)
1803                         AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
1804
1805                         // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>)
1806                         AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
1807
1808                         // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
1809                         AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1810
1811                         // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
1812                         AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1813                 }
1814
1815
1816                 class Data {
1817
1818                         public int Number;
1819                         public string String;
1820
1821                         public Data (int number, string str)
1822                         {
1823                                 Number = number;
1824                                 String = str;
1825                         }
1826                 }
1827
1828                 [Test]
1829                 public void GroupByLastNullGroup ()
1830                 {
1831                         var values = new List<Data> ();
1832
1833                         values.Add (new Data (0, "a"));
1834                         values.Add (new Data (1, "a"));
1835                         values.Add (new Data (2, "b"));
1836                         values.Add (new Data (3, "b"));
1837                         values.Add (new Data (4, null));
1838
1839                         var groups = values.GroupBy (d => d.String);
1840
1841                         Assert.AreEqual (3, groups.Count ());
1842                 }
1843
1844                 [Test]
1845                 public void ConcatArgumentNullTest ()
1846                 {
1847                         string [] data = { "2", "1", "5", "3", "4" };
1848
1849                         // Concat<TSource> (IEnumerable<TSource>)
1850                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
1851                         AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
1852                 }
1853
1854                 [Test]
1855                 public void ConcatTest ()
1856                 {
1857                         int [] data1 = { 2, 1, 5, 3, 4 };
1858                         int [] data2 = { 1, 2, 3, 4, 5 };
1859                         int [] expected = { 2, 1, 5, 3, 4, 1, 2, 3, 4, 5 };
1860
1861
1862                         // Concat<TSource> (IEnumerable<TSource>)
1863                         AssertAreSame (expected, data1.Concat (data2));
1864                 }
1865
1866                 [Test]
1867                 public void DistinctArgumentNullTest ()
1868                 {
1869                         //string [] data = { "2", "1", "5", "3", "4" };
1870
1871
1872                         // Distinct<TSource> ()
1873                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
1874
1875                         // Distinct<TSource> (IEqualityComparer<TSource>)
1876                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
1877                 }
1878
1879                 [Test]
1880                 public void DistinctTest ()
1881                 {
1882                         int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
1883                         int [] expected = { 2, 1, 5, 3, 4, 8 };
1884
1885
1886                         // Distinct<TSource> ()
1887                         AssertAreSame (expected, data.Distinct ());
1888
1889                         // Distinct<iTSourcent> (IEqualityComparer<TSource>)
1890                         AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
1891                 }
1892
1893                 [Test]
1894                 public void UnionArgumentNullTest ()
1895                 {
1896                         string [] data = { "2", "1", "5", "3", "4" };
1897
1898
1899                         // Union<TSource> (IEnumerable<TSource>)
1900                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
1901                         AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
1902
1903                         // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1904                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data, EqualityComparer<string>.Default); });
1905                         AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1906                 }
1907
1908                 [Test]
1909                 public void UnionTest ()
1910                 {
1911                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1912                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1913                         int [] expected = { 2, 1, 5, 7, 3, 4, 8 };
1914
1915                         // Union<TSource> (IEnumerable<TSource>)
1916                         AssertAreSame (expected, data1.Union (data2));
1917
1918                         // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1919                         AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
1920                 }
1921
1922                 [Test]
1923                 public void IntersectArgumentNullTest ()
1924                 {
1925                         string [] data = { "2", "1", "5", "3", "4" };
1926
1927
1928                         // Intersect<TSource> (IEnumerable<TSource>)
1929                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
1930                         AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
1931
1932                         // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1933                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data, EqualityComparer<string>.Default); });
1934                         AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1935                 }
1936
1937                 [Test]
1938                 public void IntersectTest ()
1939                 {
1940                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1941                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1942                         int [] expected = { 2, 1, 5, 3, 4 };
1943
1944
1945                         // Intersect<TSource> (IEnumerable<TSource>)
1946                         AssertAreSame (expected, data1.Intersect (data2));
1947
1948                         // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1949                         AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
1950                 }
1951
1952                 [Test]
1953                 public void ExceptArgumentNullTest ()
1954                 {
1955                         string [] data = { "2", "1", "5", "3", "4" };
1956
1957
1958                         // Except<TSource> (IEnumerable<TSource>)
1959                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
1960                         AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
1961
1962                         // Except<TSource> (IEnumerable<string>, IEqualityComparer<TSource>)
1963                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data, EqualityComparer<string>.Default); });
1964                         AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1965                 }
1966
1967                 [Test]
1968                 public void ExceptTest ()
1969                 {
1970                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1971                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1972                         int [] expected = { 7 };
1973
1974
1975                         // Except<TSource> (IEnumerable<TSource>)
1976                         AssertAreSame (expected, data1.Except (data2));
1977
1978                         // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1979                         AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
1980                 }
1981
1982                 [Test]
1983                 public void ReverseArgumentNullTest ()
1984                 {
1985                         //string [] data = { "2", "1", "5", "3", "4" };
1986
1987
1988                         // Reverse<TSource> ()
1989                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
1990                 }
1991
1992                 [Test]
1993                 public void ReverseTest ()
1994                 {
1995                         int [] data = { 2, 1, 5, 7, 3, 4 };
1996                         int [] expected = { 4, 3, 7, 5, 1, 2 };
1997
1998
1999
2000                         // Reverse<TSource> ()
2001                         AssertAreSame (expected, data.Reverse ());
2002                 }
2003
2004                 [Test]
2005                 public void SequenceEqualArgumentNullTest ()
2006                 {
2007                         string [] data = { "2", "1", "5", "3", "4" };
2008
2009
2010                         // SequenceEqual<TSource> (IEnumerable<TSource>)
2011                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
2012                         AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
2013
2014                         // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
2015                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data, EqualityComparer<string>.Default); });
2016                         AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
2017                 }
2018
2019                 [Test]
2020                 public void SequenceEqualTest ()
2021                 {
2022                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
2023                         int [] data2 = { 2, 1, 5, 7, 3, 4 };
2024                         int [] data3 = { 2, 1, 5, 7, 3, 4, 5 };
2025                         int [] data4 = { 2, 1, 5, 7, 3 };
2026                         int [] data5 = { 2, 1, 5, 8, 3, 4 };
2027
2028
2029                         // SequenceEqual<TSource> (IEnumerable<TSource>)
2030                         Assert.IsTrue (data1.SequenceEqual (data2));
2031                         Assert.IsFalse (data1.SequenceEqual (data3));
2032                         Assert.IsFalse (data1.SequenceEqual (data4));
2033                         Assert.IsFalse (data1.SequenceEqual (data5));
2034
2035                         // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
2036                         Assert.IsTrue (data1.SequenceEqual (data2, EqualityComparer<int>.Default));
2037                         Assert.IsFalse (data1.SequenceEqual (data3, EqualityComparer<int>.Default));
2038                         Assert.IsFalse (data1.SequenceEqual (data4, EqualityComparer<int>.Default));
2039                         Assert.IsFalse (data1.SequenceEqual (data5, EqualityComparer<int>.Default));
2040                 }
2041
2042                 [Test]
2043                 public void AsEnumerableArgumentNullTest ()
2044                 {
2045                         //string [] data = { "2", "1", "5", "3", "4" };
2046
2047                 }
2048
2049                 [Test]
2050                 public void AsEnumerableTest ()
2051                 {
2052                         int [] data = { 2, 1, 5, 7, 3, 4 };
2053
2054
2055                         // AsEnumerable<TSource> ()
2056                         Assert.AreSame (data, data.AsEnumerable ());
2057                 }
2058
2059                 [Test]
2060                 public void ToArrayArgumentNullTest ()
2061                 {
2062                         //string [] data = { "2", "1", "5", "3", "4" };
2063
2064
2065                         // ToArray<TSource> ()
2066                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
2067                 }
2068
2069                 [Test]
2070                 public void ToArrayTest ()
2071                 {
2072                         int [] data = { 2, 3, 4, 5 };
2073                         int [] expected = { 2, 3, 4, 5 };
2074
2075
2076                         // ToArray<TSource> ()
2077                         AssertAreSame (expected, data.ToArray ());
2078                 }
2079
2080                 [Test]
2081                 public void ToListArgumentNullTest ()
2082                 {
2083                         //string [] data = { "2", "1", "5", "3", "4" };
2084
2085
2086                         // ToList<string> ()
2087                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
2088                 }
2089
2090                 [Test]
2091                 public void ToListTest ()
2092                 {
2093                         int [] data = { 2, 4, 5, 1 };
2094                         int [] expected = { 2, 4, 5, 1 };
2095
2096
2097                         // ToList<int> ()
2098                         AssertAreSame (expected, data.ToList ());
2099                 }
2100
2101                 [Test]
2102                 public void ToDictionaryArgumentNullTest ()
2103                 {
2104                         string [] data = { "2", "1", "5", "3", "4" };
2105
2106
2107                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
2108                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test"); });
2109                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null); });
2110
2111                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
2112                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", EqualityComparer<string>.Default); });
2113                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, EqualityComparer<string>.Default); });
2114
2115                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
2116                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test"); });
2117                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test"); });
2118                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null); });
2119
2120                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
2121                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test", EqualityComparer<string>.Default); });
2122                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test", EqualityComparer<string>.Default); });
2123                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null, EqualityComparer<string>.Default); });
2124                 }
2125
2126                 [Test]
2127                 public void ToDictionaryTest ()
2128                 {
2129                         string [] data = { "2", "1", "5", "3", "4" };
2130                         Dictionary<string, string> expected = new Dictionary<string, string> ();
2131                         expected.Add ("k2", "2");
2132                         expected.Add ("k1", "1");
2133                         expected.Add ("k5", "5");
2134                         expected.Add ("k3", "3");
2135                         expected.Add ("k4", "4");
2136
2137
2138                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
2139                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x));
2140                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key"); });
2141
2142                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
2143                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, EqualityComparer<string>.Default));
2144                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", EqualityComparer<string>.Default); });
2145
2146                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
2147                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x));
2148                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x); });
2149
2150                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
2151                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x, EqualityComparer<string>.Default));
2152                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x, EqualityComparer<string>.Default); });
2153                 }
2154
2155                 [Test]
2156                 public void ToLookupArgumentNullTest ()
2157                 {
2158                         string [] data = { "2", "1", "5", "3", "4" };
2159
2160
2161                         // ToLookup<string,string> (Func<string, string>)
2162                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test")); });
2163                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null); });
2164
2165                         // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
2166                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2167                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2168
2169                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
2170                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
2171                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
2172                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
2173
2174                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
2175                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2176                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2177                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2178                 }
2179
2180                 [Test]
2181                 public void ToLookupTest ()
2182                 {
2183                         string [] data = { "23", "12", "55", "42", "41" };
2184                         Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
2185                         expected.Add ("2", new List<string> () { "23" });
2186                         expected.Add ("1", new List<string> () { "12" });
2187                         expected.Add ("5", new List<string> () { "55" });
2188                         expected.Add ("4", new List<string> () { "42", "41" });
2189
2190                         Assert.AreEqual (expected.Count, ((IEnumerable<string>)data).ToLookup ((x => x [0].ToString ())).Count);
2191                         
2192                         // ToLookup<string,string> (Func<string, string>)
2193                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
2194
2195                         // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
2196                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
2197
2198                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
2199                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
2200
2201                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
2202                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x, EqualityComparer<string>.Default));
2203                 }
2204                 
2205                 [Test]
2206                 public void ToLookupNullKeyTest ()
2207                 {
2208                         string[] strs = new string[] { "one", null, "two", null, "three" };
2209                         
2210                         int i = 0;
2211                         var l = strs.ToLookup (s => (s == null) ? null : "numbers", s => (s == null) ? (++i).ToString() : s);
2212                         
2213                         Assert.AreEqual (2, l.Count);
2214                         Assert.AreEqual (2, l [null].Count());
2215                         Assert.IsTrue (l [null].Contains ("1"));
2216                         Assert.IsTrue (l [null].Contains ("2"));
2217                         
2218                         Assert.AreEqual (3, l ["numbers"].Count());
2219                         Assert.IsTrue (l ["numbers"].Contains ("one"));
2220                         Assert.IsTrue (l ["numbers"].Contains ("two"));
2221                         Assert.IsTrue (l ["numbers"].Contains ("three"));
2222                 }
2223
2224                 [Test]
2225                 public void DefaultIfEmptyArgumentNullTest ()
2226                 {
2227                         //string [] data = { "2", "1", "5", "3", "4" };
2228
2229
2230                         // DefaultIfEmpty<string> ()
2231                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
2232
2233                         // DefaultIfEmpty<string> (string)
2234                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
2235                 }
2236
2237                 [Test]
2238                 public void DefaultIfEmptyTest ()
2239                 {
2240                         string [] data = { "2", "1", "5", "3", "4" };
2241                         string [] empty = { };
2242                         string [] default1 = { null };
2243                         string [] default2 = { "default" };
2244
2245
2246                         // DefaultIfEmpty<string> ()
2247                         AssertAreSame (data, data.DefaultIfEmpty ());
2248                         AssertAreSame (default1, empty.DefaultIfEmpty ());
2249
2250                         // DefaultIfEmpty<string> (string)
2251                         AssertAreSame (data, data.DefaultIfEmpty ("default"));
2252                         AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
2253                 }
2254
2255                 [Test]
2256                 public void OfTypeArgumentNullTest ()
2257                 {
2258                         //string [] data = { "2", "1", "5", "3", "4" };
2259
2260
2261                         // OfType<string> ()
2262                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
2263                 }
2264
2265                 [Test]
2266                 public void OfTypeTest ()
2267                 {
2268                         object [] data = { "2", 2, "1", "5", "3", "4" };
2269                         string [] expected = { "2", "1", "5", "3", "4" };
2270
2271
2272                         // OfType<string> ()
2273                         AssertAreSame (expected, data.OfType<string> ());
2274                 }
2275
2276                 [Test]
2277                 public void CastArgumentNullTest ()
2278                 {
2279                         //string [] data = { "2", "1", "5", "3", "4" };
2280
2281
2282                         // Cast<string> ()
2283                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
2284                 }
2285
2286                 [Test]
2287                 public void CastTest ()
2288                 {
2289                         object [] data = { 1, 2, 3 };
2290                         int [] expected = { 1, 2, 3 };
2291
2292
2293                         // Cast<string> ()
2294                         AssertAreSame (expected, data.Cast<int> ());
2295                         AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
2296                         data.Cast<IEnumerable> ();
2297                 }
2298
2299                 [Test]
2300                 public void RangeArgumentNullTest ()
2301                 {
2302                         //string [] data = { "2", "1", "5", "3", "4" };
2303
2304                 }
2305
2306                 [Test]
2307                 public void RangeTest ()
2308                 {
2309                         int [] expected = { 2, 3, 4, 5 };
2310
2311                         // Range<> (int)
2312                         AssertAreSame (expected, Enumerable.Range (2, 4));
2313                         AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (2, -3); });
2314                         AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (int.MaxValue - 5, 7); });
2315                         Enumerable.Range (int.MaxValue - 5, 6);
2316                 }
2317
2318                 [Test]
2319                 public void ExceptMultipleItems ()
2320                 {
2321                         var data = new [] { 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10 };
2322                         var expected = new [] { 2, 4, 6, 8, 10 };
2323
2324                         AssertAreSame (expected, data.Except (new [] { 1, 3, 5, 7, 9 }));
2325                 }
2326         }
2327 }