2 // EnumerableMoreTest.cs
5 // Andreas Noever <andreas.noever@gmail.com>
7 // (C) 2007 Andreas Noever
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections;
31 using System.Collections.Generic;
33 using NUnit.Framework;
36 namespace MonoTests.System.Linq {
39 public class EnumerableMoreTest {
41 class BigEnumerable : IEnumerable<int> {
42 public readonly ulong Count;
43 public BigEnumerable (ulong Count)
49 #region IEnumerable<int> Members
51 public IEnumerator<int> GetEnumerator ()
53 return new BigEnumerator (this);
58 #region IEnumerable Members
60 IEnumerator IEnumerable.GetEnumerator ()
62 throw new NotImplementedException ();
68 class BigEnumerator : IEnumerator<int> {
70 private ulong current;
72 public BigEnumerator (BigEnumerable parent)
82 public void Dispose ()
86 object IEnumerator.Current
88 get { throw new NotImplementedException (); }
91 public bool MoveNext ()
93 if (current == Parent.Count)
101 throw new NotImplementedException ();
106 public static void AssertException<T> (Action action) where T : Exception
114 Assert.Fail ("Expected: " + typeof (T).Name);
117 static void AssertAreSame<K, V> (K expectedKey, IEnumerable<V> expectedValues, IGrouping<K, V> actual)
119 if (expectedValues == null) {
120 Assert.IsNull (actual);
124 Assert.IsNotNull (actual);
126 Assert.AreEqual (expectedKey, actual.Key);
128 var ee = expectedValues.GetEnumerator ();
129 var ea = actual.GetEnumerator ();
131 while (ee.MoveNext ()) {
132 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
133 Assert.AreEqual (ee.Current, ea.Current);
137 Assert.Fail ("Unexpected element: " + ee.Current);
140 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, IEnumerable<IGrouping<K, V>> actual)
142 if (expected == null) {
143 Assert.IsNull (actual);
147 Assert.IsNotNull (actual);
149 var ee = expected.GetEnumerator ();
150 var ea = actual.GetEnumerator ();
152 while (ee.MoveNext ()) {
153 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
154 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
158 Assert.Fail ("Unexpected element: " + ee.Current.Key);
161 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, ILookup<K, V> actual)
163 if (expected == null) {
164 Assert.IsNull (actual);
168 Assert.IsNotNull (actual);
170 var ee = expected.GetEnumerator ();
171 var ea = actual.GetEnumerator ();
173 while (ee.MoveNext ()) {
174 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
175 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
179 Assert.Fail ("Unexpected element: " + ee.Current.Key);
182 static void AssertAreSame<K, V> (IDictionary<K, V> expected, IDictionary<K, V> actual)
184 if (expected == null) {
185 Assert.IsNull (actual);
189 Assert.IsNotNull (actual);
191 var ee = expected.GetEnumerator ();
192 var ea = actual.GetEnumerator ();
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);
201 Assert.Fail ("Unexpected element: " + ee.Current.Key + ", " + ee.Current.Value);
204 static void AssertAreSame<T> (IEnumerable<T> expected, IEnumerable<T> actual)
206 if (expected == null) {
207 Assert.IsNull (actual);
211 Assert.IsNotNull (actual);
213 IEnumerator<T> ee = expected.GetEnumerator ();
214 IEnumerator<T> ea = actual.GetEnumerator ();
216 while (ee.MoveNext ()) {
217 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
218 Assert.AreEqual (ee.Current, ea.Current);
222 Assert.Fail ("Unexpected element: " + ea.Current);
226 public void FirstArgumentNullTest ()
228 string [] data = { "2", "1", "5", "3", "4" };
232 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).First (); });
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); });
240 public void FirstTest ()
242 int [] data = { 2, 1, 5, 3, 4 };
246 Assert.AreEqual (2, data.First ());
247 AssertException<InvalidOperationException> (delegate () { empty.First (); });
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); });
256 public void FirstOrDefaultArgumentNullTest ()
258 string [] data = { "2", "1", "5", "3", "4" };
261 // FirstOrDefault<TSource> ()
262 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).FirstOrDefault (); });
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); });
270 public void FirstOrDefaultTest ()
272 int [] data = { 2, 1, 5, 3, 4 };
276 // FirstOrDefault<TSource> ()
277 Assert.AreEqual (2, data.FirstOrDefault ());
278 Assert.AreEqual (0, empty.FirstOrDefault ());
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));
288 public void LastArgumentNullTest ()
290 string [] data = { "2", "1", "5", "3", "4" };
294 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Last (); });
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); });
302 public void LastTest ()
304 int [] data = { 2, 1, 1, 3, 4, 5 };
308 Assert.AreEqual (5, data.Last ());
309 AssertException<InvalidOperationException> (delegate () { empty.Last (); });
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); });
318 public void LastOrDefaultArgumentNullTest ()
320 string [] data = { "2", "1", "5", "3", "4" };
323 // LastOrDefault<TSource> ()
324 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LastOrDefault (); });
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); });
332 public void LastOrDefaultTest ()
334 int [] data = { 2, 1, 5, 3, 4 };
338 // LastOrDefault<TSource> ()
339 Assert.AreEqual (4, data.LastOrDefault ());
340 Assert.AreEqual (0, empty.LastOrDefault ());
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));
349 public void SingleArgumentNullTest ()
351 string [] data = { "2", "1", "5", "3", "4" };
354 // Single<TSource> ()
355 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Single (); });
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); });
363 public void SingleTest ()
366 int [] data2 = { 2, 3, 5 };
370 // Single<TSource> ()
371 Assert.AreEqual (2, data.Single ());
372 AssertException<InvalidOperationException> (delegate () { data2.Single (); });
373 AssertException<InvalidOperationException> (delegate () { empty.Single (); });
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); });
383 public void SingleOrDefaultArgumentNullTest ()
385 string [] data = { "2", "1", "5", "3", "4" };
388 // SingleOrDefault<TSource> ()
389 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SingleOrDefault (); });
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); });
397 public void SingleOrDefaultTest ()
400 int [] data2 = { 2, 3, 5 };
404 // SingleOrDefault<TSource> ()
405 Assert.AreEqual (2, data.SingleOrDefault ());
406 Assert.AreEqual (0, empty.SingleOrDefault ());
407 AssertException<InvalidOperationException> (delegate () { data2.SingleOrDefault (); });
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); });
417 public void ElementAtArgumentNullTest ()
419 //string [] data = { "2", "1", "5", "3", "4" };
422 // ElementAt<TSource> (int)
423 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAt (0); });
427 public void ElementAtTest ()
429 int [] data = { 2, 3, 4, 5 };
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); });
440 public void ElementAtOrDefaultArgumentNullTest ()
442 //string [] data = { "2", "1", "5", "3", "4" };
445 // ElementAtOrDefault<TSource> (int)
446 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ElementAtOrDefault (0); });
450 public void ElementAtOrDefaultTest ()
452 int [] data = { 2, 3, 4, 5 };
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));
465 public void EmptyTest ()
467 IEnumerable<string> empty = Enumerable.Empty<string> ();
468 Assert.IsFalse (empty.GetEnumerator ().MoveNext ());
473 public void AnyArgumentNullTest ()
475 string [] data = { "2", "1", "5", "3", "4" };
479 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Any (); });
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); });
487 public void AnyTest ()
489 int [] data = { 5, 2, 3, 1, 6 };
494 Assert.IsTrue (data.Any ());
495 Assert.IsFalse (empty.Any ());
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));
504 public void AllArgumentNullTest ()
506 string [] data = { "2", "1", "5", "3", "4" };
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); });
515 public void AllTest ()
517 int [] data = { 5, 2, 3, 1, 6 };
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));
527 public void CountArgumentNullTest ()
529 string [] data = { "2", "1", "5", "3", "4" };
533 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Count (); });
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); });
541 public void CountTest ()
543 int [] data = { 5, 2, 3, 1, 6 };
546 Assert.AreEqual (5, data.Count ());
548 // Count<TSource> (Func<TSource, bool>)
549 Assert.AreEqual (3, data.Count (x => x < 5));
554 [Ignore ("Takes some time.")]
555 public void CountOverflowTest ()
557 //BigEnumerable data = new BigEnumerable ((ulong) int.MaxValue + 1);
560 //AssertException<OverflowException> (delegate () { data.Count (); });
562 // Count<TSource> (Func<TSource, bool>)
563 //AssertException<OverflowException> (delegate () { data.Count (x => 3 == x); });
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); });
571 public void LongCountArgumentNullTest ()
573 string [] data = { "2", "1", "5", "3", "4" };
576 // LongCount<TSource> ()
577 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).LongCount (); });
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); });
585 public void LongCountTest ()
587 int [] data = { 5, 2, 3, 1, 6 };
589 //TODO: Overflow test...
591 // LongCount<TSource> ()
592 Assert.AreEqual (5, data.LongCount ());
593 Assert.AreEqual (5, Enumerable.Range (0, 5).LongCount ());
595 // LongCount<TSource> (Func<TSource, bool>)
596 Assert.AreEqual (3, data.LongCount (x => x < 5));
600 public void ContainsArgumentNullTest ()
602 //string [] data = { "2", "1", "5", "3", "4" };
605 // Contains<TSource> (TSource)
606 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2"); });
608 // Contains<TSource> (TSource, IEqualityComparer<TSource>)
609 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Contains ("2", (IEqualityComparer<string>) EqualityComparer<string>.Default); });
613 public void ContainsTest ()
615 int [] data = { 5, 2, 3, 1, 6 };
618 // Contains<TSource> (TSource)
619 Assert.IsTrue (data.Contains (2));
620 Assert.IsFalse (data.Contains (0));
622 // Contains<TSource> (TSource, IEqualityComparer<TSource>)
623 Assert.IsTrue (data.Contains (2, EqualityComparer<int>.Default));
624 Assert.IsFalse (data.Contains (0, EqualityComparer<int>.Default));
628 public void AggregateArgumentNullTest ()
630 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
648 public void AggregateTest ()
650 string [] data = { "2", "1", "5", "3", "4" };
651 string [] empty = { };
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
657 // Aggregate<TSource,TAccumulate> (TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
658 Assert.AreEqual ("initial21534", (data.Aggregate ("initial", (x, y) => x + y)));
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 ())));
665 public void SumArgumentNullTest ()
667 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
710 // Sum (IEnumerable<int>)
711 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Sum (); });
713 // Sum (IEnumerable<int?>)
714 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Sum (); });
716 // Sum (IEnumerable<long>)
717 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Sum (); });
719 // Sum (IEnumerable<long?>)
720 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Sum (); });
722 // Sum (IEnumerable<float>)
723 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Sum (); });
725 // Sum (IEnumerable<float?>)
726 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Sum (); });
728 // Sum (IEnumerable<double>)
729 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Sum (); });
731 // Sum (IEnumerable<double?>)
732 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Sum (); });
734 // Sum (IEnumerable<decimal>)
735 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Sum (); });
737 // Sum (IEnumerable<decimal?>)
738 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Sum (); });
742 public void SumTest ()
744 string [] data = { "2", "3", "5", "5" };
746 //TODO: OverflowException
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))));
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))));
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))));
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))));
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))));
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))));
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))));
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))));
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))));
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))));
789 Assert.AreEqual (6, ((IEnumerable<int>) new int [] { 1, 2, 3 }).Sum ());
790 Assert.AreEqual (0, Enumerable.Empty<int> ().Sum ());
793 Assert.AreEqual (6, ((IEnumerable<Nullable<int>>) new int? [] { 1, 2, 3 }).Sum ());
794 Assert.AreEqual (0, Enumerable.Empty<int?> ().Sum ());
797 Assert.AreEqual (6, ((IEnumerable<Int64>) new long [] { 1, 2, 3 }).Sum ());
798 Assert.AreEqual (0, Enumerable.Empty<long> ().Sum ());
801 Assert.AreEqual (6, ((IEnumerable<Nullable<Int64>>) new long? [] { 1, 2, 3 }).Sum ());
802 Assert.AreEqual (0, Enumerable.Empty<long?> ().Sum ());
805 Assert.AreEqual (6, ((IEnumerable<Single>) new float [] { 1, 2, 3 }).Sum ());
806 Assert.AreEqual (0, Enumerable.Empty<float> ().Sum ());
809 Assert.AreEqual (6, ((IEnumerable<Nullable<Single>>) new float? [] { 1, 2, 3 }).Sum ());
810 Assert.AreEqual (0, Enumerable.Empty<float?> ().Sum ());
813 Assert.AreEqual (6, ((IEnumerable<Double>) new double [] { 1, 2, 3 }).Sum ());
814 Assert.AreEqual (0, Enumerable.Empty<double> ().Sum ());
817 Assert.AreEqual (6, ((IEnumerable<Nullable<Double>>) new double? [] { 1, 2, 3 }).Sum ());
818 Assert.AreEqual (0, Enumerable.Empty<double?> ().Sum ());
821 Assert.AreEqual (6, ((IEnumerable<Decimal>) new decimal [] { 1, 2, 3 }).Sum ());
822 Assert.AreEqual (0, Enumerable.Empty<decimal> ().Sum ());
825 Assert.AreEqual (6, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 1, 2, 3 }).Sum ());
826 Assert.AreEqual (0, Enumerable.Empty<decimal?> ().Sum ());
830 public void MinArgumentNullTest ()
832 string [] data = { "2", "1", "5", "3", "4" };
836 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Min<string> (); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
883 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Min (); });
886 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Min (); });
889 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Min (); });
892 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Min (); });
895 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Min (); });
898 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Min (); });
901 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Min (); });
904 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Min (); });
907 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Min (); });
910 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Min (); });
914 public void MinTest ()
916 string [] data = { "2", "1", "5", "3", "4" };
920 Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string> ());
923 // Min<TSource> (Func<TSource, int>)
924 Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, int>) (x => int.Parse (x))));
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))));
929 // Min<TSource> (Func<TSource, Int64>)
930 Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Int64>) (x => int.Parse (x))));
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))));
935 // Min<TSource> (Func<TSource, Single>)
936 Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Single>) (x => int.Parse (x))));
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))));
941 // Min<TSource> (Func<TSource, Double>)
942 Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Double>) (x => int.Parse (x))));
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))));
947 // Min<TSource> (Func<TSource, Decimal>)
948 Assert.AreEqual (1, ((IEnumerable<string>) data).Min<string> ((Func<string, Decimal>) (x => int.Parse (x))));
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))));
953 // Min<TSource,TSource> (Func<TSource, TSource>)
954 Assert.AreEqual ("1", ((IEnumerable<string>) data).Min<string, string> ((Func<string, string>) (x => x)));
957 Assert.AreEqual (2, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Min ());
960 Assert.AreEqual (2, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Min ());
963 Assert.AreEqual (2, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Min ());
966 Assert.AreEqual (2, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Min ());
969 Assert.AreEqual (2, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Min ());
972 Assert.AreEqual (2, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Min ());
975 Assert.AreEqual (2, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Min ());
978 Assert.AreEqual (2, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Min ());
981 Assert.AreEqual (2, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Min ());
984 Assert.AreEqual (2, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Min ());
988 public void MaxArgumentNullTest ()
990 string [] data = { "2", "1", "5", "3", "4" };
994 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Max<string> (); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
1041 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Max (); });
1044 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Max (); });
1047 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Max (); });
1050 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Max (); });
1053 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Max (); });
1056 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Max (); });
1059 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Max (); });
1062 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Max (); });
1065 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Max (); });
1068 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Max (); });
1072 public void MaxTest ()
1074 string [] data = { "2", "1", "5", "3", "4" };
1078 Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string> ());
1080 // Max<TSource> (Func<TSource, int>)
1081 Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, int>) (x => int.Parse (x))));
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))));
1086 // Max<TSource> (Func<TSource, Int64>)
1087 Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Int64>) (x => int.Parse (x))));
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))));
1092 // Max<TSource> (Func<TSource, Single>)
1093 Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Single>) (x => int.Parse (x))));
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))));
1098 // Max<TSource> (Func<TSource, Double>)
1099 Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Double>) (x => int.Parse (x))));
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))));
1104 // Max<TSource> (Func<TSource, Decimal>)
1105 Assert.AreEqual (5, ((IEnumerable<string>) data).Max<string> ((Func<string, Decimal>) (x => int.Parse (x))));
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))));
1110 // Max<TSource,TSource> (Func<TSource, TSource>)
1111 Assert.AreEqual ("5", ((IEnumerable<string>) data).Max<string, string> ((Func<string, string>) (x => x)));
1114 Assert.AreEqual (4, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Max ());
1117 Assert.AreEqual (4, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Max ());
1120 Assert.AreEqual (4, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Max ());
1123 Assert.AreEqual (4, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Max ());
1126 Assert.AreEqual (4, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Max ());
1129 Assert.AreEqual (4, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Max ());
1132 Assert.AreEqual (4, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Max ());
1135 Assert.AreEqual (4, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Max ());
1138 Assert.AreEqual (4, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Max ());
1141 Assert.AreEqual (4, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Max ());
1145 public void AverageArgumentNullTest ()
1147 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
1191 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<int>) null).Average (); });
1194 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<int>>) null).Average (); });
1197 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Int64>) null).Average (); });
1200 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Int64>>) null).Average (); });
1203 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Single>) null).Average (); });
1206 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Single>>) null).Average (); });
1209 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Double>) null).Average (); });
1212 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Double>>) null).Average (); });
1215 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Decimal>) null).Average (); });
1218 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<Nullable<Decimal>>) null).Average (); });
1222 public void AverageTest ()
1224 string [] data = { "2", "1", "5", "3", "4" };
1225 string [] empty = { };
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))); });
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))));
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))); });
1238 // Average<TSource> (Func<TSource, Nullable<Int64>>)
1239 Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, long?>) (x => (int?) int.Parse (x))));
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))); });
1245 // Average<TSource> (Func<TSource, Nullable<Single>>)
1246 Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, float?>) (x => (int?) int.Parse (x))));
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))); });
1252 // Average<TSource> (Func<TSource, Nullable<Double>>)
1253 Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, double?>) (x => (int?) int.Parse (x))));
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))); });
1259 // Average<TSource> (Func<TSource, Nullable<Decimal>>)
1260 Assert.AreEqual (3, ((IEnumerable<string>) data).Average<string> ((Func<string, decimal?>) (x => (int?) int.Parse (x))));
1264 Assert.AreEqual (3, ((IEnumerable<int>) new int [] { 2, 3, 4 }).Average ());
1265 AssertException<InvalidOperationException> (delegate () { new int [0].Average (); });
1268 Assert.AreEqual (3, ((IEnumerable<Nullable<int>>) new int? [] { 2, 3, 4 }).Average ());
1271 Assert.AreEqual (3, ((IEnumerable<Int64>) new long [] { 2, 3, 4 }).Average ());
1272 AssertException<InvalidOperationException> (delegate () { new long [0].Average (); });
1275 Assert.AreEqual (3, ((IEnumerable<Nullable<Int64>>) new long? [] { 2, 3, 4 }).Average ());
1278 Assert.AreEqual (3, ((IEnumerable<Single>) new float [] { 2, 3, 4 }).Average ());
1279 AssertException<InvalidOperationException> (delegate () { new float [0].Average (); });
1282 Assert.AreEqual (3, ((IEnumerable<Nullable<Single>>) new float? [] { 2, 3, 4 }).Average ());
1285 Assert.AreEqual (3, ((IEnumerable<Double>) new double [] { 2, 3, 4 }).Average ());
1286 AssertException<InvalidOperationException> (delegate () { new double [0].Average (); });
1289 Assert.AreEqual (3, ((IEnumerable<Nullable<Double>>) new double? [] { 2, 3, 4 }).Average ());
1292 Assert.AreEqual (3, ((IEnumerable<Decimal>) new decimal [] { 2, 3, 4 }).Average ());
1293 AssertException<InvalidOperationException> (delegate () { new decimal [0].Average (); });
1296 Assert.AreEqual (3, ((IEnumerable<Nullable<Decimal>>) new decimal? [] { 2, 3, 4 }).Average ());
1300 public void WhereArgumentNullTest ()
1302 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1314 public void WhereTest ()
1316 int [] data = { 2, 1, 5, 3, 4 };
1317 int [] expected1 = { 2, 1 };
1318 int [] expected2 = { 2 };
1320 // Where<TSource> (Func<TSource, bool>)
1321 AssertAreSame (expected1, data.Where (x => x < 3));
1323 // Where<TSource> (Func<TSource, int, bool>)
1324 AssertAreSame (expected2, data.Where ((x, y) => x < 3 && y != 1));
1328 public void SelectArgumentNullTest ()
1330 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1343 public void SelectTest ()
1345 string [] data = { "2", "1", "5", "3", "4" };
1346 string [] expected1 = { "2x", "1x", "5x", "3x", "4x" };
1347 string [] expected2 = { "2x0", "1x1", "5x2", "3x3", "4x4" };
1350 // Select<TSource,TResult> (Func<TSource, TResult>)
1351 AssertAreSame (expected1, data.Select<string, string> (x => x + "x"));
1353 // Select<TSource,TResult> (Func<TSource, int, TResult>)
1354 AssertAreSame (expected2, data.Select<string, string> ((x, y) => x + "x" + y));
1358 public void SelectManyArgumentNullTest ()
1360 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
1383 public void SelectManyTest ()
1385 string [] data = { "0", "1" };
1386 string [] expected = { "0", "00", "1", "11" };
1388 // SelectMany<TSource,TResult> (Func<TSource, IEnumerable<TResult>>)
1389 AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany (x => new string [] { x, x + x }));
1391 // SelectMany<TSource,TResult> (Func<TSource, int, IEnumerable<TResult>>)
1392 AssertAreSame (expected, ((IEnumerable<string>) data).SelectMany ((x, y) => new string [] { x, x + y }));
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));
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));
1402 public void TakeArgumentNullTest ()
1404 //string [] data = { "2", "1", "5", "3", "4" };
1407 // Take<TSource> (int)
1408 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Take (0); });
1412 public void TakeTest ()
1414 int [] data = { 2, 1, 5, 3, 1 };
1415 int [] expected = { 2, 1 };
1418 // Take<TSource> (int)
1419 AssertAreSame (expected, data.Take (2));
1420 AssertAreSame (empty, data.Take (-2));
1424 public void TakeWhileArgumentNullTest ()
1426 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1439 public void TakeWhileTest ()
1441 int [] data = { 2, 1, 5, 3, 1 };
1442 int [] expected = { 2, 1 };
1445 // TakeWhile<TSource> (Func<TSource, bool>)
1446 AssertAreSame (expected, data.TakeWhile (x => x != 5));
1448 // TakeWhile<TSource> (Func<TSource, int, bool>)
1449 AssertAreSame (expected, data.TakeWhile ((x, y) => y != 2));
1453 public void SkipArgumentNullTest ()
1455 //string [] data = { "2", "1", "5", "3", "4" };
1458 // Skip<TSource> (int)
1459 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Skip (0); });
1463 public void SkipTest ()
1465 int [] data = { 2, 1, 5, 3, 1 };
1466 int [] expected = { 5, 3, 1 };
1468 // Skip<string> (TSource)
1469 AssertAreSame (expected, data.Skip (2));
1470 AssertAreSame (data, data.Skip (-2));
1474 public void SkipWhileArgumentNullTest ()
1476 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1489 public void SkipWhileTest ()
1491 int [] data = { 2, 1, 5, 3, 1 };
1492 int [] expected = { 5, 3, 1 };
1496 // SkipWhile<TSource> (Func<TSource, bool>)
1497 AssertAreSame (expected, data.SkipWhile (x => x != 5));
1499 // SkipWhile<TSource> (Func<TSource, int, bool>)
1500 AssertAreSame (expected, data.SkipWhile ((x, y) => y != 2));
1504 [Category ("NotWorking")]
1505 public void JoinArgumentNullTest ()
1507 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1526 public void JoinTest ()
1528 string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1529 string [] dataInner1 = { "7", "3", "5", "8", "9" };
1530 string [] expected1 = { "55", "33" };
1532 string [] dataOuter2 = { "2", "1", "3", "4" };
1533 string [] dataInner2 = { "7", "5", "8", "9" };
1534 string [] expected2 = { };
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));
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));
1547 [Category ("NotWorking")]
1548 public void GroupJoinArgumentNullTest ()
1550 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1569 public void GroupJoinTest ()
1571 string [] dataOuter1 = { "2", "1", "5", "3", "4" };
1572 string [] dataInner1 = { "7", "3", "5", "3", "9" };
1573 string [] expected1 = { "2", "1", "55", "333", "4" };
1575 string [] dataOuter2 = { "2", "1", "5", "8", "4" };
1576 string [] dataInner2 = { "7", "3", "6", "3", "9" };
1577 string [] expected2 = { "2", "1", "5", "8", "4" };
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; })));
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));
1590 public void OrderByArgumentNullTest ()
1592 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1605 public void OrderByTest ()
1607 int [] data = { 2, 1, 5, 3, 4 };
1608 int [] expected = { 1, 2, 3, 4, 5 };
1611 // OrderBy<TSource,TKey> (Func<TSource, TKey>)
1612 AssertAreSame (expected, data.OrderBy (x => x));
1614 // OrderBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1615 AssertAreSame (expected, data.OrderBy (x => x, Comparer<int>.Default));
1619 public void OrderByDescendingArgumentNullTest ()
1621 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
1634 public void OrderByDescendingTest ()
1636 int [] data = { 2, 1, 5, 3, 4 };
1637 int [] expected = { 5, 4, 3, 2, 1 };
1640 // OrderByDescending<TSource,TKey> (Func<TSource, TKey>)
1641 AssertAreSame (expected, data.OrderByDescending (x => x));
1643 // OrderByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1644 AssertAreSame (expected, data.OrderByDescending (x => x, Comparer<int>.Default));
1648 public void ThenByArgumentNullTest ()
1650 string [] data = { "2", "1", "5", "3", "4" };
1653 // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1654 AssertException<ArgumentNullException> (delegate () {
1655 ((IOrderedEnumerable<string>) null).ThenBy (x => "test");
1657 AssertException<ArgumentNullException> (delegate () {
1658 data.OrderBy (x => x).ThenBy ((Func<string, string>) null);
1661 // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1662 AssertException<ArgumentNullException> (delegate () {
1664 ((IOrderedEnumerable<string>) null).ThenBy (x => "test", Comparer<string>.Default);
1666 AssertException<ArgumentNullException> (delegate () {
1668 data.OrderBy (x => x).ThenBy ((Func<string, string>) null, Comparer<string>.Default);
1673 public void ThenByTest ()
1675 int [] data = { 2, 1, 5, 3, 4 };
1676 int [] expected = { 1, 2, 3, 4, 5 };
1679 // ThenBy<TSource,TKey> (Func<TSource, TKey>)
1680 AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x));
1682 // ThenBy<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1683 AssertAreSame (expected, data.OrderBy (x => x).ThenBy (x => x, Comparer<int>.Default));
1687 public void ThenByDescendingArgumentNullTest ()
1689 string [] data = { "2", "1", "5", "3", "4" };
1692 // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1693 AssertException<ArgumentNullException> (delegate () {
1694 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test");
1696 AssertException<ArgumentNullException> (delegate () {
1697 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null);
1700 // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1701 AssertException<ArgumentNullException> (delegate () {
1703 ((IOrderedEnumerable<string>) null).ThenByDescending (x => "test", Comparer<string>.Default);
1705 AssertException<ArgumentNullException> (delegate () {
1707 data.OrderBy (x => x).ThenByDescending ((Func<string, string>) null, Comparer<string>.Default);
1712 public void ThenByDescendingTest ()
1714 int [] data = { 2, 1, 5, 3, 4 };
1715 int [] expected = { 5, 4, 3, 2, 1 };
1718 // ThenByDescending<TSource,TKey> (Func<TSource, TKey>)
1719 AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x));
1721 // ThenByDescending<TSource,TKey> (Func<TSource, TKey>, IComparer<string>)
1722 AssertAreSame (expected, data.OrderBy (x => 0).ThenByDescending (x => x, Comparer<int>.Default));
1726 [Category ("NotWorking")]
1727 public void GroupByArgumentNullTest ()
1729 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
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); });
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); });
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); });
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); });
1774 [Category ("NotWorking")]
1775 public void GroupByTest ()
1777 string [] data = { "2", "1", "5", "3", "4", "3" };
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" });
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" });
1793 string [] expected3 = new string [] { "22", "11", "55", "333", "44" };
1795 // GroupBy<int,int> (Func<int, int>)
1796 AssertAreSame (expected, data.GroupBy (x => x));
1798 // GroupBy<int,int> (Func<int, int>, IEqualityComparer<int>)
1799 AssertAreSame (expected, data.GroupBy (x => x, EqualityComparer<string>.Default));
1801 // GroupBy<int,int,int> (Func<int, int>, Func<int, int>)
1802 AssertAreSame (expected2, data.GroupBy (x => x, x => x + x));
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));
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; }));
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; }));
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));
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));
1821 public void ConcatArgumentNullTest ()
1823 string [] data = { "2", "1", "5", "3", "4" };
1825 // Concat<TSource> (IEnumerable<TSource>)
1826 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Concat (data); });
1827 AssertException<ArgumentNullException> (delegate () { data.Concat ((IEnumerable<string>) null); });
1831 public void ConcatTest ()
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 };
1838 // Concat<TSource> (IEnumerable<TSource>)
1839 AssertAreSame (expected, data1.Concat (data2));
1843 public void DistinctArgumentNullTest ()
1845 //string [] data = { "2", "1", "5", "3", "4" };
1848 // Distinct<TSource> ()
1849 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (); });
1851 // Distinct<TSource> (IEqualityComparer<TSource>)
1852 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Distinct (EqualityComparer<string>.Default); });
1856 public void DistinctTest ()
1858 int [] data = { 2, 1, 5, 3, 4, 2, 5, 3, 1, 8 };
1859 int [] expected = { 2, 1, 5, 3, 4, 8 };
1862 // Distinct<TSource> ()
1863 AssertAreSame (expected, data.Distinct ());
1865 // Distinct<iTSourcent> (IEqualityComparer<TSource>)
1866 AssertAreSame (expected, data.Distinct (EqualityComparer<int>.Default));
1870 public void UnionArgumentNullTest ()
1872 string [] data = { "2", "1", "5", "3", "4" };
1875 // Union<TSource> (IEnumerable<TSource>)
1876 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Union (data); });
1877 AssertException<ArgumentNullException> (delegate () { data.Union ((IEnumerable<string>) null); });
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); });
1885 public void UnionTest ()
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 };
1891 // Union<TSource> (IEnumerable<TSource>)
1892 AssertAreSame (expected, data1.Union (data2));
1894 // Union<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1895 AssertAreSame (expected, data1.Union (data2, EqualityComparer<int>.Default));
1899 public void IntersectArgumentNullTest ()
1901 string [] data = { "2", "1", "5", "3", "4" };
1904 // Intersect<TSource> (IEnumerable<TSource>)
1905 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Intersect (data); });
1906 AssertException<ArgumentNullException> (delegate () { data.Intersect ((IEnumerable<string>) null); });
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); });
1914 public void IntersectTest ()
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 };
1921 // Intersect<TSource> (IEnumerable<TSource>)
1922 AssertAreSame (expected, data1.Intersect (data2));
1924 // Intersect<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1925 AssertAreSame (expected, data1.Intersect (data2, EqualityComparer<int>.Default));
1929 public void ExceptArgumentNullTest ()
1931 string [] data = { "2", "1", "5", "3", "4" };
1934 // Except<TSource> (IEnumerable<TSource>)
1935 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Except (data); });
1936 AssertException<ArgumentNullException> (delegate () { data.Except ((IEnumerable<string>) null); });
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); });
1944 public void ExceptTest ()
1946 int [] data1 = { 2, 1, 5, 7, 3, 4 };
1947 int [] data2 = { 1, 2, 3, 8, 4, 5 };
1948 int [] expected = { 7 };
1951 // Except<TSource> (IEnumerable<TSource>)
1952 AssertAreSame (expected, data1.Except (data2));
1954 // Except<TSource> (IEnumerable<TSource>, IEqualityComparer<TSource>)
1955 AssertAreSame (expected, data1.Except (data2, EqualityComparer<int>.Default));
1959 public void ReverseArgumentNullTest ()
1961 //string [] data = { "2", "1", "5", "3", "4" };
1964 // Reverse<TSource> ()
1965 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).Reverse (); });
1969 public void ReverseTest ()
1971 int [] data = { 2, 1, 5, 7, 3, 4 };
1972 int [] expected = { 4, 3, 7, 5, 1, 2 };
1976 // Reverse<TSource> ()
1977 AssertAreSame (expected, data.Reverse ());
1981 public void SequenceEqualArgumentNullTest ()
1983 string [] data = { "2", "1", "5", "3", "4" };
1986 // SequenceEqual<TSource> (IEnumerable<TSource>)
1987 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).SequenceEqual (data); });
1988 AssertException<ArgumentNullException> (delegate () { data.SequenceEqual ((IEnumerable<string>) null); });
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); });
1996 public void SequenceEqualTest ()
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 };
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));
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));
2019 public void AsEnumerableArgumentNullTest ()
2021 //string [] data = { "2", "1", "5", "3", "4" };
2026 public void AsEnumerableTest ()
2028 int [] data = { 2, 1, 5, 7, 3, 4 };
2031 // AsEnumerable<TSource> ()
2032 Assert.AreSame (data, data.AsEnumerable ());
2036 public void ToArrayArgumentNullTest ()
2038 //string [] data = { "2", "1", "5", "3", "4" };
2041 // ToArray<TSource> ()
2042 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToArray (); });
2046 public void ToArrayTest ()
2048 int [] data = { 2, 3, 4, 5 };
2049 int [] expected = { 2, 3, 4, 5 };
2052 // ToArray<TSource> ()
2053 AssertAreSame (expected, data.ToArray ());
2057 public void ToListArgumentNullTest ()
2059 //string [] data = { "2", "1", "5", "3", "4" };
2062 // ToList<string> ()
2063 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).ToList (); });
2067 public void ToListTest ()
2069 int [] data = { 2, 4, 5, 1 };
2070 int [] expected = { 2, 4, 5, 1 };
2074 AssertAreSame (expected, data.ToList ());
2078 public void ToDictionaryArgumentNullTest ()
2080 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
2103 public void ToDictionaryTest ()
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");
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"); });
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); });
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); });
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); });
2132 public void ToLookupArgumentNullTest ()
2134 string [] data = { "2", "1", "5", "3", "4" };
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); });
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); });
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); });
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); });
2157 public void ToLookupTest ()
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" });
2167 // ToLookup<string,string> (Func<string, string>)
2168 AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup ((x => x [0].ToString ())));
2170 // ToLookup<string,string> (Func<string, string>, IEqualityComparer<string>)
2171 AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), EqualityComparer<string>.Default));
2173 // ToLookup<string,string,string> (Func<string, string>, Func<string, string>)
2174 AssertAreSame (expected, ((IEnumerable<string>) data).ToLookup (x => x [0].ToString (), x => x));
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));
2181 public void DefaultIfEmptyArgumentNullTest ()
2183 //string [] data = { "2", "1", "5", "3", "4" };
2186 // DefaultIfEmpty<string> ()
2187 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> (); });
2189 // DefaultIfEmpty<string> (string)
2190 AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).DefaultIfEmpty<string> ((string) "default"); });
2194 public void DefaultIfEmptyTest ()
2196 string [] data = { "2", "1", "5", "3", "4" };
2197 string [] empty = { };
2198 string [] default1 = { null };
2199 string [] default2 = { "default" };
2202 // DefaultIfEmpty<string> ()
2203 AssertAreSame (data, data.DefaultIfEmpty ());
2204 AssertAreSame (default1, empty.DefaultIfEmpty ());
2206 // DefaultIfEmpty<string> (string)
2207 AssertAreSame (data, data.DefaultIfEmpty ("default"));
2208 AssertAreSame (default2, empty.DefaultIfEmpty ("default"));
2212 public void OfTypeArgumentNullTest ()
2214 //string [] data = { "2", "1", "5", "3", "4" };
2217 // OfType<string> ()
2218 AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).OfType<string> (); });
2222 public void OfTypeTest ()
2224 object [] data = { "2", 2, "1", "5", "3", "4" };
2225 string [] expected = { "2", "1", "5", "3", "4" };
2228 // OfType<string> ()
2229 AssertAreSame (expected, data.OfType<string> ());
2233 public void CastArgumentNullTest ()
2235 //string [] data = { "2", "1", "5", "3", "4" };
2239 AssertException<ArgumentNullException> (delegate () { ((IEnumerable) null).Cast<string> (); });
2243 public void CastTest ()
2245 object [] data = { 1, 2, 3 };
2246 int [] expected = { 1, 2, 3 };
2250 AssertAreSame (expected, data.Cast<int> ());
2251 AssertException<InvalidCastException> (delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); });
2252 data.Cast<IEnumerable> ();
2256 public void RangeArgumentNullTest ()
2258 //string [] data = { "2", "1", "5", "3", "4" };
2263 public void RangeTest ()
2265 int [] expected = { 2, 3, 4, 5 };
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);