Merge pull request #799 from kebby/master
[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                 static void IsFalse(bool b, int[] data) {
612                         if (b) {
613                                 Console.WriteLine (data.Contains (0));
614                                 object o = null;
615                                 o.ToString ();
616                                 Assert.IsFalse (true);
617                         }
618                         //Console.WriteLine ("HIT!");
619                 }
620
621                 [Test]
622                 public void ContainsTest ()
623                 {
624                         int [] data = { 5, 2, 3, 1, 6 };
625                         ICollection<int> icoll = data;
626
627                         // Contains<TSource> (TSource)
628                         Assert.IsTrue (data.Contains (2));
629                         for (int i = 0; i < 50; ++i)
630                                 Console.WriteLine (icoll.Contains (0));//Console.WriteLine (data.Contains (0));
631                         IsFalse (data.Contains (0), data);
632
633                         // Contains<TSource> (TSource, IEqualityComparer<TSource>)
634                         Assert.IsTrue (data.Contains (2, EqualityComparer<int>.Default));
635                         Assert.IsFalse (data.Contains (0, EqualityComparer<int>.Default));
636                 }
637
638                 [Test]
639                 public void AggregateArgumentNullTest ()
640                 {
641                         string [] data = { "2", "1", "5", "3", "4" };
642
643
644                         // Aggregate<TSource> (Func<TSource, TSource, TSource>)
645                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ((x, y) => "test"); });
646                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ((Func<string, string, string>) null); });
647
648                         // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
649                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test"); });
650                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null); });
651
652                         // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
653                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Aggregate ("initial", (x, y) => "test", x => "test"); });
654                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (Func<string, string, string>) null, x => "test"); });
655                         AssertException<ArgumentNullException> (delegate () { data.Aggregate ("initial", (x, y) => "test", (Func<string, string>) null); });
656                 }
657
658                 [Test]
659                 public void AggregateTest ()
660                 {
661                         string [] data = { "2", "1", "5", "3", "4" };
662                         string [] empty = { };
663
664                         // Aggregate<TSource> (Func<TSource, TSource, TSource>)
665                         Assert.AreEqual ("21534", data.Aggregate ((x, y) => x + y));
666                         AssertException<InvalidOperationException> (delegate () { empty.Aggregate ((x, y) => x + y); }); //only this overload throws
667
668                         // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
669                         Assert.AreEqual ("initial21534", (data.Aggregate ("initial", (x, y) => x + y)));
670
671                         // Aggregate<TSource,TAccumulate,TResult> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
672                         Assert.AreEqual ("INITIAL21534", data.Aggregate ("initial", (x, y) => x + y, (x => x.ToUpper ())));
673                 }
674
675                 [Test]
676                 public void SumArgumentNullTest ()
677                 {
678                         string [] data = { "2", "1", "5", "3", "4" };
679
680
681                         // Sum<TSource> (Func<TSource, int>)
682                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, int>) (x => 0)); });
683                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, int>) null); });
684
685                         // Sum<TSource> (Func<TSource, Nullable<int>>)
686                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
687                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<int>>) null); });
688
689                         // Sum<TSource> (Func<TSource, Int64>)
690                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Int64>) (x => 0L)); });
691                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Int64>) null); });
692
693                         // Sum<TSource> (Func<TSource, Nullable<Int64>>)
694                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
695                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Int64>>) null); });
696
697                         // Sum<TSource> (Func<TSource, Single>)
698                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Single>) (x => 0f)); });
699                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Single>) null); });
700
701                         // Sum<TSource> (Func<TSource, Nullable<Single>>)
702                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
703                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Single>>) null); });
704
705                         // Sum<TSource> (Func<TSource, Double>)
706                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Double>) (x => 0d)); });
707                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Double>) null); });
708
709                         // Sum<TSource> (Func<TSource, Nullable<Double>>)
710                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
711                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Double>>) null); });
712
713                         // Sum<TSource> (Func<TSource, Decimal>)
714                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Decimal>) (x => 0m)); });
715                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Decimal>) null); });
716
717                         // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
718                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
719                         AssertException<ArgumentNullException> (delegate () { data.Sum<string> ((Func<string, Nullable<Decimal>>) null); });
720
721                         // Sum (IEnumerable<int>)
722                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Sum (); });
723
724                         // Sum (IEnumerable<int?>)
725                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Sum (); });
726
727                         // Sum (IEnumerable<long>)
728                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Sum (); });
729
730                         // Sum (IEnumerable<long?>)
731                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Sum (); });
732
733                         // Sum (IEnumerable<float>)
734                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Sum (); });
735
736                         // Sum (IEnumerable<float?>)
737                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Sum (); });
738
739                         // Sum (IEnumerable<double>)
740                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Sum (); });
741
742                         // Sum (IEnumerable<double?>)
743                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Sum (); });
744
745                         // Sum (IEnumerable<decimal>)
746                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Sum (); });
747
748                         // Sum (IEnumerable<decimal?>)
749                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Sum (); });
750                 }
751
752                 [Test]
753                 public void SumTest ()
754                 {
755                         string [] data = { "2", "3", "5", "5" };
756
757                         //TODO: OverflowException
758
759                         // Sum<TSource> (Func<TSource, int>)
760                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, int>) (x => int.Parse (x))));
761                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, int>) (x => int.Parse (x))));
762
763                         // Sum<TSource> (Func<TSource, Nullable<int>>)
764                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
765                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
766
767                         // Sum<TSource> (Func<TSource, Int64>)
768                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
769                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Int64>) (x => int.Parse (x))));
770
771                         // Sum<TSource> (Func<TSource, Nullable<Int64>>)
772                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
773                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
774
775                         // Sum<TSource> (Func<TSource, Single>)
776                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
777                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Single>) (x => int.Parse (x))));
778
779                         // Sum<TSource> (Func<TSource, Nullable<Single>>)
780                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
781                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
782
783                         // Sum<TSource> (Func<TSource, Double>)
784                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
785                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Double>) (x => int.Parse (x))));
786
787                         // Sum<TSource> (Func<TSource, Nullable<Double>>)
788                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
789                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
790
791                         // Sum<TSource> (Func<TSource, Decimal>)
792                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
793                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Decimal>) (x => int.Parse (x))));
794
795                         // Sum<TSource> (Func<TSource, Nullable<Decimal>>)
796                         Assert.AreEqual (15, ((IEnumerable<string>) data).Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
797                         Assert.AreEqual (0, Enumerable.Empty<string> ().Sum<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
798
799                         // Sum<> ()
800                         Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
801                         Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
802
803                         // Sum<> ()
804                         Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
805                         Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
806
807                         // Sum<> ()
808                         Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
809                         Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
810
811                         // Sum<> ()
812                         Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
813                         Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
814
815                         // Sum<> ()
816                         Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
817                         Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
818
819                         // Sum<> ()
820                         Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
821                         Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
822
823                         // Sum<> ()
824                         Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
825                         Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
826
827                         // Sum<> ()
828                         Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
829                         Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
830
831                         // Sum<> ()
832                         Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
833                         Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
834
835                         // Sum<> ()
836                         Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
837                         Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
838                 }
839
840                 [Test]
841                 public void MinArgumentNullTest ()
842                 {
843                         string [] data = { "2", "1", "5", "3", "4" };
844
845
846                         // Min<TSource> ()
847                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
848
849                         // Min<TSource> (Func<TSource, int>)
850                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, int>) (x => 0)); });
851                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, int>) null); });
852
853                         // Min<TSource> (Func<TSource, Nullable<int>>)
854                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
855                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<int>>) null); });
856
857                         // Min<TSource> (Func<TSource, Int64>)
858                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Int64>) (x => 0L)); });
859                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Int64>) null); });
860
861                         // Min<TSource> (Func<TSource, Nullable<Int64>>)
862                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
863                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Int64>>) null); });
864
865                         // Min<TSource> (Func<TSource, Single>)
866                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Single>) (x => 0f)); });
867                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Single>) null); });
868
869                         // Min<TSource> (Func<TSource, Nullable<Single>>)
870                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
871                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Single>>) null); });
872
873                         // Min<TSource> (Func<TSource, Double>)
874                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Double>) (x => 0d)); });
875                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Double>) null); });
876
877                         // Min<TSource> (Func<TSource, Nullable<Double>>)
878                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
879                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Double>>) null); });
880
881                         // Min<TSource> (Func<TSource, Decimal>)
882                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Decimal>) (x => 0m)); });
883                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Decimal>) null); });
884
885                         // Min<TSource> (Func<TSource, Nullable<Decimal>>)
886                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
887                         AssertException<ArgumentNullException> (delegate () { data.Min<string> ((Func<string, Nullable<Decimal>>) null); });
888
889                         // Min<TSource,TSource> (Func<TSource, string>)
890                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string, string> ((Func<string, string>) (x => "test")); });
891                         AssertException<ArgumentNullException> (delegate () { data.Min<string, string> ((Func<string, string>) null); });
892
893                         // Min<> ()
894                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
895
896                         // Min<> ()
897                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
898
899                         // Min<> ()
900                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
901
902                         // Min<> ()
903                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
904
905                         // Min<> ()
906                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
907
908                         // Min<> ()
909                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
910
911                         // Min<> ()
912                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
913
914                         // Min<> ()
915                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
916
917                         // Min<> ()
918                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
919
920                         // Min<> ()
921                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
922                 }
923
924                 [Test]
925                 public void MinTest ()
926                 {
927                         string [] data = { "2", "1", "5", "3", "4" };
928
929
930                         // Min<TSource> ()
931                         Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
932
933
934                         // Min<TSource> (Func<TSource, int>)
935                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
936
937                         // Min<TSource> (Func<TSource, Nullable<int>>)
938                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
939
940                         // Min<TSource> (Func<TSource, Int64>)
941                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
942
943                         // Min<TSource> (Func<TSource, Nullable<Int64>>)
944                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
945
946                         // Min<TSource> (Func<TSource, Single>)
947                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
948
949                         // Min<TSource> (Func<TSource, Nullable<Single>>)
950                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
951
952                         // Min<TSource> (Func<TSource, Double>)
953                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
954
955                         // Min<TSource> (Func<TSource, Nullable<Double>>)
956                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
957
958                         // Min<TSource> (Func<TSource, Decimal>)
959                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
960
961                         // Min<TSource> (Func<TSource, Nullable<Decimal>>)
962                         Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
963
964                         // Min<TSource,TSource> (Func<TSource, TSource>)
965                         Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
966
967                         // Min<> ()
968                         Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
969
970                         // Min<> ()
971                         Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
972
973                         // Min<> ()
974                         Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
975
976                         // Min<> ()
977                         Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
978
979                         // Min<> ()
980                         Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
981
982                         // Min<> ()
983                         Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
984
985                         // Min<> ()
986                         Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
987
988                         // Min<> ()
989                         Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
990
991                         // Min<> ()
992                         Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
993
994                         // Min<> ()
995                         Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
996                 }
997
998                 [Test]
999                 public void MaxArgumentNullTest ()
1000                 {
1001                         string [] data = { "2", "1", "5", "3", "4" };
1002
1003
1004                         // Max<TSource> ()
1005                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
1006
1007                         // Max<TSource> (Func<TSource, int>)
1008                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, int>) (x => 0)); });
1009                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, int>) null); });
1010
1011                         // Max<TSource> (Func<TSource, Nullable<int>>)
1012                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
1013                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<int>>) null); });
1014
1015                         // Max<TSource> (Func<TSource, Int64>)
1016                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Int64>) (x => 0L)); });
1017                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Int64>) null); });
1018
1019                         // Max<TSource> (Func<TSource, Nullable<Int64>>)
1020                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
1021                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Int64>>) null); });
1022
1023                         // Max<TSource> (Func<TSource, Single>)
1024                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Single>) (x => 0f)); });
1025                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Single>) null); });
1026
1027                         // Max<TSource> (Func<TSource, Nullable<Single>>)
1028                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
1029                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Single>>) null); });
1030
1031                         // Max<TSource> (Func<TSource, Double>)
1032                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Double>) (x => 0d)); });
1033                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Double>) null); });
1034
1035                         // Max<TSource> (Func<TSource, Nullable<Double>>)
1036                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
1037                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Double>>) null); });
1038
1039                         // Max<TSource> (Func<TSource, Decimal>)
1040                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Decimal>) (x => 0m)); });
1041                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Decimal>) null); });
1042
1043                         // Max<TSource> (Func<TSource, Nullable<Decimal>>)
1044                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
1045                         AssertException<ArgumentNullException> (delegate () { data.Max<string> ((Func<string, Nullable<Decimal>>) null); });
1046
1047                         // Max<TSource,TSource> (Func<TSource, TSource>)
1048                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string, string> ((Func<string, string>) (x => "test")); });
1049                         AssertException<ArgumentNullException> (delegate () { data.Max<string, string> ((Func<string, string>) null); });
1050
1051                         // Max<> ()
1052                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
1053
1054                         // Max<> ()
1055                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
1056
1057                         // Max<> ()
1058                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
1059
1060                         // Max<> ()
1061                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
1062
1063                         // Max<> ()
1064                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
1065
1066                         // Max<> ()
1067                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
1068
1069                         // Max<> ()
1070                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
1071
1072                         // Max<> ()
1073                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
1074
1075                         // Max<> ()
1076                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
1077
1078                         // Max<> ()
1079                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
1080                 }
1081
1082                 [Test]
1083                 public void MaxTest ()
1084                 {
1085                         string [] data = { "2", "1", "5", "3", "4" };
1086
1087
1088                         // Max<string> ()
1089                         Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
1090
1091                         // Max<TSource> (Func<TSource, int>)
1092                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
1093
1094                         // Max<TSource> (Func<TSource, Nullable<int>>)
1095                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
1096
1097                         // Max<TSource> (Func<TSource, Int64>)
1098                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
1099
1100                         // Max<TSource> (Func<TSource, Nullable<Int64>>)
1101                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Int64>>) (x => (int?) int.Parse (x))));
1102
1103                         // Max<TSource> (Func<TSource, Single>)
1104                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
1105
1106                         // Max<TSource> (Func<TSource, Nullable<Single>>)
1107                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Single>>) (x => (int?) int.Parse (x))));
1108
1109                         // Max<TSource> (Func<TSource, Double>)
1110                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
1111
1112                         // Max<TSource> (Func<TSource, Nullable<Double>>)
1113                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Double>>) (x => (int?) int.Parse (x))));
1114
1115                         // Max<TSource> (Func<TSource, Decimal>)
1116                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
1117
1118                         // Max<TSource> (Func<TSource, Nullable<Decimal>>)
1119                         Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Nullable<Decimal>>) (x => (int?) int.Parse (x))));
1120
1121                         // Max<TSource,TSource> (Func<TSource, TSource>)
1122                         Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
1123
1124                         // Max<> ()
1125                         Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
1126
1127                         // Max<> ()
1128                         Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
1129
1130                         // Max<> ()
1131                         Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
1132
1133                         // Max<> ()
1134                         Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
1135
1136                         // Max<> ()
1137                         Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
1138
1139                         // Max<> ()
1140                         Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
1141
1142                         // Max<> ()
1143                         Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
1144
1145                         // Max<> ()
1146                         Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
1147
1148                         // Max<> ()
1149                         Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
1150
1151                         // Max<> ()
1152                         Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
1153                 }
1154
1155                 [Test]
1156                 public void AverageArgumentNullTest ()
1157                 {
1158                         string [] data = { "2", "1", "5", "3", "4" };
1159
1160
1161                         // Average<TSource> (Func<TSource, int>)
1162                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, int>) (x => 0)); });
1163                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, int>) null); });
1164
1165                         // Average<TSource> (Func<TSource, Nullable<int>>)
1166                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<int>>) (x => (int?) 0)); });
1167                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<int>>) null); });
1168
1169                         // Average<TSource> (Func<TSource, Int64>)
1170                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Int64>) (x => 0L)); });
1171                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Int64>) null); });
1172
1173                         // Average<TSource> (Func<TSource, Nullable<Int64>>)
1174                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Int64>>) (x => (int?) 0L)); });
1175                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Int64>>) null); });
1176
1177                         // Average<TSource> (Func<TSource, Single>)
1178                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Single>) (x => 0f)); });
1179                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Single>) null); });
1180
1181                         // Average<TSource> (Func<TSource, Nullable<Single>>)
1182                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Single>>) (x => (int?) 0f)); });
1183                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Single>>) null); });
1184
1185                         // Average<TSource> (Func<TSource, Double>)
1186                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Double>) (x => 0d)); });
1187                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Double>) null); });
1188
1189                         // Average<TSource> (Func<TSource, Nullable<Double>>)
1190                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Double>>) (x => (int?) 0d)); });
1191                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Double>>) null); });
1192
1193                         // Average<TSource> (Func<TSource, Decimal>)
1194                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Decimal>) (x => 0m)); });
1195                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Decimal>) null); });
1196
1197                         // Average<TSource> (Func<TSource, Nullable<Decimal>>)
1198                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Average<string> ((Func<string, Nullable<Decimal>>) (x => (int?) 0m)); });
1199                         AssertException<ArgumentNullException> (delegate () { data.Average<string> ((Func<string, Nullable<Decimal>>) null); });
1200
1201                         // Average<> ()
1202                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
1203
1204                         // Average<> ()
1205                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
1206
1207                         // Average<> ()
1208                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
1209
1210                         // Average<> ()
1211                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
1212
1213                         // Average<> ()
1214                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
1215
1216                         // Average<> ()
1217                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
1218
1219                         // Average<> ()
1220                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
1221
1222                         // Average<> ()
1223                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
1224
1225                         // Average<> ()
1226                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
1227
1228                         // Average<> ()
1229                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
1230                 }
1231
1232                 [Test]
1233                 public void AverageTest ()
1234                 {
1235                         string [] data = { "2", "1", "5", "3", "4" };
1236                         string [] empty = { };
1237
1238                         // Average<string> (Func<string, int>)
1239                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, int>) (x => int.Parse (x))));
1240                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, int>) (x => int.Parse (x))); });
1241
1242                         // Average<TSource> (Func<TSource, Nullable<int>>)
1243                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, Nullable<int>>) (x => (int?) int.Parse (x))));
1244
1245                         // Average<TSource> (Func<TSource, Int64>)
1246                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long>) (x => int.Parse (x))));
1247                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, long>) (x => int.Parse (x))); });
1248
1249                         // Average<TSource> (Func<TSource, Nullable<Int64>>)
1250                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
1251
1252                         // Average<TSource> (Func<TSource, Single>)
1253                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float>) (x => int.Parse (x))));
1254                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, float>) (x => int.Parse (x))); });
1255
1256                         // Average<TSource> (Func<TSource, Nullable<Single>>)
1257                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
1258
1259                         // Average<TSource> (Func<TSource, Double>)
1260                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double>) (x => int.Parse (x))));
1261                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, double>) (x => int.Parse (x))); });
1262
1263                         // Average<TSource> (Func<TSource, Nullable<Double>>)
1264                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
1265
1266                         // Average<TSource> (Func<TSource, Decimal>)
1267                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal>) (x => int.Parse (x))));
1268                         AssertException<InvalidOperationException> (delegate () { empty.Average ((Func<string, decimal>) (x => int.Parse (x))); });
1269
1270                         // Average<TSource> (Func<TSource, Nullable<Decimal>>)
1271                         Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
1272
1273
1274                         // Average<> ()
1275                         Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
1276                         AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
1277
1278                         // Average<> ()
1279                         Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
1280
1281                         // Average<> ()
1282                         Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
1283                         AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
1284
1285                         // Average<> ()
1286                         Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
1287
1288                         // Average<> ()
1289                         Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
1290                         AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
1291
1292                         // Average<> ()
1293                         Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
1294
1295                         // Average<> ()
1296                         Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
1297                         AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
1298
1299                         // Average<> ()
1300                         Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
1301
1302                         // Average<> ()
1303                         Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
1304                         AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
1305
1306                         // Average<> ()
1307                         Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
1308                 }
1309
1310                 [Test]
1311                 public void WhereArgumentNullTest ()
1312                 {
1313                         string [] data = { "2", "1", "5", "3", "4" };
1314
1315                         // Where<TSource> (Func<TSource, bool>)
1316                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where (x => true); });
1317                         AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, bool>) null); });
1318
1319                         // Where<TSource> (Func<TSource, int, bool>)
1320                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Where ((x, y) => true); });
1321                         AssertException<ArgumentNullException> (delegate () { data.Where ((Func<string, int, bool>) null); });
1322                 }
1323
1324                 [Test]
1325                 public void WhereTest ()
1326                 {
1327                         int [] data = { 2, 1, 5, 3, 4 };
1328                         int [] expected1 = { 2, 1 };
1329                         int [] expected2 = { 2 };
1330
1331                         // Where<TSource> (Func<TSource, bool>)
1332                         AssertAreSame (expected1, data.Where (x => x < 3));
1333
1334                         // Where<TSource> (Func<TSource, int, bool>)
1335                         AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
1336                 }
1337
1338                 [Test]
1339                 public void SelectArgumentNullTest ()
1340                 {
1341                         string [] data = { "2", "1", "5", "3", "4" };
1342
1343
1344                         // Select<TSource,TResult> (Func<TSource, TResult>)
1345                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select (x => "test"); });
1346                         AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, string>) null); });
1347
1348                         // Select<TSource,TResult> (Func<TSource, int, TResult>)
1349                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Select ((x, y) => "test"); });
1350                         AssertException<ArgumentNullException> (delegate () { data.Select ((Func<string, int, string>) null); });
1351                 }
1352
1353                 [Test]
1354                 public void SelectTest ()
1355                 {
1356                         string [] data = { "2", "1", "5", "3", "4" };
1357                         string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
1358                         string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
1359
1360
1361                         // Select<TSource,TResult> (Func<TSource, TResult>)
1362                         AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
1363
1364                         // Select<TSource,TResult> (Func<TSource, int, TResult>)
1365                         AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
1366                 }
1367
1368                 [Test]
1369                 public void SelectManyArgumentNullTest ()
1370                 {
1371                         string [] data = { "2", "1", "5", "3", "4" };
1372
1373
1374                         // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
1375                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data); });
1376                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null); });
1377
1378                         // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
1379                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data); });
1380                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null); });
1381
1382                         // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1383                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany ((x, y) => data, (x, y) => "test"); });
1384                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, int, IEnumerable<string>>) null, (x, y) => "test"); });
1385                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((x, y) => data, (Func<string, string, string>) null); });
1386
1387                         // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1388                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SelectMany (x => data, (x, y) => "test"); });
1389                         AssertException<ArgumentNullException> (delegate () { data.SelectMany ((Func<string, IEnumerable<string>>) null, (x, y) => "test"); });
1390                         AssertException<ArgumentNullException> (delegate () { data.SelectMany (x => data, (Func<string, string, string>) null); });
1391                 }
1392
1393                 [Test]
1394                 public void SelectManyTest ()
1395                 {
1396                         string [] data = { "0", "1" };
1397                         string [] expected = { "0", "00", "1", "11" };
1398
1399                         // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
1400                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
1401
1402                         // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
1403                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
1404
1405                         // SelectMany<TSource,TCollection,TResult> (Func<string, int, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1406                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }, (x, y) => y));
1407
1408                         // SelectMany<TSource,TCollection,TResult> (Func<TSource, IEnumerable<TCollection>>, Func<TSource, TCollection, TResult>)
1409                         AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }, (x, y) => y));
1410                 }
1411
1412                 [Test]
1413                 public void TakeArgumentNullTest ()
1414                 {
1415                         //string [] data = { "2", "1", "5", "3", "4" };
1416
1417
1418                         // Take<TSource> (int)
1419                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
1420                 }
1421
1422                 [Test]
1423                 public void TakeTest ()
1424                 {
1425                         int [] data = { 2, 1, 5, 3, 1 };
1426                         int [] expected = { 2, 1 };
1427                         int [] empty = { };
1428
1429                         // Take<TSource> (int)
1430                         AssertAreSame (expected, data.Take (2));
1431                         AssertAreSame (empty, data.Take (-2));
1432                 }
1433
1434                 [Test]
1435                 public void TakeWhileArgumentNullTest ()
1436                 {
1437                         string [] data = { "2", "1", "5", "3", "4" };
1438
1439
1440                         // TakeWhile<TSource> (Func<TSource, bool>)
1441                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile (x => true); });
1442                         AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, bool>) null); });
1443
1444                         // TakeWhile<TSource> (Func<TSource, int, bool>)
1445                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).TakeWhile ((x, y) => true); });
1446                         AssertException<ArgumentNullException> (delegate () { data.TakeWhile ((Func<string, int, bool>) null); });
1447                 }
1448
1449                 [Test]
1450                 public void TakeWhileTest ()
1451                 {
1452                         int [] data = { 2, 1, 5, 3, 1 };
1453                         int [] expected = { 2, 1 };
1454
1455
1456                         // TakeWhile<TSource> (Func<TSource, bool>)
1457                         AssertAreSame (expected, data.TakeWhile (x => x != 5));
1458
1459                         // TakeWhile<TSource> (Func<TSource, int, bool>)
1460                         AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
1461                 }
1462
1463                 [Test]
1464                 public void SkipArgumentNullTest ()
1465                 {
1466                         //string [] data = { "2", "1", "5", "3", "4" };
1467
1468
1469                         // Skip<TSource> (int)
1470                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
1471                 }
1472
1473                 [Test]
1474                 public void SkipTest ()
1475                 {
1476                         int [] data = { 2, 1, 5, 3, 1 };
1477                         int [] expected = { 5, 3, 1 };
1478
1479                         // Skip<string> (TSource)
1480                         AssertAreSame (expected, data.Skip (2));
1481                         AssertAreSame (data, data.Skip (-2));
1482                 }
1483
1484                 [Test]
1485                 public void SkipWhileArgumentNullTest ()
1486                 {
1487                         string [] data = { "2", "1", "5", "3", "4" };
1488
1489
1490                         // SkipWhile<TSource> (Func<TSource, bool>)
1491                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile (x => true); });
1492                         AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, bool>) null); });
1493
1494                         // SkipWhile<TSource> (Func<TSource, int, bool>)
1495                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SkipWhile ((x, y) => true); });
1496                         AssertException<ArgumentNullException> (delegate () { data.SkipWhile ((Func<string, int, bool>) null); });
1497                 }
1498
1499                 [Test]
1500                 public void SkipWhileTest ()
1501                 {
1502                         int [] data = { 2, 1, 5, 3, 1 };
1503                         int [] expected = { 5, 3, 1 };
1504
1505
1506
1507                         // SkipWhile<TSource> (Func<TSource, bool>)
1508                         AssertAreSame (expected, data.SkipWhile (x => x != 5));
1509
1510                         // SkipWhile<TSource> (Func<TSource, int, bool>)
1511                         AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
1512                 }
1513
1514                 [Test]
1515                 public void JoinArgumentNullTest ()
1516                 {
1517                         string [] data = { "2", "1", "5", "3", "4" };
1518
1519
1520                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
1521                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test"); });
1522                         AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
1523                         AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
1524                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
1525                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null); });
1526
1527                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
1528                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Join (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1529                         AssertException<ArgumentNullException> (delegate () { data.Join ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1530                         AssertException<ArgumentNullException> (delegate () { data.Join (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1531                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
1532                         AssertException<ArgumentNullException> (delegate () { data.Join (data, x => "test", x => "test", (Func<string, string, string>) null, EqualityComparer<string>.Default); });
1533                 }
1534
1535                 [Test]
1536                 public void JoinTest ()
1537                 {
1538                         string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1539                         string [] dataInner1 = { "7", "3", "5", "8", "9" };
1540                         string [] expected1 = { "55", "33" };
1541
1542                         string [] dataOuter2 = { "2", "1", "3", "4" };
1543                         string [] dataInner2 = { "7", "5", "8", "9" };
1544                         string [] expected2 = { };
1545
1546
1547                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)
1548                         AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y));
1549                         AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y));
1550
1551                         // Join<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>, IEqualityComparer<string>)
1552                         AssertAreSame (expected1, dataOuter1.Join (dataInner1, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
1553                         AssertAreSame (expected2, dataOuter2.Join (dataInner2, x => x, x => x, (x, y) => x + y, EqualityComparer<string>.Default));
1554                 }
1555
1556                 [Test]
1557                 public void GroupJoinArgumentNullTest ()
1558                 {
1559                         string [] data = { "2", "1", "5", "3", "4" };
1560
1561
1562                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
1563                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test"); });
1564                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test"); });
1565                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test"); });
1566                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test"); });
1567                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null); });
1568
1569                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
1570                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupJoin (data, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1571                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin ((IEnumerable<string>) null, x => "test", x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1572                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, (Func<string, string>) null, x => "test", (x, y) => "test", EqualityComparer<string>.Default); });
1573                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", (Func<string, string>) null, (x, y) => "test", EqualityComparer<string>.Default); });
1574                         AssertException<ArgumentNullException> (delegate () { data.GroupJoin (data, x => "test", x => "test", (Func<string, IEnumerable<string>, string>) null, EqualityComparer<string>.Default); });
1575                 }
1576
1577                 [Test]
1578                 public void GroupJoinTest ()
1579                 {
1580                         string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1581                         string [] dataInner1 = { "7", "3", "5", "3", "9" };
1582                         string [] expected1 = { "2", "1", "55", "333", "4" };
1583
1584                         string [] dataOuter2 = { "2", "1", "5", "8", "4" };
1585                         string [] dataInner2 = { "7", "3", "6", "3", "9" };
1586                         string [] expected2 = { "2", "1", "5", "8", "4" };
1587
1588
1589                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)
1590                         AssertAreSame (expected1, (dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
1591                         AssertAreSame (expected2, (dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; })));
1592
1593                         // GroupJoin<TOuter,TInner,TKey,TResult> (IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult, IEqualityComparer<TKey>>)
1594                         AssertAreSame (expected1, dataOuter1.GroupJoin (dataInner1, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1595                         AssertAreSame (expected2, dataOuter2.GroupJoin (dataInner2, x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1596                 }
1597
1598                 [Test]
1599                 public void OrderByArgumentNullTest ()
1600                 {
1601                         string [] data = { "2", "1", "5", "3", "4" };
1602
1603
1604                         // OrderBy<TSource,TKey> (Func<TSource, TKey>)
1605                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test"); });
1606                         AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null); });
1607
1608                         // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1609                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderBy (x => "test", Comparer<string>.Default); });
1610                         AssertException<ArgumentNullException> (delegate () { data.OrderBy ((Func<string, string>) null, Comparer<string>.Default); });
1611                 }
1612
1613                 [Test]
1614                 public void OrderByTest ()
1615                 {
1616                         int [] data = { 2, 1, 5, 3, 4 };
1617                         int [] expected = { 1, 2, 3, 4, 5 };
1618
1619
1620                         // OrderBy<TSource,TKey> (Func<TSource, TKey>)
1621                         AssertAreSame (expected, data.OrderBy (x => x));
1622
1623                         // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1624                         AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
1625                 }
1626
1627                 [Test]
1628                 public void OrderByDescendingArgumentNullTest ()
1629                 {
1630                         string [] data = { "2", "1", "5", "3", "4" };
1631
1632
1633                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
1634                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test"); });
1635                         AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null); });
1636
1637                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1638                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).OrderByDescending (x => "test", Comparer<string>.Default); });
1639                         AssertException<ArgumentNullException> (delegate () { data.OrderByDescending ((Func<string, string>) null, Comparer<string>.Default); });
1640                 }
1641
1642                 [Test]
1643                 public void OrderByDescendingTest ()
1644                 {
1645                         int [] data = { 2, 1, 5, 3, 4 };
1646                         int [] expected = { 5, 4, 3, 2, 1 };
1647
1648
1649                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
1650                         AssertAreSame (expected, data.OrderByDescending (x => x));
1651
1652                         // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1653                         AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
1654                 }
1655
1656                 [Test]
1657                 public void ThenByArgumentNullTest ()
1658                 {
1659                         string [] data = { "2", "1", "5", "3", "4" };
1660
1661
1662                         // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1663                         AssertException<ArgumentNullException> (delegate () {
1664                                 ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
1665                         });
1666                         AssertException<ArgumentNullException> (delegate () {
1667                                 data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
1668                         });
1669
1670                         // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1671                         AssertException<ArgumentNullException> (delegate () {
1672
1673                                 ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
1674                         });
1675                         AssertException<ArgumentNullException> (delegate () {
1676
1677                                 data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
1678                         });
1679                 }
1680
1681                 [Test]
1682                 public void ThenByTest ()
1683                 {
1684                         int [] data = { 2, 1, 5, 3, 4 };
1685                         int [] expected = { 1, 2, 3, 4, 5 };
1686
1687
1688                         // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1689                         AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
1690
1691                         // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1692                         AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
1693                 }
1694
1695                 [Test]
1696                 public void ThenByDescendingArgumentNullTest ()
1697                 {
1698                         string [] data = { "2", "1", "5", "3", "4" };
1699
1700
1701                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1702                         AssertException<ArgumentNullException> (delegate () {
1703                                 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
1704                         });
1705                         AssertException<ArgumentNullException> (delegate () {
1706                                 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
1707                         });
1708
1709                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1710                         AssertException<ArgumentNullException> (delegate () {
1711
1712                                 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
1713                         });
1714                         AssertException<ArgumentNullException> (delegate () {
1715
1716                                 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
1717                         });
1718                 }
1719
1720                 [Test]
1721                 public void ThenByDescendingTest ()
1722                 {
1723                         int [] data = { 2, 1, 5, 3, 4 };
1724                         int [] expected = { 5, 4, 3, 2, 1 };
1725
1726
1727                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1728                         AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
1729
1730                         // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1731                         AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
1732                 }
1733
1734                 [Test]
1735                 public void GroupByArgumentNullTest ()
1736                 {
1737                         string [] data = { "2", "1", "5", "3", "4" };
1738
1739
1740                         // GroupBy<string,string> (Func<string, string>)
1741                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test")); });
1742                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null); });
1743
1744                         // GroupBy<string,string> (Func<string, string>, IEqualityComparer<string>)
1745                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1746                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1747
1748                         // GroupBy<string,string,string> (Func<string, string>, Func<string, string>)
1749                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
1750                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
1751                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
1752
1753                         // GroupBy<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
1754                         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); });
1755                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1756                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1757
1758                         // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>)
1759                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1760                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) null, (Func<string, IEnumerable<string>, string>) ((x, y) => "test")); });
1761                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null); });
1762
1763                         // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>)
1764                         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")); });
1765                         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")); });
1766                         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")); });
1767                         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); });
1768
1769                         // GroupBy<string,string,string> (Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
1770                         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); });
1771                         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); });
1772                         AssertException<ArgumentNullException> (delegate () { data.GroupBy<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, IEnumerable<string>, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
1773
1774                         // GroupBy<string,string,string,string> (Func<string, string>, Func<string, string>, Func<string, IEnumerable<string>, string>, IEqualityComparer<string>)
1775                         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); });
1776                         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); });
1777                         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); });
1778                         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); });
1779                 }
1780
1781                 [Test]
1782                 public void GroupByTest ()
1783                 {
1784                         string [] data = { "2", "1", "5", "3", "4", "3" };
1785
1786                         Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
1787                         expected.Add ("2", new List<string> () { "2" });
1788                         expected.Add ("1", new List<string> () { "1" });
1789                         expected.Add ("5", new List<string> () { "5" });
1790                         expected.Add ("3", new List<string> () { "3", "3" });
1791                         expected.Add ("4", new List<string> () { "4" });
1792
1793                         Dictionary<string, IEnumerable<string>> expected2 = new Dictionary<string, IEnumerable<string>> ();
1794                         expected2.Add ("2", new List<string> () { "22" });
1795                         expected2.Add ("1", new List<string> () { "11" });
1796                         expected2.Add ("5", new List<string> () { "55" });
1797                         expected2.Add ("3", new List<string> () { "33", "33" });
1798                         expected2.Add ("4", new List<string> () { "44" });
1799
1800                         string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
1801
1802                         // GroupBy<int,int> (Func<int, int>)
1803                         AssertAreSame (expected, data.GroupBy (x => x));
1804
1805                         // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
1806                         AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
1807
1808                         // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
1809                         AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
1810
1811                         // GroupBy<int,int,int> (Func<int, int>, Func<int, int>, IEqualityComparer<int>)
1812                         AssertAreSame (expected2, data.GroupBy (x => x, x => x + x, EqualityComparer<string>.Default));
1813
1814                         // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>)
1815                         AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
1816
1817                         // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>)
1818                         AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }));
1819
1820                         // GroupBy<int,int,int> (Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
1821                         AssertAreSame (expected3, data.GroupBy (x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1822
1823                         // GroupBy<int,int,int,int> (Func<int, int>, Func<int, int>, Func<int, IEnumerable<int>, int>, IEqualityComparer<int>)
1824                         AssertAreSame (expected3, data.GroupBy (x => x, x => x, (x, y) => { foreach (var s in y) x += s; return x; }, EqualityComparer<string>.Default));
1825                 }
1826
1827
1828                 class Data {
1829
1830                         public int Number;
1831                         public string String;
1832
1833                         public Data (int number, string str)
1834                         {
1835                                 Number = number;
1836                                 String = str;
1837                         }
1838                 }
1839
1840                 [Test]
1841                 public void GroupByLastNullGroup ()
1842                 {
1843                         var values = new List<Data> ();
1844
1845                         values.Add (new Data (0, "a"));
1846                         values.Add (new Data (1, "a"));
1847                         values.Add (new Data (2, "b"));
1848                         values.Add (new Data (3, "b"));
1849                         values.Add (new Data (4, null));
1850
1851                         var groups = values.GroupBy (d => d.String);
1852
1853                         Assert.AreEqual (3, groups.Count ());
1854                 }
1855
1856                 [Test]
1857                 public void ConcatArgumentNullTest ()
1858                 {
1859                         string [] data = { "2", "1", "5", "3", "4" };
1860
1861                         // Concat<TSource> (IEnumerable<TSource>)
1862                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
1863                         AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
1864                 }
1865
1866                 [Test]
1867                 public void ConcatTest ()
1868                 {
1869                         int [] data1 = { 2, 1, 5, 3, 4 };
1870                         int [] data2 = { 1, 2, 3, 4, 5 };
1871                         int [] expected = { 2, 1, 5, 3, 4, 1, 2, 3, 4, 5 };
1872
1873
1874                         // Concat<TSource> (IEnumerable<TSource>)
1875                         AssertAreSame (expected, data1.Concat (data2));
1876                 }
1877
1878                 [Test]
1879                 public void DistinctArgumentNullTest ()
1880                 {
1881                         //string [] data = { "2", "1", "5", "3", "4" };
1882
1883
1884                         // Distinct<TSource> ()
1885                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
1886
1887                         // Distinct<TSource> (IEqualityComparer<TSource>)
1888                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
1889                 }
1890
1891                 [Test]
1892                 public void DistinctTest ()
1893                 {
1894                         int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
1895                         int [] expected = { 2, 1, 5, 3, 4, 8 };
1896
1897
1898                         // Distinct<TSource> ()
1899                         AssertAreSame (expected, data.Distinct ());
1900
1901                         // Distinct<iTSourcent> (IEqualityComparer<TSource>)
1902                         AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
1903                 }
1904
1905                 [Test]
1906                 public void UnionArgumentNullTest ()
1907                 {
1908                         string [] data = { "2", "1", "5", "3", "4" };
1909
1910
1911                         // Union<TSource> (IEnumerable<TSource>)
1912                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
1913                         AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
1914
1915                         // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1916                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data, EqualityComparer<string>.Default); });
1917                         AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1918                 }
1919
1920                 [Test]
1921                 public void UnionTest ()
1922                 {
1923                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1924                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1925                         int [] expected = { 2, 1, 5, 7, 3, 4, 8 };
1926
1927                         // Union<TSource> (IEnumerable<TSource>)
1928                         AssertAreSame (expected, data1.Union (data2));
1929
1930                         // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1931                         AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
1932                 }
1933
1934                 [Test]
1935                 public void IntersectArgumentNullTest ()
1936                 {
1937                         string [] data = { "2", "1", "5", "3", "4" };
1938
1939
1940                         // Intersect<TSource> (IEnumerable<TSource>)
1941                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
1942                         AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
1943
1944                         // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1945                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data, EqualityComparer<string>.Default); });
1946                         AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1947                 }
1948
1949                 [Test]
1950                 public void IntersectTest ()
1951                 {
1952                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1953                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1954                         int [] expected = { 2, 1, 5, 3, 4 };
1955
1956
1957                         // Intersect<TSource> (IEnumerable<TSource>)
1958                         AssertAreSame (expected, data1.Intersect (data2));
1959
1960                         // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1961                         AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
1962                 }
1963
1964                 [Test]
1965                 public void ExceptArgumentNullTest ()
1966                 {
1967                         string [] data = { "2", "1", "5", "3", "4" };
1968
1969
1970                         // Except<TSource> (IEnumerable<TSource>)
1971                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
1972                         AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
1973
1974                         // Except<TSource> (IEnumerable<string>, IEqualityComparer<TSource>)
1975                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data, EqualityComparer<string>.Default); });
1976                         AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
1977                 }
1978
1979                 [Test]
1980                 public void ExceptTest ()
1981                 {
1982                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
1983                         int [] data2 = { 1, 2, 3, 8, 4, 5 };
1984                         int [] expected = { 7 };
1985
1986
1987                         // Except<TSource> (IEnumerable<TSource>)
1988                         AssertAreSame (expected, data1.Except (data2));
1989
1990                         // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1991                         AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
1992                 }
1993
1994                 [Test]
1995                 public void ReverseArgumentNullTest ()
1996                 {
1997                         //string [] data = { "2", "1", "5", "3", "4" };
1998
1999
2000                         // Reverse<TSource> ()
2001                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
2002                 }
2003
2004                 [Test]
2005                 public void ReverseTest ()
2006                 {
2007                         int [] data = { 2, 1, 5, 7, 3, 4 };
2008                         int [] expected = { 4, 3, 7, 5, 1, 2 };
2009
2010
2011
2012                         // Reverse<TSource> ()
2013                         AssertAreSame (expected, data.Reverse ());
2014                 }
2015
2016                 [Test]
2017                 public void SequenceEqualArgumentNullTest ()
2018                 {
2019                         string [] data = { "2", "1", "5", "3", "4" };
2020
2021
2022                         // SequenceEqual<TSource> (IEnumerable<TSource>)
2023                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
2024                         AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
2025
2026                         // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
2027                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data, EqualityComparer<string>.Default); });
2028                         AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null, EqualityComparer<string>.Default); });
2029                 }
2030
2031                 [Test]
2032                 public void SequenceEqualTest ()
2033                 {
2034                         int [] data1 = { 2, 1, 5, 7, 3, 4 };
2035                         int [] data2 = { 2, 1, 5, 7, 3, 4 };
2036                         int [] data3 = { 2, 1, 5, 7, 3, 4, 5 };
2037                         int [] data4 = { 2, 1, 5, 7, 3 };
2038                         int [] data5 = { 2, 1, 5, 8, 3, 4 };
2039
2040
2041                         // SequenceEqual<TSource> (IEnumerable<TSource>)
2042                         Assert.IsTrue (data1.SequenceEqual (data2));
2043                         Assert.IsFalse (data1.SequenceEqual (data3));
2044                         Assert.IsFalse (data1.SequenceEqual (data4));
2045                         Assert.IsFalse (data1.SequenceEqual (data5));
2046
2047                         // SequenceEqual<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
2048                         Assert.IsTrue (data1.SequenceEqual (data2, EqualityComparer<int>.Default));
2049                         Assert.IsFalse (data1.SequenceEqual (data3, EqualityComparer<int>.Default));
2050                         Assert.IsFalse (data1.SequenceEqual (data4, EqualityComparer<int>.Default));
2051                         Assert.IsFalse (data1.SequenceEqual (data5, EqualityComparer<int>.Default));
2052                 }
2053
2054                 [Test]
2055                 public void AsEnumerableArgumentNullTest ()
2056                 {
2057                         //string [] data = { "2", "1", "5", "3", "4" };
2058
2059                 }
2060
2061                 [Test]
2062                 public void AsEnumerableTest ()
2063                 {
2064                         int [] data = { 2, 1, 5, 7, 3, 4 };
2065
2066
2067                         // AsEnumerable<TSource> ()
2068                         Assert.AreSame (data, data.AsEnumerable ());
2069                 }
2070
2071                 [Test]
2072                 public void ToArrayArgumentNullTest ()
2073                 {
2074                         //string [] data = { "2", "1", "5", "3", "4" };
2075
2076
2077                         // ToArray<TSource> ()
2078                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
2079                 }
2080
2081                 [Test]
2082                 public void ToArrayTest ()
2083                 {
2084                         int [] data = { 2, 3, 4, 5 };
2085                         int [] expected = { 2, 3, 4, 5 };
2086
2087
2088                         // ToArray<TSource> ()
2089                         AssertAreSame (expected, data.ToArray ());
2090                 }
2091
2092                 [Test]
2093                 public void ToListArgumentNullTest ()
2094                 {
2095                         //string [] data = { "2", "1", "5", "3", "4" };
2096
2097
2098                         // ToList<string> ()
2099                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
2100                 }
2101
2102                 [Test]
2103                 public void ToListTest ()
2104                 {
2105                         int [] data = { 2, 4, 5, 1 };
2106                         int [] expected = { 2, 4, 5, 1 };
2107
2108
2109                         // ToList<int> ()
2110                         AssertAreSame (expected, data.ToList ());
2111                 }
2112
2113                 [Test]
2114                 public void ToDictionaryArgumentNullTest ()
2115                 {
2116                         string [] data = { "2", "1", "5", "3", "4" };
2117
2118
2119                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
2120                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test"); });
2121                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null); });
2122
2123                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
2124                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", EqualityComparer<string>.Default); });
2125                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, EqualityComparer<string>.Default); });
2126
2127                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
2128                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test"); });
2129                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test"); });
2130                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null); });
2131
2132                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
2133                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToDictionary (x => "test", x => "test", EqualityComparer<string>.Default); });
2134                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary ((Func<string, string>) null, x => "test", EqualityComparer<string>.Default); });
2135                         AssertException<ArgumentNullException> (delegate () { data.ToDictionary (x => "test", (Func<string, string>) null, EqualityComparer<string>.Default); });
2136                 }
2137
2138                 [Test]
2139                 public void ToDictionaryTest ()
2140                 {
2141                         string [] data = { "2", "1", "5", "3", "4" };
2142                         Dictionary<string, string> expected = new Dictionary<string, string> ();
2143                         expected.Add ("k2", "2");
2144                         expected.Add ("k1", "1");
2145                         expected.Add ("k5", "5");
2146                         expected.Add ("k3", "3");
2147                         expected.Add ("k4", "4");
2148
2149
2150                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>)
2151                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x));
2152                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key"); });
2153
2154                         // ToDictionary<TSource,TKey> (Func<TSource, TKey>, IEqualityComparer<TKey>)
2155                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, EqualityComparer<string>.Default));
2156                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", EqualityComparer<string>.Default); });
2157
2158                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>)
2159                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x));
2160                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x); });
2161
2162                         // ToDictionary<TSource,TKey,TElement> (Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
2163                         AssertAreSame (expected, ((IEnumerable<string>) data).ToDictionary (x => "k" + x, x => x, EqualityComparer<string>.Default));
2164                         AssertException<ArgumentException> (delegate () { data.ToDictionary (x => "key", x => x, EqualityComparer<string>.Default); });
2165                 }
2166
2167                 [Test]
2168                 public void ToLookupArgumentNullTest ()
2169                 {
2170                         string [] data = { "2", "1", "5", "3", "4" };
2171
2172
2173                         // ToLookup<string,string> (Func<string, string>)
2174                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test")); });
2175                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null); });
2176
2177                         // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
2178                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string> ((Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2179                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string> ((Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2180
2181                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
2182                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) (x => "test")); });
2183                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test")); });
2184                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null); });
2185
2186                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
2187                         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); });
2188                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) null, (Func<string, string>) (x => "test"), (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2189                         AssertException<ArgumentNullException> (delegate () { data.ToLookup<string, string, string> ((Func<string, string>) (x => "test"), (Func<string, string>) null, (IEqualityComparer<string>) EqualityComparer<string>.Default); });
2190                 }
2191
2192                 [Test]
2193                 public void ToLookupTest ()
2194                 {
2195                         string [] data = { "23", "12", "55", "42", "41" };
2196                         Dictionary<string, IEnumerable<string>> expected = new Dictionary<string, IEnumerable<string>> ();
2197                         expected.Add ("2", new List<string> () { "23" });
2198                         expected.Add ("1", new List<string> () { "12" });
2199                         expected.Add ("5", new List<string> () { "55" });
2200                         expected.Add ("4", new List<string> () { "42", "41" });
2201
2202                         Assert.AreEqual (expected.Count, ((IEnumerable<string>)data).ToLookup ((x => x [0].ToString ())).Count);
2203                         
2204                         // ToLookup<string,string> (Func<string, string>)
2205                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
2206
2207                         // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
2208                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
2209
2210                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
2211                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
2212
2213                         // ToLookup<string,string,string> (Func<string, string>, Func<string, string>, IEqualityComparer<string>)
2214                         AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x, EqualityComparer<string>.Default));
2215                 }
2216                 
2217                 [Test]
2218                 public void ToLookupNullKeyTest ()
2219                 {
2220                         string[] strs = new string[] { "one", null, "two", null, "three" };
2221                         
2222                         int i = 0;
2223                         var l = strs.ToLookup (s => (s == null) ? null : "numbers", s => (s == null) ? (++i).ToString() : s);
2224                         
2225                         Assert.AreEqual (2, l.Count);
2226                         Assert.AreEqual (2, l [null].Count());
2227                         Assert.IsTrue (l [null].Contains ("1"));
2228                         Assert.IsTrue (l [null].Contains ("2"));
2229                         
2230                         Assert.AreEqual (3, l ["numbers"].Count());
2231                         Assert.IsTrue (l ["numbers"].Contains ("one"));
2232                         Assert.IsTrue (l ["numbers"].Contains ("two"));
2233                         Assert.IsTrue (l ["numbers"].Contains ("three"));
2234                 }
2235
2236                 [Test]
2237                 public void DefaultIfEmptyArgumentNullTest ()
2238                 {
2239                         //string [] data = { "2", "1", "5", "3", "4" };
2240
2241
2242                         // DefaultIfEmpty<string> ()
2243                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
2244
2245                         // DefaultIfEmpty<string> (string)
2246                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
2247                 }
2248
2249                 [Test]
2250                 public void DefaultIfEmptyTest ()
2251                 {
2252                         string [] data = { "2", "1", "5", "3", "4" };
2253                         string [] empty = { };
2254                         string [] default1 = { null };
2255                         string [] default2 = { "default" };
2256
2257
2258                         // DefaultIfEmpty<string> ()
2259                         AssertAreSame (data, data.DefaultIfEmpty ());
2260                         AssertAreSame (default1, empty.DefaultIfEmpty ());
2261
2262                         // DefaultIfEmpty<string> (string)
2263                         AssertAreSame (data, data.DefaultIfEmpty ("default"));
2264                         AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
2265                 }
2266
2267                 [Test]
2268                 public void OfTypeArgumentNullTest ()
2269                 {
2270                         //string [] data = { "2", "1", "5", "3", "4" };
2271
2272
2273                         // OfType<string> ()
2274                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
2275                 }
2276
2277                 [Test]
2278                 public void OfTypeTest ()
2279                 {
2280                         object [] data = { "2", 2, "1", "5", "3", "4" };
2281                         string [] expected = { "2", "1", "5", "3", "4" };
2282
2283
2284                         // OfType<string> ()
2285                         AssertAreSame (expected, data.OfType<string> ());
2286                 }
2287
2288                 [Test]
2289                 public void CastArgumentNullTest ()
2290                 {
2291                         //string [] data = { "2", "1", "5", "3", "4" };
2292
2293
2294                         // Cast<string> ()
2295                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
2296                 }
2297
2298                 [Test]
2299                 public void CastTest ()
2300                 {
2301                         object [] data = { 1, 2, 3 };
2302                         int [] expected = { 1, 2, 3 };
2303
2304
2305                         // Cast<string> ()
2306                         AssertAreSame (expected, data.Cast<int> ());
2307                         AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
2308                         data.Cast<IEnumerable> ();
2309                 }
2310
2311                 [Test]
2312                 public void RangeArgumentNullTest ()
2313                 {
2314                         //string [] data = { "2", "1", "5", "3", "4" };
2315
2316                 }
2317
2318                 [Test]
2319                 public void RangeTest ()
2320                 {
2321                         int [] expected = { 2, 3, 4, 5 };
2322
2323                         // Range<> (int)
2324                         AssertAreSame (expected, Enumerable.Range (2, 4));
2325                         AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (2, -3); });
2326                         AssertException<ArgumentOutOfRangeException> (delegate () { Enumerable.Range (int.MaxValue - 5, 7); });
2327                         Enumerable.Range (int.MaxValue - 5, 6);
2328                 }
2329
2330                 [Test]
2331                 public void ExceptMultipleItems ()
2332                 {
2333                         var data = new [] { 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10 };
2334                         var expected = new [] { 2, 4, 6, 8, 10 };
2335
2336                         AssertAreSame (expected, data.Except (new [] { 1, 3, 5, 7, 9 }));
2337                 }
2338         }
2339 }