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