New tests.
[mono.git] / mcs / class / System.Core / Test / System.Linq / ParallelEnumerableTests.cs
1 // ParallelEnumerableTests.cs
2 //
3 // Copyright (c) 2008 Jérémie "Garuma" Laval
4 //
5 // Based on Enumerable test suite by Jb Evain (jbevain@novell.com)
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 // THE SOFTWARE.
24 //
25 //
26
27 #if NET_4_0
28
29 using System;
30 using System.Threading;
31 using System.Linq;
32
33 using System.Collections;
34 using System.Collections.Generic;
35
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Linq
39 {
40         [TestFixtureAttribute]
41         public class ParallelEnumerableTests
42         {
43                 IEnumerable<int> baseEnumerable;
44                 
45                 [SetUpAttribute]
46                 public void Setup ()
47                 {
48                         baseEnumerable = Enumerable.Range(1, 10000);
49                 }
50                 
51                 void AreEquivalent (IEnumerable<int> syncEnumerable, IEnumerable<int> asyncEnumerable, int count)
52                 {
53                         int[] sync  = Enumerable.ToArray(syncEnumerable);
54                         int[] async = Enumerable.ToArray(asyncEnumerable);
55                         
56                         // This is not AreEquals because ParallelQuery is non-deterministic (IParallelOrderedEnumerable is)
57                         // thus the order of the initial Enumerable might not be preserved
58                         CollectionAssert.AreEquivalent(sync, async, "#" + count);
59                 }
60                 
61                 void AreEquivalent<T> (IEnumerable<T> syncEnumerable, IEnumerable<T> asyncEnumerable, int count)
62                 {
63                         T[] sync  = Enumerable.ToArray(syncEnumerable);
64                         T[] async = Enumerable.ToArray(asyncEnumerable);
65                         
66                         // This is not AreEquals because ParallelQuery is non-deterministic (IParallelOrderedEnumerable is)
67                         // thus the order of the initial Enumerable might not be preserved
68                         CollectionAssert.AreEquivalent(sync, async, "#" + count);
69                 }
70                 
71                 static void AssertAreSame<T> (IEnumerable<T> expected, IEnumerable<T> actual)
72                 {
73                         if (expected == null) {
74                                 Assert.IsNull (actual);
75                                 return;
76                         }
77
78                         Assert.IsNotNull (actual);
79
80                         IEnumerator<T> ee = expected.GetEnumerator ();
81                         IEnumerator<T> ea = actual.GetEnumerator ();
82
83                         while (ee.MoveNext ()) {
84                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
85                                 Assert.AreEqual (ee.Current, ea.Current);
86                         }
87
88                         if (ea.MoveNext ())
89                                 Assert.Fail ("Unexpected element: " + ea.Current);
90                 }
91                 
92                 public static void AssertException<T> (Action action) where T : Exception
93                 {
94                         try {
95                                 action ();
96                         }
97                         catch (T) {
98                                 return;
99                         }
100                         Assert.Fail ("Expected: " + typeof (T).Name);
101                 }
102
103                 static void AssertAreSame<K, V> (K expectedKey, IEnumerable<V> expectedValues, IGrouping<K, V> actual)
104                 {
105                         if (expectedValues == null) {
106                                 Assert.IsNull (actual);
107                                 return;
108                         }
109
110                         Assert.IsNotNull (actual);
111
112                         Assert.AreEqual (expectedKey, actual.Key);
113
114                         var ee = expectedValues.GetEnumerator ();
115                         var ea = actual.GetEnumerator ();
116
117                         while (ee.MoveNext ()) {
118                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current + "' expected.");
119                                 Assert.AreEqual (ee.Current, ea.Current);
120                         }
121
122                         if (ea.MoveNext ())
123                                 Assert.Fail ("Unexpected element: " + ee.Current);
124                 }
125
126                 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, IEnumerable<IGrouping<K, V>> actual)
127                 {
128                         if (expected == null) {
129                                 Assert.IsNull (actual);
130                                 return;
131                         }
132
133                         Assert.IsNotNull (actual);
134
135                         var ee = expected.GetEnumerator ();
136                         var ea = actual.GetEnumerator ();
137
138                         while (ee.MoveNext ()) {
139                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
140                                 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
141                         }
142
143                         if (ea.MoveNext ())
144                                 Assert.Fail ("Unexpected element: " + ee.Current.Key);
145                 }
146
147                 static void AssertAreSame<K, V> (IDictionary<K, IEnumerable<V>> expected, ILookup<K, V> actual)
148                 {
149                         if (expected == null) {
150                                 Assert.IsNull (actual);
151                                 return;
152                         }
153
154                         Assert.IsNotNull (actual);
155
156                         var ee = expected.GetEnumerator ();
157                         var ea = actual.GetEnumerator ();
158
159                         while (ee.MoveNext ()) {
160                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + "' expected.");
161                                 AssertAreSame (ee.Current.Key, ee.Current.Value, ea.Current);
162                         }
163
164                         if (ea.MoveNext ())
165                                 Assert.Fail ("Unexpected element: " + ee.Current.Key);
166                 }
167
168                 static void AssertAreSame<K, V> (IDictionary<K, V> expected, IDictionary<K, V> actual)
169                 {
170                         if (expected == null) {
171                                 Assert.IsNull (actual);
172                                 return;
173                         }
174
175                         Assert.IsNotNull (actual);
176
177                         var ee = expected.GetEnumerator ();
178                         var ea = actual.GetEnumerator ();
179
180                         while (ee.MoveNext ()) {
181                                 Assert.IsTrue (ea.MoveNext (), "'" + ee.Current.Key + ", " + ee.Current.Value + "' expected.");
182                                 Assert.AreEqual (ee.Current.Key, ea.Current.Key);
183                                 Assert.AreEqual (ee.Current.Value, ea.Current.Value);
184                         }
185
186                         if (ea.MoveNext ())
187                                 Assert.Fail ("Unexpected element: " + ee.Current.Key + ", " + ee.Current.Value);
188                 }
189
190                 [Test]
191                 public void SelectTestCase ()
192                 {
193                         ParallelTestHelper.Repeat (() => {
194                                 IEnumerable<int> sync  = baseEnumerable.Select (i => i * i);
195                                 IEnumerable<int> async = baseEnumerable.AsParallel ().Select (i => i * i);
196                                 
197                                 AreEquivalent(sync, async, 1);
198                         });
199                 }
200                         
201                 [Test]
202                 public void WhereTestCase ()
203                 {
204                         ParallelTestHelper.Repeat (() => {
205                                 IEnumerable<int> sync  = baseEnumerable.Where(i => i % 2 == 0);
206                                 IEnumerable<int> async = baseEnumerable.AsParallel().Where(i => i % 2 == 0);
207                                 
208                                 AreEquivalent(sync, async, 1);
209                         });
210                 }
211                 
212                 [Test]
213                 public void CountTestCase ()
214                 {
215                         ParallelTestHelper.Repeat (() => {
216                                 int sync  = baseEnumerable.Count();
217                                 int async = baseEnumerable.AsParallel().Count();
218                                 
219                                 Assert.AreEqual(sync, async, "#1");
220                         });
221                 }
222                 
223                 [Test]
224                 public void AggregateTestCase ()
225                 {
226                         ParallelTestHelper.Repeat (() => {
227                                 ParallelQuery<int> range = ParallelEnumerable.Repeat (5, 2643);
228                                 double average = range.Aggregate(() => new double[2],
229                                                                  (acc, elem) => { acc[0] += elem; acc[1]++; return acc; },
230                                 (acc1, acc2) => { acc1[0] += acc2[0]; acc1[1] += acc2[1]; return acc1; },
231                                 acc => acc[0] / acc[1]);
232                                 
233                                 Assert.AreEqual(5.0, average, "#1");
234                         });
235                 }
236                 
237                 [Test]
238                 public void TestSimpleExcept ()
239                 {
240                         ParallelTestHelper.Repeat (() => {
241                                 int [] first = {0, 1, 2, 3, 4, 5};
242                                 int [] second = {2, 4, 6};
243                                 int [] result = {0, 1, 3, 5};
244         
245                                 AreEquivalent (result, first.AsParallel ().Except (second.AsParallel ()), 1);
246                         });
247                 }
248
249                 [Test]
250                 public void TestSimpleIntersect ()
251                 {
252                         ParallelTestHelper.Repeat (() => {
253                                 int [] first = {0, 1, 2, 3, 4, 5};
254                                 int [] second = {2, 4, 6};
255                                 int [] result = {2, 4};
256         
257                                 AreEquivalent (result, first.AsParallel ().Intersect (second.AsParallel ()), 1);
258                         });
259                 }
260
261                 [Test]
262                 public void TestSimpleUnion ()
263                 {
264                         ParallelTestHelper.Repeat (() => {
265                                 int [] first = {0, 1, 2, 3, 4, 5};
266                                 int [] second = {2, 4, 6};
267                                 int [] result = {0, 1, 2, 3, 4, 5, 6};
268                                 
269                                 AreEquivalent (result, first.AsParallel ().Union (second.AsParallel ()), 1);
270                         });
271                 }
272                 
273                 class Foo {}
274                 class Bar : Foo {}
275
276                 [Test]
277                 public void TestCast ()
278                 {
279                         Bar a = new Bar ();
280                         Bar b = new Bar ();
281                         Bar c = new Bar ();
282
283                         Foo [] foos = new Foo [] {a, b, c};
284                         Bar [] result = new Bar [] {a, b, c};
285
286                         AreEquivalent (result, foos.AsParallel ().Cast<Bar> (), 1);
287                 }
288                 
289                 [Test]
290                 public void TestSkip ()
291                 {
292                         int [] data = {0, 1, 2, 3, 4, 5};
293                         int [] result = {3, 4, 5};
294
295                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Skip (3).ToArray ());
296                 }
297
298                 /*[Test]
299                 public void TestSkipWhile ()
300                 {
301                         int [] data = {0, 1, 2, 3, 4, 5};
302                         int [] result = {3, 4, 5};
303
304                         AssertAreSame (result, data.AsParallel ().AsOrdered ().SkipWhile (i => i < 3));
305                 }
306
307                 [Test]
308                 public void TestTake ()
309                 {
310                         int [] data = {0, 1, 2, 3, 4, 5};
311                         int [] result = {0, 1, 2};
312
313                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Take (3));
314                 }
315
316                 [Test]
317                 public void TestTakeWhile ()
318                 {
319                         int [] data = {0, 1, 2, 3, 4, 5};
320                         int [] result = {0, 1, 2};
321
322                         AssertAreSame (result, data.AsParallel ().AsOrdered ().TakeWhile (i => i < 3));
323                 }*/
324                 
325 //              [Test]
326 //              public void TestLast ()
327 //              {
328 //                      int [] data = {1, 2, 3};
329 //
330 //                      Assert.AreEqual (3, data.AsParallel ().Last ());
331 //              }
332 //
333 //              [Test]
334 //              public void TestLastOrDefault ()
335 //              {
336 //                      int [] data = {};
337 //
338 //                      Assert.AreEqual (default (int), data.AsParallel ().LastOrDefault ());
339 //              }
340 //
341 //              [Test]
342 //              public void TestFirst ()
343 //              {
344 //                      int [] data = {1, 2, 3};
345 //
346 //                      Assert.AreEqual (1, data.AsParallel ().First ());
347 //              }
348 //
349 //              [Test]
350 //              public void TestFirstOrDefault ()
351 //              {
352 //                      int [] data = {};
353 //
354 //                      Assert.AreEqual (default (int), data.AsParallel ().FirstOrDefault ());
355 //              }
356                 
357                 [Test]
358                 public void TestReverse ()
359                 {
360                         int [] data = {0, 1, 2, 3, 4};
361                         int [] result = {4, 3, 2, 1, 0};
362
363                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Reverse ());
364                         AssertAreSame (result, ParallelEnumerable.Range (0, 5).AsOrdered ().Reverse ());
365                 }
366                 
367                 [Test]
368                 public void TestOrderBy ()
369                 {
370                         ParallelTestHelper.Repeat (() => {
371                                 int [] array = { 14, 53, 3, 9, 11, 14, 5, 32, 2 };
372                                 
373                                 var q = array.AsParallel ().OrderBy ((i) => i);
374                                 AssertIsOrdered (q, array.Length);
375                         });
376                 }
377
378                 class Baz {
379                         string name;
380                         int age;
381
382                         public string Name
383                         {
384                                 get {
385                                         if (string.IsNullOrEmpty (name))
386                                                 return Age.ToString ();
387
388                                         return name + " (" + Age + ")";
389                                 }
390                         }
391
392                         public int Age
393                         {
394                                 get { return age + 1; }
395                         }
396
397                         public Baz (string name, int age)
398                         {
399                                 this.name = name;
400                                 this.age = age;
401                         }
402
403                         public override int GetHashCode ()
404                         {
405                                 return this.Age ^ this.Name.GetHashCode ();
406                         }
407
408                         public override bool Equals (object obj)
409                         {
410                                 Baz b = obj as Baz;
411                                 if (b == null)
412                                         return false;
413
414                                 return b.Age == this.Age && b.Name == this.Name;
415                         }
416
417                         public override string ToString ()
418                         {
419                                 return this.Name;
420                         }
421                 }
422
423                 static IEnumerable<Baz> CreateBazCollection ()
424                 {
425                         return new [] {
426                                 new Baz ("jb", 25),
427                                 new Baz ("ana", 20),
428                                 new Baz ("reg", 28),
429                                 new Baz ("ro", 25),
430                                 new Baz ("jb", 7),
431                         };
432                 }
433
434                 [Test]
435                 public void TestOrderByAgeAscendingTheByNameDescending ()
436                 {
437                         ParallelTestHelper.Repeat (() => {
438                                 var q = from b in CreateBazCollection ().AsParallel()
439                                                 orderby b.Age ascending, b.Name descending
440                                                 select b;
441                                 //var q = CreateBazCollection ().AsParallel ().OrderBy ((b) => b.Age).ThenByDescending ((b) => b.Name);
442         
443                                 var expected = new [] {
444                                         new Baz ("jb", 7),
445                                         new Baz ("ana", 20),
446                                         new Baz ("ro", 25),
447                                         new Baz ("jb", 25),
448                                         new Baz ("reg", 28),
449                                 };
450                                 
451                                 foreach (Baz b in q) {
452                                         Console.Write(b.Name + ", " + b.Age + "; ");
453                                 }
454         
455                                 AssertAreSame (expected, q);
456                         });
457                 }
458
459                 class Data {
460                         public int ID { get; set; }
461                         public string Name { get; set; }
462
463                         public override string ToString ()
464                         {
465                                 return ID + " " + Name;
466                         }
467                 }
468
469                 IEnumerable<Data> CreateData ()
470                 {
471                         return new [] {
472                                 new Data { ID = 10, Name = "bcd" },
473                                 new Data { ID = 20, Name = "Abcd" },
474                                 new Data { ID = 20, Name = "Ab" },
475                                 new Data { ID = 10, Name = "Zyx" },
476                         };
477                 }
478
479                 [Test]
480                 public void TestOrderByIdDescendingThenByNameAscending ()
481                 {
482                         ParallelTestHelper.Repeat (() => {
483                                 var q = from d in CreateData ().AsParallel()
484                                         orderby d.ID descending, d.Name ascending
485                                                 select d;
486                                 
487                                 var list = new List<Data> (q);
488                                 
489                                 Assert.AreEqual ("Ab", list [0].Name);
490                                 Assert.AreEqual ("Abcd", list [1].Name);
491                                 Assert.AreEqual ("bcd", list [2].Name);
492                                 Assert.AreEqual ("Zyx", list [3].Name);
493                         });
494                 }
495
496                 static void AssertIsOrdered (IEnumerable<int> e, int count)
497                 {
498                         int f = int.MinValue;
499                         int c = 0;
500                         
501                         foreach (int i in e) {
502                                 Assert.IsTrue (f <= i, string.Format ("{0} <= {1}", f, i));
503                                 f = i;
504                                 c++;
505                         }
506                         
507                         Assert.AreEqual (count, c);
508                 }
509                 
510                 /*
511                 [TestAttribute, Ignore]
512                 public void ElementAtTestCase()
513                 {
514                         ParallelTestHelper.Repeat (() => {
515                                 Assert.AreEqual(1, baseEnumerable.ElementAt(0), "#1");
516                                 Assert.AreEqual(51, baseEnumerable.ElementAt(50), "#2");
517                                 Assert.AreEqual(489, baseEnumerable.ElementAt(488), "#3");
518                         });
519                 }
520                 
521                 [TestAttribute, Ignore]
522                 public void TakeTestCase()
523                 {
524                         ParallelTestHelper.Repeat (() => {
525                                 ParallelQuery<int> async = baseEnumerable.AsParallel().Take(2000);
526                                 IEnumerable<int> sync = baseEnumerable.Take(2000);
527                                 
528                                 AreEquivalent(sync, async, 1);
529                                 
530                                 async = baseEnumerable.AsParallel().Take(100);
531                                 sync = baseEnumerable.Take(100);
532                         
533                                 AreEquivalent(sync, async, 2);
534                         });
535                 }
536                 
537                 [TestAttribute, Ignore]
538                 public void SkipTestCase()
539                 {
540                         ParallelTestHelper.Repeat (() => {
541                                 ParallelQuery<int> async = baseEnumerable.AsParallel().AsOrdered().Skip(2000);
542                                 IEnumerable<int> sync = baseEnumerable.Skip(2000);
543                                 
544                                 AreEquivalent(sync, async, 1);
545                                 
546                                 async = baseEnumerable.AsParallel().Skip(100);
547                                 sync = baseEnumerable.Skip(100);
548                                 
549                                 Assert.AreEqual(sync.Count(), async.Count(), "#2");
550                         });
551                 }
552
553                 [TestAttribute, Ignore]
554                 public void ZipTestCase()
555                 {
556                         ParallelTestHelper.Repeat (() => {
557                                 ParallelQuery<int> async1 = ParallelEnumerable.Range(0, 10000);
558                                 ParallelQuery<int> async2 = ParallelEnumerable.Repeat(1, 10000).Zip(async1, (e1, e2) => e1 + e2);
559                                 
560                                 int[] expected = Enumerable.Range (1, 10000).ToArray ();
561                                 CollectionAssert.AreEquivalent(expected, Enumerable.ToArray (async2), "#1");
562                         });
563                 }
564                 */
565                 [Test]
566                 public void RangeTestCase ()
567                 {
568                         ParallelTestHelper.Repeat (() => {
569                                 IEnumerable<int> sync  = Enumerable.Range(1, 1000);
570                                 IEnumerable<int> async = ParallelEnumerable.Range(1, 1000);
571                                 
572                                 AreEquivalent (sync, async, 1);
573                         });
574                 }
575                 
576                 [Test]
577                 public void RepeatTestCase ()
578                 {
579                         ParallelTestHelper.Repeat (() => {
580                                 IEnumerable<int> sync  = Enumerable.Repeat(1, 1000);
581                                 IEnumerable<int> async = ParallelEnumerable.Repeat(1, 1000);
582                                 
583                                 AreEquivalent (sync, async, 1);
584                         });
585                 }
586                 
587                 [Test]
588                 public void TestSum ()
589                 {
590                         int [] data = {1, 2, 3, 4};
591
592                         Assert.AreEqual (10, data.AsParallel().Sum ());
593                 }
594
595                 [Test]
596                 public void SumOnEmpty ()
597                 {
598                         int [] data = {};
599
600                         Assert.AreEqual (0, data.AsParallel().Sum ());
601                 }
602
603                 [Test]
604                 public void TestMax ()
605                 {
606                         int [] data = {1, 3, 5, 2};
607
608                         Assert.AreEqual (5, data.AsParallel().Max ());
609                 }
610
611                 [Test]
612                 public void TestMin ()
613                 {
614                         int [] data = {3, 5, 2, 6, 1, 7};
615
616                         Assert.AreEqual (1, data.AsParallel().Min ());
617                 }
618                 
619                 [Test]
620                 public void TestToListOrdered ()
621                 {
622                         int [] data = { 2, 3, 5 };
623
624                         var list = data.AsParallel().AsOrdered().ToList ();
625
626                         AssertAreSame (data, list);
627                         AssertIsOrdered (list, data.Length);
628
629                         Assert.AreEqual (typeof (List<int>), list.GetType ());
630                 }
631
632                 [Test]
633                 public void TestToArrayOrdered ()
634                 {
635                         ICollection<int> coll = new List<int> ();
636                         coll.Add (0);
637                         coll.Add (1);
638                         coll.Add (2);
639
640                         int [] result = {0, 1, 2};
641
642                         var array = coll.AsParallel().AsOrdered().ToArray ();
643
644                         AssertAreSame (result, array);
645                         AssertIsOrdered (array, result.Length);
646
647                         Assert.AreEqual (typeof (int []), array.GetType ());
648                 }
649
650                 [Test]
651                 public void TestToList ()
652                 {
653                         int [] data = {3, 5, 2};
654
655                         var list = data.AsParallel().ToList ();
656
657                         CollectionAssert.AreEquivalent (data, list);
658
659                         Assert.AreEqual (typeof (List<int>), list.GetType ());
660                 }
661
662                 [Test]
663                 public void TestToArray ()
664                 {
665                         ICollection<int> coll = new List<int> ();
666                         coll.Add (0);
667                         coll.Add (1);
668                         coll.Add (2);
669
670                         int [] result = {0, 1, 2};
671
672                         var array = coll.AsParallel().ToArray ();
673
674                         CollectionAssert.AreEquivalent (result, array);
675
676                         Assert.AreEqual (typeof (int []), array.GetType ());
677                 }
678                 
679                 
680                 [Test]
681                 public void TestAverageOnInt32 ()
682                 {
683                         Assert.AreEqual (23.25, (new int [] { 24, 7, 28, 34 }).Average ());
684                 }
685
686                 [Test]
687                 public void TestAverageOnInt64 ()
688                 {
689                         Assert.AreEqual (23.25, (new long [] { 24, 7, 28, 34 }).Average ());
690                 }
691                 
692                 /*
693                 [Test]
694                 public void AnyArgumentNullTest ()
695                 {
696                         string [] data = { "2", "1", "5", "3", "4" };
697
698
699                         // Any<TSource> ()
700                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().Any (); });
701
702                         // Any<TSource> (Func<TSource, bool>)
703                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().Any (x => true); });
704                         AssertException<ArgumentNullException> (delegate () { data.AsParallel ().Any ((Func<string, bool>) null); });
705                 }*/
706
707                 [Test]
708                 public void AnyTest ()
709                 {
710                         int [] data = { 5, 2, 3, 1, 6 };
711                         int [] empty = { };
712
713
714                         // Any<TSource> ()
715                         Assert.IsTrue (data.AsParallel ().Any ());
716                         Assert.IsFalse (empty.AsParallel ().Any ());
717
718                         // Any<TSource> (Func<TSource, bool>)
719                         Assert.IsTrue (data.AsParallel ().Any (x => x == 5));
720                         Assert.IsFalse (data.AsParallel ().Any (x => x == 9));
721                         Assert.IsFalse (empty.AsParallel ().Any (x => true));
722                 }
723
724                 /*
725                 [Test]
726                 public void AllArgumentNullTest ()
727                 {
728                         string [] data = { "2", "1", "5", "3", "4" };
729
730                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().All (x => true); });
731                         AssertException<ArgumentNullException> (delegate () { data.AsParallel ().All ((Func<string, bool>) null); });
732                 }*/
733
734                 [Test]
735                 public void AllTest ()
736                 {
737                         int [] data = { 5, 2, 3, 1, 6 };
738                         int [] empty = { };
739
740                         Assert.IsTrue (data.AsParallel ().All (x => true));
741                         Assert.IsFalse (data.AsParallel ().All (x => x != 1));
742                         Assert.IsTrue (empty.AsParallel ().All (x => false));
743                 }
744         }
745 }
746
747 #endif