Normalize line endings.
[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 TestSkipIterating ()
300                 {
301                         int [] data = {0, 1, 2, 3, 4, 5};
302                         int [] result = {3, 4, 5};
303
304                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Skip (3));
305                 }
306
307                 [Test, Ignore]
308                 public void TestSkipWhile ()
309                 {
310                         int [] data = {0, 1, 2, 3, 4, 5};
311                         int [] result = {3, 4, 5};
312
313                         AssertAreSame (result, data.AsParallel ().AsOrdered ().SkipWhile (i => i < 3));
314                 }
315
316                 [Test, Ignore]
317                 public void TestTake ()
318                 {
319                         int [] data = {0, 1, 2, 3, 4, 5};
320                         int [] result = {0, 1, 2};
321
322                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Take (3));
323                 }
324
325                 [Test, Ignore]
326                 public void TestTakeWhile ()
327                 {
328                         int [] data = {0, 1, 2, 3, 4, 5};
329                         int [] result = {0, 1, 2};
330
331                         AssertAreSame (result, data.AsParallel ().AsOrdered ().TakeWhile (i => i < 3));
332                 }
333                 
334                 [Test, Ignore]
335                 public void TestLast ()
336                 {
337                         int [] data = {1, 2, 3};
338
339                         Assert.AreEqual (3, data.AsParallel ().Last ());
340                 }
341
342                 [Test, Ignore]
343                 public void TestLastOrDefault ()
344                 {
345                         int [] data = {};
346
347                         Assert.AreEqual (default (int), data.AsParallel ().LastOrDefault ());
348                 }
349
350                 [Test, Ignore]
351                 public void TestFirst ()
352                 {
353                         int [] data = {1, 2, 3};
354
355                         Assert.AreEqual (1, data.AsParallel ().First ());
356                 }
357
358                 [Test, Ignore]
359                 public void TestFirstOrDefault ()
360                 {
361                         int [] data = {};
362
363                         Assert.AreEqual (default (int), data.AsParallel ().FirstOrDefault ());
364                 }
365                 
366                 [Test]
367                 public void TestReverse ()
368                 {
369                         int [] data = {0, 1, 2, 3, 4};
370                         int [] result = {4, 3, 2, 1, 0};
371
372                         AssertAreSame (result, data.AsParallel ().AsOrdered ().Reverse ());
373                         AssertAreSame (result, ParallelEnumerable.Range (0, 5).AsOrdered ().Reverse ());
374                 }
375                 
376                 [Test]
377                 public void TestOrderBy ()
378                 {
379                         ParallelTestHelper.Repeat (() => {
380                                 int [] array = { 14, 53, 3, 9, 11, 14, 5, 32, 2 };
381                                 
382                                 var q = array.AsParallel ().OrderBy ((i) => i);
383                                 AssertIsOrdered (q, array.Length);
384                         });
385                 }
386
387                 class Baz {
388                         string name;
389                         int age;
390
391                         public string Name
392                         {
393                                 get {
394                                         if (string.IsNullOrEmpty (name))
395                                                 return Age.ToString ();
396
397                                         return name + " (" + Age + ")";
398                                 }
399                         }
400
401                         public int Age
402                         {
403                                 get { return age + 1; }
404                         }
405
406                         public Baz (string name, int age)
407                         {
408                                 this.name = name;
409                                 this.age = age;
410                         }
411
412                         public override int GetHashCode ()
413                         {
414                                 return this.Age ^ this.Name.GetHashCode ();
415                         }
416
417                         public override bool Equals (object obj)
418                         {
419                                 Baz b = obj as Baz;
420                                 if (b == null)
421                                         return false;
422
423                                 return b.Age == this.Age && b.Name == this.Name;
424                         }
425
426                         public override string ToString ()
427                         {
428                                 return this.Name;
429                         }
430                 }
431
432                 static IEnumerable<Baz> CreateBazCollection ()
433                 {
434                         return new [] {
435                                 new Baz ("jb", 25),
436                                 new Baz ("ana", 20),
437                                 new Baz ("reg", 28),
438                                 new Baz ("ro", 25),
439                                 new Baz ("jb", 7),
440                         };
441                 }
442
443                 [Test]
444                 public void TestOrderByAgeAscendingTheByNameDescending ()
445                 {
446                         ParallelTestHelper.Repeat (() => {
447                                 var q = from b in CreateBazCollection ().AsParallel()
448                                                 orderby b.Age ascending, b.Name descending
449                                                 select b;
450                                 //var q = CreateBazCollection ().AsParallel ().OrderBy ((b) => b.Age).ThenByDescending ((b) => b.Name);
451         
452                                 var expected = new [] {
453                                         new Baz ("jb", 7),
454                                         new Baz ("ana", 20),
455                                         new Baz ("ro", 25),
456                                         new Baz ("jb", 25),
457                                         new Baz ("reg", 28),
458                                 };
459                                 
460                                 foreach (Baz b in q) {
461                                         Console.Write(b.Name + ", " + b.Age + "; ");
462                                 }
463         
464                                 AssertAreSame (expected, q);
465                         });
466                 }
467
468                 class Data {
469                         public int ID { get; set; }
470                         public string Name { get; set; }
471
472                         public override string ToString ()
473                         {
474                                 return ID + " " + Name;
475                         }
476                 }
477
478                 IEnumerable<Data> CreateData ()
479                 {
480                         return new [] {
481                                 new Data { ID = 10, Name = "bcd" },
482                                 new Data { ID = 20, Name = "Abcd" },
483                                 new Data { ID = 20, Name = "Ab" },
484                                 new Data { ID = 10, Name = "Zyx" },
485                         };
486                 }
487
488                 [Test]
489                 public void TestOrderByIdDescendingThenByNameAscending ()
490                 {
491                         ParallelTestHelper.Repeat (() => {
492                                 var q = from d in CreateData ().AsParallel()
493                                         orderby d.ID descending, d.Name ascending
494                                                 select d;
495                                 
496                                 var list = new List<Data> (q);
497                                 
498                                 Assert.AreEqual ("Ab", list [0].Name);
499                                 Assert.AreEqual ("Abcd", list [1].Name);
500                                 Assert.AreEqual ("bcd", list [2].Name);
501                                 Assert.AreEqual ("Zyx", list [3].Name);
502                         });
503                 }
504
505                 static void AssertIsOrdered (IEnumerable<int> e, int count)
506                 {
507                         int f = int.MinValue;
508                         int c = 0;
509                         
510                         foreach (int i in e) {
511                                 Assert.IsTrue (f <= i, string.Format ("{0} <= {1}", f, i));
512                                 f = i;
513                                 c++;
514                         }
515                         
516                         Assert.AreEqual (count, c);
517                 }
518                 
519                 
520                 [TestAttribute, Ignore]
521                 public void ElementAtTestCase()
522                 {
523                         ParallelTestHelper.Repeat (() => {
524                                 Assert.AreEqual(1, baseEnumerable.ElementAt(0), "#1");
525                                 Assert.AreEqual(51, baseEnumerable.ElementAt(50), "#2");
526                                 Assert.AreEqual(489, baseEnumerable.ElementAt(488), "#3");
527                         });
528                 }
529                 
530                 [TestAttribute, Ignore]
531                 public void TakeTestCase()
532                 {
533                         ParallelTestHelper.Repeat (() => {
534                                 ParallelQuery<int> async = baseEnumerable.AsParallel().Take(2000);
535                                 IEnumerable<int> sync = baseEnumerable.Take(2000);
536                                 
537                                 AreEquivalent(sync, async, 1);
538                                 
539                                 async = baseEnumerable.AsParallel().Take(100);
540                                 sync = baseEnumerable.Take(100);
541                         
542                                 AreEquivalent(sync, async, 2);
543                         }, 20);
544                 }
545                 
546                 [Test]
547                 public void SkipTestCase()
548                 {
549                         ParallelTestHelper.Repeat (() => {
550                                 ParallelQuery<int> async = baseEnumerable.AsParallel().AsOrdered().Skip(2000);
551                                 IEnumerable<int> sync = baseEnumerable.Skip(2000);
552                                 
553                                 AreEquivalent(sync, async, 1);
554                                 
555                                 async = baseEnumerable.AsParallel().Skip(100);
556                                 sync = baseEnumerable.Skip(100);
557                                 
558                                 Assert.AreEqual(sync.Count(), async.Count(), "#2");
559                         }, 20);
560                 }
561
562                 [Test]
563                 public void ZipTestCase()
564                 {
565                         ParallelTestHelper.Repeat (() => {
566                                 ParallelQuery<int> async1 = ParallelEnumerable.Range(0, 10000);
567                                 ParallelQuery<int> async2 = ParallelEnumerable.Repeat(1, 10000).Zip(async1, (e1, e2) => e1 + e2);
568                                 
569                                 int[] expected = Enumerable.Range (1, 10000).ToArray ();
570                                 CollectionAssert.AreEquivalent(expected, Enumerable.ToArray (async2), "#1");
571                         });
572                 }
573                 
574                 [Test]
575                 public void RangeTestCase ()
576                 {
577                         ParallelTestHelper.Repeat (() => {
578                                 IEnumerable<int> sync  = Enumerable.Range(1, 1000);
579                                 IEnumerable<int> async = ParallelEnumerable.Range(1, 1000);
580                                 
581                                 AreEquivalent (sync, async, 1);
582                         });
583                 }
584                 
585                 [Test]
586                 public void RepeatTestCase ()
587                 {
588                         ParallelTestHelper.Repeat (() => {
589                                 IEnumerable<int> sync  = Enumerable.Repeat(1, 1000);
590                                 IEnumerable<int> async = ParallelEnumerable.Repeat(1, 1000);
591                                 
592                                 AreEquivalent (sync, async, 1);
593                         });
594                 }
595                 
596                 [Test]
597                 public void TestSum ()
598                 {
599                         int [] data = {1, 2, 3, 4};
600
601                         Assert.AreEqual (10, data.AsParallel().Sum ());
602                 }
603
604                 [Test]
605                 public void SumOnEmpty ()
606                 {
607                         int [] data = {};
608
609                         Assert.AreEqual (0, data.AsParallel().Sum ());
610                 }
611
612                 [Test]
613                 public void TestMax ()
614                 {
615                         int [] data = {1, 3, 5, 2};
616
617                         Assert.AreEqual (5, data.AsParallel().Max ());
618                 }
619
620                 [Test]
621                 public void TestMin ()
622                 {
623                         int [] data = {3, 5, 2, 6, 1, 7};
624
625                         Assert.AreEqual (1, data.AsParallel().Min ());
626                 }
627                 
628                 [Test]
629                 public void TestToListOrdered ()
630                 {
631                         int [] data = { 2, 3, 5 };
632
633                         var list = data.AsParallel().AsOrdered().ToList ();
634
635                         AssertAreSame (data, list);
636                         AssertIsOrdered (list, data.Length);
637
638                         Assert.AreEqual (typeof (List<int>), list.GetType ());
639                 }
640
641                 [Test]
642                 public void TestToArrayOrdered ()
643                 {
644                         ICollection<int> coll = new List<int> ();
645                         coll.Add (0);
646                         coll.Add (1);
647                         coll.Add (2);
648
649                         int [] result = {0, 1, 2};
650
651                         var array = coll.AsParallel().AsOrdered().ToArray ();
652
653                         AssertAreSame (result, array);
654                         AssertIsOrdered (array, result.Length);
655
656                         Assert.AreEqual (typeof (int []), array.GetType ());
657                 }
658
659                 [Test]
660                 public void TestToList ()
661                 {
662                         int [] data = {3, 5, 2};
663
664                         var list = data.AsParallel().ToList ();
665
666                         CollectionAssert.AreEquivalent (data, list);
667
668                         Assert.AreEqual (typeof (List<int>), list.GetType ());
669                 }
670
671                 [Test]
672                 public void TestToArray ()
673                 {
674                         ICollection<int> coll = new List<int> ();
675                         coll.Add (0);
676                         coll.Add (1);
677                         coll.Add (2);
678
679                         int [] result = {0, 1, 2};
680
681                         var array = coll.AsParallel().ToArray ();
682
683                         CollectionAssert.AreEquivalent (result, array);
684
685                         Assert.AreEqual (typeof (int []), array.GetType ());
686                 }
687                 
688                 
689                 [Test]
690                 public void TestAverageOnInt32 ()
691                 {
692                         Assert.AreEqual (23.25, (new int [] { 24, 7, 28, 34 }).Average ());
693                 }
694
695                 [Test]
696                 public void TestAverageOnInt64 ()
697                 {
698                         Assert.AreEqual (23.25, (new long [] { 24, 7, 28, 34 }).Average ());
699                 }
700                 
701                 
702                 [Test]
703                 public void AnyArgumentNullTest ()
704                 {
705                         string [] data = { "2", "1", "5", "3", "4" };
706
707
708                         // Any<TSource> ()
709                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().Any (); });
710
711                         // Any<TSource> (Func<TSource, bool>)
712                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().Any (x => true); });
713                         AssertException<ArgumentNullException> (delegate () { data.AsParallel ().Any ((Func<string, bool>) null); });
714                 }
715
716                 [Test]
717                 public void AnyTest ()
718                 {
719                         int [] data = { 5, 2, 3, 1, 6 };
720                         int [] empty = { };
721
722
723                         // Any<TSource> ()
724                         Assert.IsTrue (data.AsParallel ().Any ());
725                         Assert.IsFalse (empty.AsParallel ().Any ());
726
727                         // Any<TSource> (Func<TSource, bool>)
728                         Assert.IsTrue (data.AsParallel ().Any (x => x == 5));
729                         Assert.IsFalse (data.AsParallel ().Any (x => x == 9));
730                         Assert.IsFalse (empty.AsParallel ().Any (x => true));
731                 }
732
733                 
734                 [Test]
735                 public void AllArgumentNullTest ()
736                 {
737                         string [] data = { "2", "1", "5", "3", "4" };
738
739                         AssertException<ArgumentNullException> (delegate () { ((IEnumerable<string>) null).AsParallel ().All (x => true); });
740                         AssertException<ArgumentNullException> (delegate () { data.AsParallel ().All ((Func<string, bool>) null); });
741                 }
742
743                 [Test]
744                 public void AllTest ()
745                 {
746                         int [] data = { 5, 2, 3, 1, 6 };
747                         int [] empty = { };
748
749                         Assert.IsTrue (data.AsParallel ().All (x => true));
750                         Assert.IsFalse (data.AsParallel ().All (x => x != 1));
751                         Assert.IsTrue (empty.AsParallel ().All (x => false));
752                 }
753         }
754 }
755
756 #endif