New tests.
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
2 //
3 // David Brandt (bucky@keystreams.com)
4 // Eduardo Garcia (kiwnix@yahoo.es)
5 // 
6 // (C) Ximian, Inc.  http://www.ximian.com
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.Globalization;
14
15 #if NET_2_0
16 using System.Collections.Generic;
17 #endif
18
19 namespace MonoTests.System
20 {
21         //Auxiliary Things
22         enum enua  {hola,adios,mas,menos};
23
24         class AClass
25         {
26                 public AClass()
27                 {
28
29                 }
30         }
31
32         class BClass : AClass
33         {
34         }
35
36         class CClass : AClass
37         {
38         }
39
40         struct AStruct
41         {
42                 public string s;
43                 public string a;
44         }
45         
46         class DataEqual
47         {
48                 public override bool Equals (object obj)
49                 {
50                         return true;
51                 }
52
53                 public override int GetHashCode ()
54                 {
55                         return 0;
56                 }
57         }
58                 
59         //End Auxiliary Things
60
61 [TestFixture]
62 public class ArrayTest
63 {
64         char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
65
66         public ArrayTest() {}
67
68         [Test]
69         public void TestIsFixedSize() {
70                 char[] a1 = {'a'};
71                 Assert.IsTrue (a1.IsFixedSize, "All arrays are fixed");
72         }
73         
74         [Test]
75         public void TestIsReadOnly() {
76                 char[] a1 = {'a'};
77                 Assert.IsTrue (!a1.IsReadOnly, "No array is readonly");
78         }
79
80         [Test]
81         public void TestIsSynchronized() {
82                 char[] a1 = {'a'};
83                 Assert.IsTrue (!a1.IsSynchronized, "No array is synchronized");
84         }
85
86         [Test]
87         public void TestLength() {
88                 {
89                         char[] a1 = { };
90                         Assert.AreEqual (0, a1.Length, "Zero length array");
91                 }
92                 {
93                         char[] a1 = {'c'};
94                         Assert.AreEqual (1, a1.Length, "One-length array");
95                 }
96                 {
97                         char[] a1 = {'c', 'c'};
98                         Assert.AreEqual (2, a1.Length, "Two-length array");
99                 }
100         }
101
102         [Test]
103         public void TestRank() {
104                 char[] a1 = { 'c', 'd', 'e' };
105                 Assert.AreEqual (1, a1.Rank, "Rank one");
106
107                 char[,] a2 = new Char[3,3];
108                 Assert.AreEqual (2, a2.Rank, "Rank two");
109
110                 char[,,] a3 = new Char[3,3,3];
111                 Assert.AreEqual (3, a3.Rank, "Rank three");
112         }
113
114         [Test]
115         public void TestBinarySearch1() {
116                 bool errorThrown = false;
117                 try {
118                         Array.BinarySearch(null, "blue");
119                 } catch (ArgumentNullException) {
120                         errorThrown = true;
121                 }
122                 Assert.IsTrue (errorThrown, "#B01");
123                 errorThrown = false;
124                 try {
125                         char[,] c1 = new Char[2,2];
126                         Array.BinarySearch(c1, "needle");
127                 } catch (RankException) {
128                         errorThrown = true;
129                 }
130                 Assert.IsTrue (errorThrown, "#B02");
131
132                 {
133                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
134                         Assert.IsTrue (Array.BinarySearch(arr, 'c') >= 3, "#B05");
135                         Assert.IsTrue (Array.BinarySearch(arr, 'c') < 6, "#B06");
136                 }
137                 {
138                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
139                         Assert.AreEqual (-4, Array.BinarySearch(arr, 'c'), "#B07");
140                 }
141                 {
142                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
143                         Assert.AreEqual (-9, Array.BinarySearch(arr, 'e'), "#B08");
144                 }
145         }
146
147         [Test]
148         public void TestBinarySearch2() {
149                 bool errorThrown = false;
150                 try {
151                         Array.BinarySearch(null, 0, 1, "blue");
152                 } catch (ArgumentNullException) {
153                         errorThrown = true;
154                 }
155                 Assert.IsTrue (errorThrown, "#B20");
156                 errorThrown = false;
157                 try {
158                         char[,] c1 = new Char[2,2];
159                         Array.BinarySearch(c1, 0, 1, "needle");
160                 } catch (RankException) {
161                         errorThrown = true;
162                 }
163                 Assert.IsTrue (errorThrown, "#B21");
164                 errorThrown = false;
165                 try {
166                         char[] c1 = {'a'};
167                         Array.BinarySearch(c1, -1, 1, 'a');
168                 } catch (ArgumentOutOfRangeException) {
169                         errorThrown = true;
170                 }
171                 Assert.IsTrue (errorThrown, "#B22");
172                 errorThrown = false;
173                 try {
174                         char[] c1 = {'a'};
175                         Array.BinarySearch(c1, 0, -1, 'a');
176                 } catch (ArgumentOutOfRangeException) {
177                         errorThrown = true;
178                 }
179                 Assert.IsTrue (errorThrown, "#B23");
180                 errorThrown = false;
181                 try {
182                         char[] c1 = {'a'};
183                         Array.BinarySearch(c1, 0, 4, 'a');
184                 } catch (ArgumentException) {
185                         errorThrown = true;
186                 }
187                 Assert.IsTrue (errorThrown, "#B24");
188
189                 {
190                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
191                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') >= 5, "#B26");
192                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') < 8, "#B27");
193                 }
194                 {
195                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
196                         Assert.AreEqual (-6, Array.BinarySearch(arr, 2, 8, 'c'), "#B28");
197                 }
198                 {
199                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
200                         Assert.AreEqual (-11, Array.BinarySearch(arr, 2, 8, 'e'), "#B29");
201                 }
202         }
203
204         public void TestBinarySearch3()
205         {
206                 int[] array = new int[100];
207
208                 for (int i = 0; i < 100; i++)
209                         array[i] = 10;
210
211                 Assert.AreEqual (49, Array.BinarySearch(array, 10), "#B30");
212         }
213
214         [Test]
215         public void BinarySearch_NullValue () 
216         {
217                 int[] array = new int[1];
218                 Assert.AreEqual (-1, Array.BinarySearch (array, null), "I=a,o");
219                 Assert.AreEqual (-1, Array.BinarySearch (array, null, null), "I=a,o,c");
220                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null), "I=a,i,i,o");
221                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null, null), "I=a,i,i,o,c");
222
223                 object[] o = new object [3] { this, this, null };
224                 Assert.AreEqual (-1, Array.BinarySearch (o, null), "O=a,o");
225                 Assert.AreEqual (-1, Array.BinarySearch (o, null, null), "O=a,o,c");
226                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null), "O=a,i,i,o");
227                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null, null), "O=a,i,i,o,c");
228         }
229
230         // TODO - testBinarySearch with explicit IComparer args
231
232         [Test]
233         public void TestClear() {
234                 bool errorThrown = false;
235                 try {
236                         Array.Clear(null, 0, 1);
237                 } catch (ArgumentNullException) {
238                         errorThrown = true;
239                 }
240                 Assert.IsTrue (errorThrown, "#C01");
241
242                 int[] i1 = { 1, 2, 3, 4 };
243                 {
244                         int[] compare = {1,2,3,4};
245                         Assert.AreEqual (compare[0], i1[0], "#C02");
246                         Assert.AreEqual (compare[1], i1[1], "#C03");
247                         Assert.AreEqual (compare[2], i1[2], "#C04");
248                         Assert.AreEqual (compare[3], i1[3], "#C05");
249                 }
250                 Array.Clear(i1, 3, 1);
251                 {
252                         int[] compare = {1,2,3,0};
253                         Assert.AreEqual (compare[0], i1[0], "#C06");
254                         Assert.AreEqual (compare[1], i1[1], "#C07");
255                         Assert.AreEqual (compare[2], i1[2], "#C08");
256                         Assert.AreEqual (compare[3], i1[3], "#C09");
257                 }
258                 Array.Clear(i1, 1, 1);
259                 {
260                         int[] compare = {1,0,3,0};
261                         Assert.AreEqual (compare[0], i1[0], "#C10");
262                         Assert.AreEqual (compare[1], i1[1], "#C11");
263                         Assert.AreEqual (compare[2], i1[2], "#C12");
264                         Assert.AreEqual (compare[3], i1[3], "#C13");
265                 }
266                 Array.Clear(i1, 1, 3);
267                 {
268                         int[] compare = {1,0,0,0};
269                         Assert.AreEqual (compare[0], i1[0], "#C14");
270                         Assert.AreEqual (compare[1], i1[1], "#C15");
271                         Assert.AreEqual (compare[2], i1[2], "#C16");
272                         Assert.AreEqual (compare[3], i1[3], "#C17");
273                 }
274
275                 string[] s1 = { "red", "green", "blue" };
276                 Array.Clear(s1, 0, 3);
277                 {
278                         string[] compare = {null, null, null};
279                         Assert.AreEqual (compare[0], s1[0], "#C18");
280                         Assert.AreEqual (compare[1], s1[1], "#C19");
281                         Assert.AreEqual (compare[2], s1[2], "#C20");
282                 }
283         }
284
285         [Test]
286         public void TestClone() {
287                 char[] c1 = {'a', 'b', 'c'};
288                 char[] c2 = (char[])c1.Clone();
289                 Assert.AreEqual (c1[0], c2[0], "#D01");
290                 Assert.AreEqual (c1[1], c2[1], "#D02");
291                 Assert.AreEqual (c1[2], c2[2], "#D03");
292
293                 char[] d10 = {'a', 'b'};
294                 char[] d11 = {'a', 'c'};
295                 char[] d12 = {'b', 'c'};
296                 char[][] d1 = {d10, d11, d12};
297                 char[][] d2 = (char[][])d1.Clone();
298                 Assert.AreEqual (d1[0], d2[0], "#D04");
299                 Assert.AreEqual (d1[1], d2[1], "#D05");
300                 Assert.AreEqual (d1[2], d2[2], "#D06");
301
302                 d1[0][0] = 'z';
303                 Assert.AreEqual (d1[0], d2[0], "#D07");
304         }
305
306         [Test] public void TestIndexer ()
307         {
308                 int [] a = new int [10];
309                 IList b = a;
310                 try {
311                         object c = b [-1];
312                         Assert.Fail ("IList.this [-1] should throw");
313                 } catch (IndexOutOfRangeException) {
314                         // Good
315                 } catch (Exception){
316                         Assert.Fail ("Should have thrown an IndexOutOfRangeException");
317                 }
318         }
319                 
320         [Test]
321         public void TestCopy() {
322                 {
323                         bool errorThrown = false;
324                         try {
325                                 Char[] c1 = {};
326                                 Array.Copy(c1, null, 1);
327                         } catch (ArgumentNullException) {
328                                 errorThrown = true;
329                         }
330                         Assert.IsTrue (errorThrown, "#E01");
331                 }
332                 {
333                         bool errorThrown = false;
334                         try {
335                                 Char[] c1 = {};
336                                 Array.Copy(null, c1, 1);
337                         } catch (ArgumentNullException) {
338                                 errorThrown = true;
339                         }
340                         Assert.IsTrue (errorThrown, "#E02");
341                 }
342                 {
343                         bool errorThrown = false;
344                         try {
345                                 Char[] c1 = new Char[1];
346                                 Char[,] c2 = new Char[1,1];
347                                 Array.Copy(c1, c2, 1);
348                         } catch (RankException) {
349                                 errorThrown = true;
350                         }
351                         Assert.IsTrue (errorThrown, "#E03");
352                 }
353                 {
354                         bool errorThrown = false;
355                         try {
356                                 Char[] c1 = new Char[1];
357                                 string[] s1 = new String[1];
358                                 Array.Copy(c1, s1, 1);
359                         } catch (ArrayTypeMismatchException) {
360                                 errorThrown = true;
361                         }
362                         Assert.IsTrue (errorThrown, "#E04");
363                 }
364                 {
365                         bool errorThrown = false;
366                         try {
367                                 Char[] c1 = new Char[1];
368                                 Object[] o1 = new Object[1];
369                                 o1[0] = "hello";
370                                 Array.Copy(o1, c1, 1);
371                         } catch (InvalidCastException) {
372                                 errorThrown = true;
373                         }
374                         Assert.IsTrue (errorThrown, "#E05");
375                 }
376                 {
377                         bool errorThrown = false;
378                         try {
379                                 Char[] c1 = new Char[1];
380                                 Char[] c2 = new Char[1];
381                                 Array.Copy(c1, c2, -1);
382                         } catch (ArgumentOutOfRangeException) {
383                                 errorThrown = true;
384                         }
385                         Assert.IsTrue (errorThrown, "#E06");
386                 }
387                 {
388                         bool errorThrown = false;
389                         try {
390                                 Char[] c1 = new Char[1];
391                                 Char[] c2 = new Char[2];
392                                 Array.Copy(c1, c2, 2);
393                         } catch (ArgumentException) {
394                                 errorThrown = true;
395                         }
396                         Assert.IsTrue (errorThrown, "#E07");
397                 }
398                 {
399                         bool errorThrown = false;
400                         try {
401                                 Char[] c1 = new Char[1];
402                                 Char[] c2 = new Char[2];
403                                 Array.Copy(c2, c1, 2);
404                         } catch (ArgumentException) {
405                                 errorThrown = true;
406                         }
407                         Assert.IsTrue (errorThrown, "#E08");
408                 }
409
410                 char[] orig = {'a', 'b', 'd', 'a'};
411                 char[] copy = new Char[4];
412                 Array.Copy(orig, copy, 4);
413                 for (int i = 0; i < orig.Length; i++) {
414                         Assert.AreEqual (orig[i], copy[i], "#E09(" + i + ")");
415                 }
416                 Array.Clear(copy, 0, copy.Length);
417                 for (int i = 0; i < orig.Length; i++) {
418                         Assert.AreEqual ((char)0, copy[i], "#E10(" + i + ")");
419                 }
420                 Array.Copy(orig, copy, 2);
421                 Assert.AreEqual (orig[0], copy[0], "#E11");
422                 Assert.AreEqual (orig[1], copy[1], "#E12");
423                 Assert.IsTrue (orig[2] != copy[2], "#E13");
424                 Assert.IsTrue (orig[3] != copy[3], "#E14");
425         }
426
427         [Test]
428         public void TestCopy2() {
429                 {
430                         bool errorThrown = false;
431                         try {
432                                 Char[] c1 = new Char[2];
433                                 Char[] c2 = new Char[2];
434                                 Array.Copy(c2, 1, c1, 0, 2);
435                         } catch (ArgumentException) {
436                                 errorThrown = true;
437                         }
438                         Assert.IsTrue (errorThrown, "#E31");
439                 }
440                 {
441                         bool errorThrown = false;
442                         try {
443                                 Char[] c1 = new Char[2];
444                                 Char[] c2 = new Char[2];
445                                 Array.Copy(c2, 0, c1, 1, 2);
446                         } catch (ArgumentException) {
447                                 errorThrown = true;
448                         }
449                         Assert.IsTrue (errorThrown, "#E32");
450                 }
451                 
452                 char[] orig = {'a', 'b', 'd', 'a'};
453                 char[] copy = new Char[4];
454                 Array.Copy(orig, 1, copy, 1, 3);
455                 Assert.IsTrue (copy[0] != orig[0], "#E33");
456                 for (int i = 1; i < orig.Length; i++) {
457                         Assert.AreEqual (orig[i], copy[i], "#E34(" + i + ")");
458                 }
459                 Array.Clear(copy, 0, copy.Length);
460                 Array.Copy(orig, 1, copy, 0, 2);
461                 Assert.AreEqual (orig[1], copy[0], "#E35");
462                 Assert.AreEqual (orig[2], copy[1], "#E36");
463                 Assert.IsTrue (copy[2] != orig[2], "#E37");
464                 Assert.IsTrue (copy[3] != orig[3], "#E38");
465         }
466
467         [Test]
468         [ExpectedException (typeof (InvalidCastException))]
469         public void Copy_InvalidCast () {
470                 object[] arr1 = new object [10];
471                 Type[] arr2 = new Type [10];
472
473                 arr1 [0] = new object ();
474
475                 Array.Copy (arr1, 0, arr2, 0, 10);
476         }
477
478         [Test]
479         public void TestCopyTo() {
480                 {
481                         bool errorThrown = false;
482                         try {
483                                 Char[] c1 = new Char[2];
484                                 c1.CopyTo(null, 2);
485                         } catch (ArgumentNullException) {
486                                 errorThrown = true;
487                         }
488                         Assert.IsTrue (errorThrown, "#E61");
489                 }
490                 {
491                         bool errorThrown = false;
492                         try {
493                                 Char[] c1 = new Char[2];
494                                 Char[,] c2 = new Char[2,2];
495                                 c1.CopyTo(c2, 2);
496                         } catch (ArgumentException) {
497                                 errorThrown = true;
498                         }
499 #if TARGET_JVM // This is really implementation dependent behaviour.
500                         catch (RankException) {
501                                 errorThrown = true;
502                         }
503 #endif // TARGET_JVM
504                         Assert.IsTrue (errorThrown, "#E62");
505                 }
506                 {
507                         bool errorThrown = false;
508                         try {
509                                 Char[,] c1 = new Char[2,2];
510                                 Char[] c2 = new Char[2];
511                                 c1.CopyTo(c2, -1);
512                         } catch (RankException) {
513                                 errorThrown = true;
514                         }
515                         Assert.IsTrue (errorThrown, "#E63");
516                 }
517                 {
518                         bool errorThrown = false;
519                         try {
520                                 Char[,] c1 = new Char[2,2];
521                                 Char[] c2 = new Char[2];
522                                 c1.CopyTo(c2, 2);
523                         } catch (RankException) {
524                                 errorThrown = true;
525                         }
526                         Assert.IsTrue (errorThrown, "#E64");
527                 }
528                 {
529                         bool errorThrown = false;
530                         try {
531                                 Char[] c1 = new Char[2];
532                                 Char[] c2 = new Char[2];
533                                 c1.CopyTo(c2, -1);
534                         } catch (ArgumentOutOfRangeException) {
535                                 errorThrown = true;
536                         }
537                         Assert.IsTrue (errorThrown, "#E65");
538                 }
539                 {
540                         bool errorThrown = false;
541                         try {
542                                 Char[] c1 = new Char[2];
543                                 Char[] c2 = new Char[2];
544                                 c1.CopyTo(c2, 3);
545                         } catch (ArgumentException) {
546                                 errorThrown = true;
547                         }
548                         Assert.IsTrue (errorThrown, "#E66");
549                 }
550                 {
551                         bool errorThrown = false;
552                         try {
553                                 Char[] c1 = new Char[2];
554                                 Char[] c2 = new Char[2];
555                                 c1.CopyTo(c2, 1);
556                         } catch (ArgumentException) {
557                                 errorThrown = true;
558                         }
559                         Assert.IsTrue (errorThrown, "#E67");
560                 }
561
562                 {
563                         bool errorThrown = false;
564                         try {
565                                 String[] c1 = new String[2];
566                                 // TODO: this crashes mono if there are null
567                                 // values in the array.
568                                 c1[1] = "hey";
569                                 c1[0] = "you";
570                                 Char[] c2 = new Char[2];
571                                 c2[1] = 'a';
572                                 c2[0] = 'z';
573                                 c1.CopyTo(c2, 0);
574                         } catch (ArrayTypeMismatchException) {
575                                 errorThrown = true;
576                         }
577                         Assert.IsTrue (errorThrown, "#E68");
578                 }
579
580                 Char[] orig = {'a', 'b', 'c', 'd'};
581                 Char[] copy = new Char[10];
582                 Array.Clear(copy, 0, copy.Length);
583                 orig.CopyTo(copy, 3);
584                 Assert.AreEqual ((char)0, copy[0], "#E69");
585                 Assert.AreEqual ((char)0, copy[1], "#E70");
586                 Assert.AreEqual ((char)0, copy[2], "#E71");
587                 Assert.AreEqual (orig[0], copy[3], "#E72");
588                 Assert.AreEqual (orig[1], copy[4], "#E73");
589                 Assert.AreEqual (orig[2], copy[5], "#E74");
590                 Assert.AreEqual (orig[3], copy[6], "#E75");
591                 Assert.AreEqual ((char)0, copy[7], "#E76");
592                 Assert.AreEqual ((char)0, copy[8], "#E77");
593                 Assert.AreEqual ((char)0, copy[9], "#E78");
594
595                 {
596                         // The following is valid and must not throw an exception.
597                         bool errorThrown = false;
598                         try {
599                                 int[] src = new int [0];
600                                 int[] dest = new int [0];
601                                 src.CopyTo (dest, 0);
602                         } catch (ArgumentException) {
603                                 errorThrown = true;
604                         }
605                         Assert.IsTrue (!errorThrown, "#E79");
606                 }
607
608                 {
609                         // bug #38812
610                         bool errorThrown = false;
611                         try {
612                                 CClass[] src = new CClass [] { new CClass () };
613                                 BClass[] dest = new BClass [1];
614
615                                 src.CopyTo (dest, 0);
616
617                         } catch (ArrayTypeMismatchException) {
618                                 errorThrown = true;
619                         }
620                         Assert.IsTrue (errorThrown, "#E80");
621                 }
622         }
623
624         [Test]
625         public void TestCreateInstance() {
626                 {
627                         bool errorThrown = false;
628                         try {
629                                 Array.CreateInstance(null, 12);
630                         } catch (ArgumentNullException) {
631                                 errorThrown = true;
632                         }
633                         Assert.IsTrue (errorThrown, "#F01");
634                 }
635                 {
636                         bool errorThrown = false;
637                         try {
638                                 Array.CreateInstance(Type.GetType("System.Char"), -3);
639                         } catch (ArgumentOutOfRangeException) {
640                                 errorThrown = true;
641                         }
642                         Assert.IsTrue (errorThrown, "#F02");
643                 }
644                 {
645                         bool errorThrown = false;
646                         try {
647                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
648                         } catch (ArgumentNullException) {
649                                 errorThrown = true;
650                         }
651                         Assert.IsTrue (errorThrown, "#F03a");
652                 }
653 #if NET_1_1
654                 {
655                         bool errorThrown = false;
656                         try {
657                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
658                         } catch (ArgumentNullException) {
659                                 errorThrown = true;
660                         }
661                         Assert.IsTrue (errorThrown, "#F03b");
662                 }
663 #endif
664 #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
665                 {
666                         bool errorThrown = false;
667                         try {
668                                 Array.CreateInstance(Type.GetType("System.Char"), null, null);
669                         } catch (ArgumentNullException) {
670                                 errorThrown = true;
671                         }
672                         Assert.IsTrue (errorThrown, "#F04");
673                 }
674 #endif // TARGET_JVM
675                 {
676                         bool errorThrown = false;
677                         try {
678                                 int[] lengths = new int [0];
679                                 Array.CreateInstance(Type.GetType("System.Char"), lengths);
680                         } catch (ArgumentException) {
681                                 errorThrown = true;
682                         }
683                         Assert.IsTrue (errorThrown, "#F05");
684                 }
685 #if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
686                 {
687                         bool errorThrown = false;
688                         try {
689                                 int[] lengths = new int [1];
690                                 int[] bounds = new int [2];
691                                 Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
692                                 errorThrown = true;
693                         } catch (ArgumentException) {
694                                 errorThrown = true;
695                         }
696                         Assert.IsTrue (errorThrown, "#F06");
697                 }
698
699                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
700                 Assert.AreEqual (12, c1.Length, "#F07");
701
702                 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
703                 Assert.AreEqual (2, c2.Rank, "#F08");
704                 Assert.AreEqual (60, c2.Length, "#F09");
705
706
707                 {
708                         int[] lengths = { 3 };
709                         int[] bounds = { 5 };
710                         int[] src = { 512, 718, 912 };
711                         Array array = Array.CreateInstance(typeof(int), lengths, bounds);
712
713                         Assert.AreEqual (3, array.Length, "#F10");
714                         Assert.AreEqual (5, array.GetLowerBound(0), "#F11");
715                         Assert.AreEqual (7, array.GetUpperBound(0), "#F12");
716
717                         src.CopyTo (array, 5);
718
719                         for (int i = 0; i < src.Length; i++)
720                                 Assert.AreEqual (src[i], array.GetValue(i+5), "#F13(" + i + ")");
721                 }
722
723                 // Test that a 1 dimensional array with 0 lower bound is the
724                 // same as an szarray
725                 Type szarrayType = new int [10].GetType ();
726                 Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
727                 Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
728 #endif // TARGET_JVM
729         }
730         
731         [Test]
732         [ExpectedException (typeof (ArgumentNullException))]
733         public void TestCreateInstance2 ()
734         {
735                 Array.CreateInstance (typeof (Int32), (int[])null);
736         }
737
738         [Test]
739 #if NET_2_0
740         [ExpectedException (typeof (ArgumentNullException))]
741 #else
742         [ExpectedException (typeof (NullReferenceException))]
743 #endif
744         public void TestCreateInstance2b ()
745         {
746                 Array.CreateInstance (typeof (Int32), (long[])null);
747         }
748
749         [Test]
750         public void TestGetEnumerator() {
751                 String[] s1 = {"this", "is", "a", "test"};
752                 IEnumerator en = s1.GetEnumerator ();
753                 Assert.IsNotNull (en, "#G01");
754
755                 Assert.IsTrue (en.MoveNext (), "#G02");
756                 Assert.AreEqual ("this", en.Current, "#G03");
757                 Assert.IsTrue (en.MoveNext (), "#G04");
758                 Assert.AreEqual ("is", en.Current, "#G05");
759                 Assert.IsTrue (en.MoveNext (), "#G06");
760                 Assert.AreEqual ("a", en.Current, "#G07");
761                 Assert.IsTrue (en.MoveNext (), "#G08");
762                 Assert.AreEqual ("test", en.Current, "#G09");
763                 Assert.IsTrue (!en.MoveNext (), "#G10");
764
765                 en.Reset ();
766                 Assert.IsTrue (en.MoveNext (), "#G11");
767                 Assert.AreEqual ("this", en.Current, "#G12");
768
769                 // mutation does not invalidate array enumerator!
770                 s1.SetValue ("change", 1);
771                 Assert.IsTrue (en.MoveNext (), "#G13");
772                 Assert.AreEqual ("change", en.Current, "#G14");
773         }
774
775         [Test]
776         public void TestGetEnumeratorMultipleDimension() {
777                 String[,] s1 = {{"this", "is"}, {"a", "test"}};
778                 IEnumerator en = s1.GetEnumerator ();
779                 Assert.IsNotNull (en, "#AA01");
780
781                 Assert.IsTrue (en.MoveNext (), "#AA02");
782                 Assert.AreEqual ("this", en.Current, "#AA03");
783                 Assert.IsTrue (en.MoveNext (), "#AA04");
784                 Assert.AreEqual ("is", en.Current, "#AA05");
785                 Assert.IsTrue (en.MoveNext (), "#AA06");
786                 Assert.AreEqual ("a", en.Current, "#AA07");
787                 Assert.IsTrue (en.MoveNext (), "#AA08");
788                 Assert.AreEqual ("test", en.Current, "#AA09");
789                 Assert.IsTrue (!en.MoveNext (), "#AA10");
790
791                 en.Reset ();
792                 Assert.IsTrue (en.MoveNext (), "#AA11");
793                 Assert.AreEqual ("this", en.Current, "#AA12");
794
795                 int[] idxs = {0,1};
796                 // mutation does not invalidate array enumerator!
797                 s1.SetValue ("change", idxs);
798                 Assert.IsTrue (en.MoveNext (), "#AA13");
799                 Assert.AreEqual ("change", en.Current, "#AA14");
800         }
801
802         [Test]
803         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
804         public void TestGetEnumeratorNonZeroLowerBounds() {
805                 int[] myLengthsArray = new int[2] { 3, 5 };
806                 int[] myBoundsArray = new int[2] { 2, 3 };
807
808                 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
809                 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
810                         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
811                                 int[] myIndicesArray = new int[2] { i, j };
812                                 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
813                         }
814                 IEnumerator en = myArray.GetEnumerator ();
815                 Assert.IsNotNull (en, "#AB01");
816
817                 // check the first couple of values
818                 Assert.IsTrue (en.MoveNext (), "#AB02");
819                 Assert.AreEqual ("23", en.Current, "#AB03");
820                 Assert.IsTrue (en.MoveNext (), "#AB04");
821                 Assert.AreEqual ("24", en.Current, "#AB05");
822
823                 // then check the last element's value
824                 string lastElement;
825                 do {  
826                         lastElement = (string)en.Current;
827                 } while (en.MoveNext());
828                 Assert.AreEqual ("47", lastElement, "#AB06");
829         }
830
831         [Test]
832         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
833         public void TestIList_Add () {
834                 int[] myLengthsArray = new int[2] { 3, 5 };
835                 int[] myBoundsArray = new int[2] { 2, 3 };
836
837                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
838                 try {
839                         ((IList)myArray).Add ("can not");
840                         Assert.Fail ("IList.Add should throw");
841                 }
842                 catch (NotSupportedException) {
843                         return;
844                 }
845                 catch (Exception) {
846                         Assert.Fail ("IList.Add threw wrong exception type");
847                 }
848
849                 Assert.Fail ("IList.Add shouldn't get this far");
850         }
851
852         [Test]
853         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
854         public void TestIList_Insert () {
855                 int[] myLengthsArray = new int[2] { 3, 5 };
856                 int[] myBoundsArray = new int[2] { 2, 3 };
857
858                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
859                 try {
860                         ((IList)myArray).Insert (0, "can not");
861                         Assert.Fail ("IList.Insert should throw");
862                 }
863                 catch (NotSupportedException) {
864                         return;
865                 }
866                 catch (Exception) {
867                         Assert.Fail ("IList.Insert threw wrong exception type");
868                 }
869
870                 Assert.Fail ("IList.Insert shouldn't get this far");
871         }
872
873         [Test]
874         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
875         public void TestIList_Remove () {
876                 int[] myLengthsArray = new int[2] { 3, 5 };
877                 int[] myBoundsArray = new int[2] { 2, 3 };
878
879                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
880                 try {
881                         ((IList)myArray).Remove ("can not");
882                         Assert.Fail ("IList.Remove should throw");
883                 }
884                 catch (NotSupportedException) {
885                         return;
886                 }
887                 catch (Exception) {
888                         Assert.Fail ("IList.Remove threw wrong exception type");
889                 }
890
891                 Assert.Fail ("IList.Remove shouldn't get this far");
892         }
893
894         [Test]
895         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
896         public void TestIList_RemoveAt () {
897                 int[] myLengthsArray = new int[2] { 3, 5 };
898                 int[] myBoundsArray = new int[2] { 2, 3 };
899
900                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
901                 try {
902                         ((IList)myArray).RemoveAt (0);
903                         Assert.Fail ("IList.RemoveAt should throw");
904                 }
905                 catch (NotSupportedException) {
906                         return;
907                 }
908                 catch (Exception) {
909                         Assert.Fail ("IList.RemoveAt threw wrong exception type");
910                 }
911
912                 Assert.Fail ("IList.RemoveAt shouldn't get this far");
913         }
914
915         [Test]
916         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
917         public void TestIList_Contains () {
918                 int[] myLengthsArray = new int[2] { 3, 5 };
919                 int[] myBoundsArray = new int[2] { 2, 3 };
920
921                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
922
923                 try {
924                         bool b = ((IList)myArray).Contains ("23");
925                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
926                 }
927                 catch (RankException) {
928                         int[] iArr = new int[3] { 1, 2, 3};
929                         // check the first and last items
930                         Assert.IsTrue (((IList)iArr).Contains (1), "AC01");
931                         Assert.IsTrue (((IList)iArr).Contains (3), "AC02");
932
933                         // and one that is definately not there
934                         Assert.IsTrue (!((IList)iArr).Contains (42), "AC03");
935                         return;
936                 }
937
938                 Assert.Fail ("Should not get here");
939         }
940
941         [Test]
942         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
943         public void TestIList_IndexOf () {
944                 int[] myLengthsArray = new int[2] { 3, 5 };
945                 int[] myBoundsArray = new int[2] { 2, 3 };
946
947                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
948
949                 try {
950                         bool b = ((IList)myArray).Contains ("23");
951                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
952                 }
953                 catch (RankException) {
954                         int[] iArr = new int[3] { 1, 2, 3};
955                         // check the first and last items
956                         Assert.AreEqual (0, ((IList)iArr).IndexOf (1), "AD01");
957                         Assert.AreEqual (2, ((IList)iArr).IndexOf (3), "AD02");
958
959                         // and one that is definately not there
960                         Assert.AreEqual (-1, ((IList)iArr).IndexOf (42), "AD03");
961                 }
962                 catch (Exception e) {
963                         Assert.Fail ("Unexpected exception: " + e.ToString());
964                 }
965
966                 // check that wierd case whem lowerbound is Int32.MinValue,
967                 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
968                 int[] myLengthArray = new int[1] { 3 };
969                 int[] myBoundArray = new int[1] { Int32.MinValue };
970                 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
971                 Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
972
973         }
974
975         [Test]
976         public void TestGetLength() {
977                 {
978                         bool errorThrown = false;
979                         try {
980                                 char[] c1 = {'a', 'b', 'c'};
981                                 c1.GetLength(-1);
982                         } catch (IndexOutOfRangeException) {
983                                 errorThrown = true;
984                         }
985                         Assert.IsTrue (errorThrown, "#H01");
986                 }
987                 {
988                         bool errorThrown = false;
989                         try {
990                                 char[] c1 = {'a', 'b', 'c'};
991                                 c1.GetLength(1);
992                         } catch (IndexOutOfRangeException) {
993                                 errorThrown = true;
994                         }
995                         Assert.IsTrue (errorThrown, "#H02");
996                 }
997
998                 char[] c2 = new Char[5];
999                 Assert.AreEqual (5, c2.GetLength(0), "#H03");
1000
1001                 char[,] c3 = new Char[6,7];
1002                 Assert.AreEqual (6, c3.GetLength(0), "#H04");
1003                 Assert.AreEqual (7, c3.GetLength(1), "#H05");
1004         }
1005
1006         [Test]
1007         public void TestGetLowerBound() {
1008                 {
1009                         bool errorThrown = false;
1010                         try {
1011                                 char[] c = {'a', 'b', 'c'};
1012                                 c.GetLowerBound(-1);
1013                         } catch (IndexOutOfRangeException) {
1014                                 errorThrown = true;
1015                         }
1016                         Assert.IsTrue (errorThrown, "#H31");
1017                 }
1018                 {
1019                         bool errorThrown = false;
1020                         try {
1021                                 char[] c = {'a', 'b', 'c'};
1022                                 c.GetLowerBound(1);
1023                         } catch (IndexOutOfRangeException) {
1024                                 errorThrown = true;
1025                         }
1026                         Assert.IsTrue (errorThrown, "#H32");
1027                 }
1028
1029                 char[] c1 = new Char[5];
1030                 Assert.AreEqual (0, c1.GetLowerBound(0), "#H33");
1031
1032                 char[,] c2 = new Char[4,4];
1033                 Assert.AreEqual (0, c2.GetLowerBound(0), "#H34");
1034                 Assert.AreEqual (0, c2.GetLowerBound(1), "#H35");
1035         }
1036
1037         [Test]
1038         public void TestGetUpperBound() {
1039                 {
1040                         bool errorThrown = false;
1041                         try {
1042                                 char[] c = {'a', 'b', 'c'};
1043                                 c.GetUpperBound(-1);
1044                         } catch (IndexOutOfRangeException) {
1045                                 errorThrown = true;
1046                         }
1047                         Assert.IsTrue (errorThrown, "#H61");
1048                 }
1049                 {
1050                         bool errorThrown = false;
1051                         try {
1052                                 char[] c = {'a', 'b', 'c'};
1053                                 c.GetUpperBound(1);
1054                         } catch (IndexOutOfRangeException) {
1055                                 errorThrown = true;
1056                         }
1057                         Assert.IsTrue (errorThrown, "#H62");
1058                 }
1059
1060                 char[] c1 = new Char[5];
1061                 Assert.AreEqual (4, c1.GetUpperBound(0), "#H63");
1062
1063                 char[,] c2 = new Char[4,6];
1064                 Assert.AreEqual (3, c2.GetUpperBound(0), "#H64");
1065                 Assert.AreEqual (5, c2.GetUpperBound(1), "#H65");
1066         }
1067
1068         [Test]
1069         public void TestGetValue1() {
1070                 {
1071                         bool errorThrown = false;
1072                         try {
1073                                 char[,] c = new Char[2,2];
1074                                 c.GetValue(1);
1075                         } catch (ArgumentException) {
1076                                 errorThrown = true;
1077                         }
1078                         Assert.IsTrue (errorThrown, "#I01");
1079                 }
1080                 {
1081                         bool errorThrown = false;
1082                         try {
1083                                 char[] c = {'a', 'b', 'c'};
1084                                 c.GetValue(-1);
1085                         } catch (IndexOutOfRangeException) {
1086                                 errorThrown = true;
1087                         }
1088                         Assert.IsTrue (errorThrown, "#I02");
1089                 }
1090                 {
1091                         bool errorThrown = false;
1092                         try {
1093                                 char[] c = {'a', 'b', 'c'};
1094                                 c.GetValue(4);
1095                         } catch (IndexOutOfRangeException) {
1096                                 errorThrown = true;
1097                         }
1098                         Assert.IsTrue (errorThrown, "#I03");
1099                 }
1100
1101                 char[] c1 = {'a', 'b', 'c', 'd'};
1102                 for (int i = 0; i < c1.Length; i++) {
1103                         Assert.AreEqual (c1[i], c1.GetValue(i), "#I04(" + i + ")");
1104                 }
1105         }
1106
1107         [Test]
1108         public void TestGetValue2() {
1109                 {
1110                         bool errorThrown = false;
1111                         try {
1112                                 char[] c = new Char[2];
1113                                 c.GetValue(1,1);
1114                         } catch (ArgumentException) {
1115                                 errorThrown = true;
1116                         }
1117                         Assert.IsTrue (errorThrown, "#I21");
1118                 }
1119                 {
1120                         bool errorThrown = false;
1121                         try {
1122                                 char[,] c = new Char[2,2];
1123                                 c.GetValue(-1, 1);
1124                         } catch (IndexOutOfRangeException) {
1125                                 errorThrown = true;
1126                         }
1127                         Assert.IsTrue (errorThrown, "#I22");
1128                 }
1129                 {
1130                         bool errorThrown = false;
1131                         try {
1132                                 char[,] c = new Char[2,2];
1133                                 c.GetValue(4,1);
1134                         } catch (IndexOutOfRangeException) {
1135                                 errorThrown = true;
1136                         }
1137                         Assert.IsTrue (errorThrown, "#I23");
1138                 }
1139
1140                 char[,] c1 = new Char[4,6];
1141                 for (int i = 0; i < 24; i++) {
1142                         int first = i / 6;
1143                         int second = i % 6;
1144                         c1[first,second] = (char)(((int)'a')+i);
1145                 }
1146                 for (int i = 0; i < c1.GetLength(0); i++) {
1147                         for (int j = 0; j < c1.GetLength(1); j++) {
1148                                 Assert.AreEqual (c1[i, j], c1.GetValue(i, j), "#I24(" + i + "," + j + ")");
1149                         }
1150                 }
1151         }
1152
1153         [Test]
1154         public void TestGetValue3() {
1155                 {
1156                         bool errorThrown = false;
1157                         try {
1158                                 char[] c = new Char[2];
1159                                 c.GetValue(1,1,1);
1160                         } catch (ArgumentException) {
1161                                 errorThrown = true;
1162                         }
1163                         Assert.IsTrue (errorThrown, "#I41");
1164                 }
1165                 {
1166                         bool errorThrown = false;
1167                         try {
1168                                 char[,,] c = new Char[2,2,2];
1169                                 c.GetValue(-1, 1, 1);
1170                         } catch (IndexOutOfRangeException) {
1171                                 errorThrown = true;
1172                         }
1173                         Assert.IsTrue (errorThrown, "#I42");
1174                 }
1175                 {
1176                         bool errorThrown = false;
1177                         try {
1178                                 char[,,] c = new Char[2,2,2];
1179                                 c.GetValue(4,1,1);
1180                         } catch (IndexOutOfRangeException) {
1181                                 errorThrown = true;
1182                         }
1183                         Assert.IsTrue (errorThrown, "#I43");
1184                 }
1185
1186                 char[,,] c1 = new Char[4,2,3];
1187                 for (int i = 0; i < 24; i++) {
1188                         int first = i / 6;
1189                         int remains = i % 6;
1190                         int second = remains / 3;
1191                         int third = remains % 3;
1192                         c1[first,second, third] = (char)(((int)'a')+i);
1193                 }
1194                 for (int i = 0; i < c1.GetLength(0); i++) {
1195                         for (int j = 0; j < c1.GetLength(1); j++) {
1196                                 for (int k = 0; k < c1.GetLength(2); k++) {
1197                                         Assert.AreEqual (c1[i, j, k], c1.GetValue(i, j, k), "#I44(" + i + "," + j + ")");
1198                                 }
1199                         }
1200                 }
1201         }
1202
1203         [Test]
1204 #if NET_2_0
1205         [ExpectedException (typeof (ArgumentNullException))]
1206 #else
1207         [ExpectedException (typeof (NullReferenceException))]
1208 #endif
1209         public void TestGetValueLongArray ()
1210         {
1211                 char[] c = new Char[2];
1212                 c.GetValue((long [])null);
1213         }
1214
1215         [Test]
1216         public void TestGetValueN() {
1217                 {
1218                         bool errorThrown = false;
1219                         try {
1220                                 char[] c = new Char[2];
1221                                 c.GetValue((int [])null);
1222                         } catch (ArgumentNullException) {
1223                                 errorThrown = true;
1224                         }
1225                         Assert.IsTrue (errorThrown, "#I61a");
1226                 }
1227                 {
1228                         bool errorThrown = false;
1229                         try {
1230                                 char[] c = new Char[2];
1231                                 int[] coords = {1, 1};
1232                                 c.GetValue(coords);
1233                         } catch (ArgumentException) {
1234                                 errorThrown = true;
1235                         }
1236                         Assert.IsTrue (errorThrown, "#I62");
1237                 }
1238                 {
1239                         bool errorThrown = false;
1240                         try {
1241                                 char[,] c = new Char[2,2];
1242                                 int[] coords = {-1, 1};
1243                                 c.GetValue(coords);
1244                         } catch (IndexOutOfRangeException) {
1245                                 errorThrown = true;
1246                         }
1247                         Assert.IsTrue (errorThrown, "#I63");
1248                 }
1249                 {
1250                         bool errorThrown = false;
1251                         try {
1252                                 char[,] c = new Char[2,2];
1253                                 int[] coords = {4, 1};
1254                                 c.GetValue(coords);
1255                         } catch (IndexOutOfRangeException) {
1256                                 errorThrown = true;
1257                         }
1258                         Assert.IsTrue (errorThrown, "#I64");
1259                 }
1260
1261                 char[,] c1 = new Char[4,6];
1262                 for (int i = 0; i < 24; i++) {
1263                         int first = i / 6;
1264                         int second = i % 6;
1265                         c1[first,second] = (char)(((int)'a')+i);
1266                 }
1267                 for (int i = 0; i < c1.GetLength(0); i++) {
1268                         for (int j = 0; j < c1.GetLength(1); j++) {
1269                                 int[] coords = {i, j};
1270                                 Assert.AreEqual (c1[i, j], c1.GetValue(coords), "#I65(" + i + "," + j + ")");
1271                         }
1272                 }
1273         }
1274
1275         [Test]
1276         public void TestIndexOf1() {
1277                 {
1278                         bool errorThrown = false;
1279                         try {
1280                                 Array.IndexOf(null, "huh?");
1281                         } catch (ArgumentNullException) {
1282                                 errorThrown = true;
1283                         }
1284                         Assert.IsTrue (errorThrown, "#J01");
1285                 }
1286                 {
1287                         bool errorThrown = false;
1288                         try {
1289                                 char[,] c = new Char[2,2];
1290                                 Array.IndexOf(c, "huh?");
1291                         } catch (RankException) {
1292                                 errorThrown = true;
1293                         }
1294                         Assert.IsTrue (errorThrown, "#J02");
1295                 }
1296
1297                 String[] s1 = {"this", "is", "a", "test"};
1298                 Assert.AreEqual (-1, Array.IndexOf(s1, null), "#J03");
1299                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing"), "#J04");
1300                 Assert.AreEqual (0, Array.IndexOf(s1, "this"), "#J05");
1301                 Assert.AreEqual (3, Array.IndexOf(s1, "test"), "#J06");
1302         }
1303
1304         [Test]
1305         public void TestIndexOf2() {
1306                 {
1307                         bool errorThrown = false;
1308                         try {
1309                                 Array.IndexOf(null, "huh?", 0);
1310                         } catch (ArgumentNullException) {
1311                                 errorThrown = true;
1312                         }
1313                         Assert.IsTrue (errorThrown, "#J21");
1314                 }
1315                 {
1316                         bool errorThrown = false;
1317                         try {
1318                                 char[,] c = new Char[2,2];
1319                                 Array.IndexOf(c, "huh?", 0);
1320                         } catch (RankException) {
1321                                 errorThrown = true;
1322                         }
1323                         Assert.IsTrue (errorThrown, "#J22");
1324                 }
1325                 {
1326                         bool errorThrown = false;
1327                         try {
1328                                 char[] c = new Char[2];
1329                                 Array.IndexOf(c, "huh?", 3);
1330                         } catch (ArgumentOutOfRangeException) {
1331                                 errorThrown = true;
1332                         }
1333                         Assert.IsTrue (errorThrown, "#J23");
1334                 }
1335
1336                 String[] s1 = {"this", "is", "really", "a", "test"};
1337                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1), "#J24");
1338                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1), "#J25");
1339                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1), "#J26");
1340                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1), "#J27");
1341                 Assert.AreEqual (4, Array.IndexOf(s1, "test", 1), "#J28");
1342         }
1343
1344         [Test]
1345         public void TestIndexOf3() {
1346                 {
1347                         bool errorThrown = false;
1348                         try {
1349                                 Array.IndexOf(null, "huh?", 0, 1);
1350                         } catch (ArgumentNullException) {
1351                                 errorThrown = true;
1352                         }
1353                         Assert.IsTrue (errorThrown, "#J41");
1354                 }
1355                 {
1356                         bool errorThrown = false;
1357                         try {
1358                                 char[,] c = new Char[2,2];
1359                                 Array.IndexOf(c, "huh?", 0, 1);
1360                         } catch (RankException) {
1361                                 errorThrown = true;
1362                         }
1363                         Assert.IsTrue (errorThrown, "#J42");
1364                 }
1365                 {
1366                         bool errorThrown = false;
1367                         try {
1368                                 char[] c = new Char[2];
1369                                 Array.IndexOf(c, "huh?", 3, 1);
1370                         } catch (ArgumentOutOfRangeException) {
1371                                 errorThrown = true;
1372                         }
1373                         Assert.IsTrue (errorThrown, "#J43");
1374                 }
1375                 {
1376                         bool errorThrown = false;
1377                         try {
1378                                 char[] c = new Char[2];
1379                                 Array.IndexOf(c, "huh?", 0, 5);
1380                         } catch (ArgumentOutOfRangeException) {
1381                                 errorThrown = true;
1382                         }
1383                         Assert.IsTrue (errorThrown, "#J44");
1384                 }
1385
1386                 String[] s1 = {"this", "is", "really", "a", "test"};
1387                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1, 3), "#J45");
1388                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1, 3), "#J46");
1389                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1, 3), "#J47");
1390                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1, 3), "#J48");
1391                 Assert.AreEqual (-1, Array.IndexOf(s1, "test", 1, 3), "#J49");
1392                 Assert.AreEqual (3, Array.IndexOf(s1, "a", 1, 3), "#J50");
1393         }
1394         
1395         [Test]
1396         public void TestIndexOf_CustomEqual ()
1397         {
1398                 DataEqual[] test = new DataEqual [] { new DataEqual () };
1399                 Assert.AreEqual (0, Array.IndexOf (test, "asdfas", 0));
1400                 
1401                 IList array = (IList)test;
1402                 Assert.AreEqual (0, array.IndexOf ("asdfas"));
1403         }
1404         
1405         [Test]
1406         public void TestLastIndexOf1() {
1407                 {
1408                         bool errorThrown = false;
1409                         try {
1410                                 Array.LastIndexOf(null, "huh?");
1411                         } catch (ArgumentNullException) {
1412                                 errorThrown = true;
1413                         }
1414                         Assert.IsTrue (errorThrown, "#K01");
1415                 }
1416                 {
1417                         bool errorThrown = false;
1418                         try {
1419                                 char[,] c = new Char[2,2];
1420                                 Array.LastIndexOf(c, "huh?");
1421                         } catch (RankException) {
1422                                 errorThrown = true;
1423                         }
1424                         Assert.IsTrue (errorThrown, "#K02");
1425                 }
1426
1427                 String[] s1 = {"this", "is", "a", "a", "test"};
1428                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null), "#K03");
1429                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing"), "#K04");
1430                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this"), "#K05");
1431                 Assert.AreEqual (4, Array.LastIndexOf(s1, "test"), "#K06");
1432                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a"), "#K07");
1433
1434                 Assert.AreEqual (-1, Array.LastIndexOf (new String [0], "foo"));
1435         }
1436
1437         [Test]
1438         public void TestLastIndexOf2() {
1439                 {
1440                         bool errorThrown = false;
1441                         try {
1442                                 Array.LastIndexOf(null, "huh?", 0);
1443                         } catch (ArgumentNullException) {
1444                                 errorThrown = true;
1445                         }
1446                         Assert.IsTrue (errorThrown, "#K21");
1447                 }
1448                 {
1449                         bool errorThrown = false;
1450                         try {
1451                                 char[,] c = new Char[2,2];
1452                                 Array.LastIndexOf(c, "huh?", 0);
1453                         } catch (RankException) {
1454                                 errorThrown = true;
1455                         }
1456                         Assert.IsTrue (errorThrown, "#K22");
1457                 }
1458                 {
1459                         bool errorThrown = false;
1460                         try {
1461                                 char[] c = new Char[2];
1462                                 Array.LastIndexOf(c, "huh?", 3);
1463                         } catch (ArgumentOutOfRangeException) {
1464                                 errorThrown = true;
1465                         }
1466                         Assert.IsTrue (errorThrown, "#K23");
1467                 }
1468
1469                 String[] s1 = {"this", "is", "really", "a", "test"};
1470                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3), "#K24");
1471                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3), "#K25");
1472                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3), "#K26");
1473                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3), "#K27");
1474                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this", 3), "#K28");
1475         }
1476
1477         [Test]
1478         public void TestLastIndexOf3() {
1479                 {
1480                         bool errorThrown = false;
1481                         try {
1482                                 Array.LastIndexOf(null, "huh?", 0, 1);
1483                         } catch (ArgumentNullException) {
1484                                 errorThrown = true;
1485                         }
1486                         Assert.IsTrue (errorThrown, "#K41");
1487                 }
1488                 {
1489                         bool errorThrown = false;
1490                         try {
1491                                 char[,] c = new Char[2,2];
1492                                 Array.LastIndexOf(c, "huh?", 0, 1);
1493                         } catch (RankException) {
1494                                 errorThrown = true;
1495                         }
1496                         Assert.IsTrue (errorThrown, "#K42");
1497                 }
1498                 {
1499                         bool errorThrown = false;
1500                         try {
1501                                 char[] c = new Char[2];
1502                                 Array.LastIndexOf(c, "huh?", 3, 1);
1503                         } catch (ArgumentOutOfRangeException) {
1504                                 errorThrown = true;
1505                         }
1506                         Assert.IsTrue (errorThrown, "#K43");
1507                 }
1508                 {
1509                         bool errorThrown = false;
1510                         try {
1511                                 char[] c = new Char[2];
1512                                 Array.LastIndexOf(c, "huh?", 0, 5);
1513                         } catch (ArgumentOutOfRangeException) {
1514                                 errorThrown = true;
1515                         }
1516                         Assert.IsTrue (errorThrown, "#K44");
1517                 }
1518
1519                 String[] s1 = {"this", "is", "really", "a", "test"};
1520                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3, 3), "#K45");
1521                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3, 3), "#K46");
1522                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "this", 3, 3), "#K47");
1523                 Assert.AreEqual (1, Array.LastIndexOf(s1, "is", 3, 3), "#K48");
1524                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3, 3), "#K49");
1525                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3, 3), "#K50");
1526         }
1527
1528         [Test]
1529         public void TestLastIndexOf4 ()
1530         {
1531                 short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
1532                 try {
1533                         Array.LastIndexOf (a, (object)16, -1);
1534                         NUnit.Framework.Assert.Fail ("#1");
1535                 } catch (ArgumentOutOfRangeException) { }
1536                 
1537 #if NET_2_0             
1538                 try {
1539                         Array.LastIndexOf<short> (a, 16, -1);
1540                         NUnit.Framework.Assert.Fail ("#2");
1541                 } catch (ArgumentOutOfRangeException) { }
1542 #endif          
1543         }
1544
1545         [Test]
1546         public void TestLastIndexOf5 ()
1547         {
1548                 char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
1549                 string s;
1550                 int retval;
1551                 bool error = false;
1552
1553                 for (int i = a.Length - 1; i >= 0 ; i--) {
1554                         s = i.ToString ();
1555                         retval = Array.LastIndexOf(a, a [i], i, i + 1);
1556                         if (retval != i)
1557                                 error = true;
1558                 }
1559                 Assert.IsTrue (!error);
1560         }
1561
1562         [Test]
1563         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1564         public void LastIndexOf_StartIndexOverflow ()
1565         {
1566                 // legal - no exception
1567                 byte[] array = new byte [16];
1568                 Array.LastIndexOf (array, this, Int32.MaxValue, 1);
1569         }
1570
1571         [Test]
1572         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1573         public void LastIndexOf_CountOverflow ()
1574         {
1575                 // legal - no exception
1576                 byte[] array = new byte [16];
1577                 Array.LastIndexOf (array, this, 1, Int32.MaxValue);
1578         }
1579
1580         [Test]
1581         public void LastIndexOf_0LengthArray ()
1582         {
1583                 Array array = Array.CreateInstance (typeof (char), 0);
1584                 int idx = Array.LastIndexOf (array, (object) null, -1, 0);
1585                 Assert.IsTrue (idx == -1, "#01");
1586                 idx = Array.LastIndexOf (array, (object) null, -1, 10);
1587                 Assert.IsTrue (idx == -1, "#02");
1588                 idx = Array.LastIndexOf (array, (object) null, -100, 10);
1589                 Assert.IsTrue (idx == -1, "#02");
1590
1591                 array = Array.CreateInstance (typeof (char), 1);
1592                 try {
1593                         Array.LastIndexOf (array, (object) null, -1, 0);
1594                         Assert.Fail ("#04");
1595                 } catch (ArgumentOutOfRangeException e) {
1596                 }
1597                 try {
1598                         Array.LastIndexOf (array, (object) null, -1, 10);
1599                         Assert.Fail ("#05");
1600                 } catch (ArgumentOutOfRangeException e) {
1601                 }
1602                 try {
1603                         Array.LastIndexOf (array, (object) null, -100, 10);
1604                         Assert.Fail ("#06");
1605                 } catch (ArgumentOutOfRangeException e) {
1606                 }
1607         }
1608
1609         [Test]
1610         public void TestReverse() {
1611                 {
1612                         bool errorThrown = false;
1613                         try {
1614                                 Array.Reverse(null);
1615                         } catch (ArgumentNullException) {
1616                                 errorThrown = true;
1617                         }
1618                         Assert.IsTrue (errorThrown, "#L01");
1619                 }
1620                 {
1621                         bool errorThrown = false;
1622                         try {
1623                                 char[,] c = new Char[2,2];
1624                                 Array.Reverse(c);
1625                         } catch (RankException) {
1626                                 errorThrown = true;
1627                         }
1628                         Assert.IsTrue (errorThrown, "#L02");
1629                 }
1630                 
1631                 char[] c1 = {'a', 'b', 'c', 'd'};
1632                 Array.Reverse(c1);
1633                 Assert.AreEqual ('d', c1[0], "#L03");
1634                 Assert.AreEqual ('c', c1[1], "#L04");
1635                 Assert.AreEqual ('b', c1[2], "#L05");
1636                 Assert.AreEqual ('a', c1[3], "#L06");
1637
1638                 {
1639                         bool errorThrown = false;
1640                         try {
1641                                 Array.Reverse(null, 0, 0);
1642                         } catch (ArgumentNullException) {
1643                                 errorThrown = true;
1644                         }
1645                         Assert.IsTrue (errorThrown, "#L07");
1646                 }
1647                 {
1648                         bool errorThrown = false;
1649                         try {
1650                                 char[,] c = new Char[2,2];
1651                                 Array.Reverse(c, 0, 0);
1652                         } catch (RankException) {
1653                                 errorThrown = true;
1654                         }
1655                         Assert.IsTrue (errorThrown, "#L08");
1656                 }
1657                 //{
1658                 //bool errorThrown = false;
1659                 //try {
1660                 //      char[] c = new Char[2];
1661                 //      Array.Reverse(c, 0, 3);
1662                 //} catch (ArgumentOutOfRangeException) {
1663                 //      errorThrown = true;
1664                 //}
1665                 //Assert.IsTrue (errorThrown, "#L09");
1666                 //}
1667                 //{
1668                 //bool errorThrown = false;
1669                 //try {
1670                 //      char[] c = new Char[2];
1671                 //      Array.Reverse(c, 3, 0);
1672                 //} catch (ArgumentOutOfRangeException) {
1673                 //      errorThrown = true;
1674                 //}
1675                 //Assert.IsTrue (errorThrown, "#L10");
1676                 //}
1677
1678                 char[] c2 = { 'a', 'b', 'c', 'd'};
1679                 Array.Reverse(c2, 1, 2);
1680                 Assert.AreEqual ('a', c2[0], "#L11");
1681                 Assert.AreEqual ('c', c2[1], "#L12");
1682                 Assert.AreEqual ('b', c2[2], "#L13");
1683                 Assert.AreEqual ('d', c2[3], "#L14");
1684         }
1685
1686         [Test]
1687         public void TestSetValue1() {
1688                 {
1689                         bool errorThrown = false;
1690                         try {
1691                                 char[,] c = new Char[2,2];
1692                                 c.SetValue("buh", 1);
1693                         } catch (ArgumentException) {
1694                                 errorThrown = true;
1695                         }
1696                         Assert.IsTrue (errorThrown, "#M01");
1697                 }
1698                 {
1699                         bool errorThrown = false;
1700                         try {
1701                                 char[] c = {'a', 'b', 'c'};
1702                                 c.SetValue("buh", -1);
1703                         } catch (IndexOutOfRangeException) {
1704                                 errorThrown = true;
1705                         }
1706                         Assert.IsTrue (errorThrown, "#M02");
1707                 }
1708                 {
1709                         bool errorThrown = false;
1710                         try {
1711                                 char[] c = {'a', 'b', 'c'};
1712                                 c.SetValue("buh", 4);
1713                         } catch (IndexOutOfRangeException) {
1714                                 errorThrown = true;
1715                         }
1716                         Assert.IsTrue (errorThrown, "#M03");
1717                 }
1718
1719                 char[] c1 = {'a', 'b', 'c', 'd'};
1720                 char[] c2 = new char[4];
1721                 for (int i = 0; i < c1.Length; i++) {
1722                         c2.SetValue(c1[i], i);
1723                 }
1724                 for (int i = 0; i < c1.Length; i++) {
1725                         Assert.AreEqual (c1[i], c2[i], "#M04(" + i + ")");
1726                 }
1727
1728                 int[] c3 = { 1, 2, 3 };
1729                 long[] c4 = new long [3];
1730
1731                 for (int i = 0; i < c3.Length; i++)
1732                         c4.SetValue (c3 [i], i);
1733
1734                 try {
1735                         c3.CopyTo (c4, 0);
1736                 } catch (Exception e) {
1737                         Assert.Fail ("c3.CopyTo(): e=" + e);
1738                 }
1739                 for (int i = 0; i < c3.Length; i++)
1740                         Assert.IsTrue (c3[i] == c4[i], "#M05(" + i + ")");
1741
1742                 Object[] c5 = new Object [3];
1743                 long[] c6 = new long [3];
1744
1745                 try {
1746                         c4.CopyTo (c5, 0);
1747                 } catch (Exception e) {
1748                         Assert.Fail ("c4.CopyTo(): e=" + e);
1749                 }
1750
1751                 try {
1752                         c5.CopyTo (c6, 0);
1753                 } catch (Exception e) {
1754                         Assert.Fail ("c5.CopyTo(): e=" + e);
1755                 }
1756                 // for (int i = 0; i < c5.Length; i++)
1757                 // Assert.IsTrue (c5[i] == c6[i], "#M06(" + i + ")");
1758         }
1759
1760         [Test]
1761         public void TestSetValue2() {
1762                 {
1763                         bool errorThrown = false;
1764                         try {
1765                                 char[] c = new Char[2];
1766                                 c.SetValue("buh", 1,1);
1767                         } catch (ArgumentException) {
1768                                 errorThrown = true;
1769                         }
1770                         Assert.IsTrue (errorThrown, "#M21");
1771                 }
1772                 {
1773                         bool errorThrown = false;
1774                         try {
1775                                 char[,] c = new Char[2,2];
1776                                 c.SetValue("buh", -1, 1);
1777                         } catch (IndexOutOfRangeException) {
1778                                 errorThrown = true;
1779                         }
1780                         Assert.IsTrue (errorThrown, "#M22");
1781                 }
1782                 {
1783                         bool errorThrown = false;
1784                         try {
1785                                 char[,] c = new Char[2,2];
1786                                 c.SetValue("buh", 4,1);
1787                         } catch (IndexOutOfRangeException) {
1788                                 errorThrown = true;
1789                         }
1790                         Assert.IsTrue (errorThrown, "#M23");
1791                 }
1792
1793                 char[,] c1 = new Char[4,6];
1794                 char[,] c2 = new Char[4,6];
1795                 for (int i = 0; i < 24; i++) {
1796                         int first = i / 6;
1797                         int second = i % 6;
1798                         c1[first,second] = (char)(((int)'a')+i);
1799                         c2.SetValue(c1[first,second], first, second);
1800                 }
1801                 for (int i = 0; i < c1.GetLength(0); i++) {
1802                         for (int j = 0; j < c1.GetLength(1); j++) {
1803                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M24(" + i + "," + j + ")");
1804                         }
1805                 }
1806         }
1807
1808         [Test]
1809         public void TestSetValue3() {
1810                 {
1811                         bool errorThrown = false;
1812                         try {
1813                                 char[] c = new Char[2];
1814                                 c.SetValue("buh", 1,1,1);
1815                         } catch (ArgumentException) {
1816                                 errorThrown = true;
1817                         }
1818                         Assert.IsTrue (errorThrown, "#M41");
1819                 }
1820                 {
1821                         bool errorThrown = false;
1822                         try {
1823                                 char[,,] c = new Char[2,2,2];
1824                                 c.SetValue("buh", -1, 1, 1);
1825                         } catch (IndexOutOfRangeException) {
1826                                 errorThrown = true;
1827                         }
1828                         Assert.IsTrue (errorThrown, "#M42");
1829                 }
1830                 {
1831                         bool errorThrown = false;
1832                         try {
1833                                 char[,,] c = new Char[2,2,2];
1834                                 c.SetValue("buh", 4,1,1);
1835                         } catch (IndexOutOfRangeException) {
1836                                 errorThrown = true;
1837                         }
1838                         Assert.IsTrue (errorThrown, "#M43");
1839                 }
1840
1841                 char[,,] c1 = new Char[4,2,3];
1842                 char[,,] c2 = new Char[4,2,3];
1843                 for (int i = 0; i < 24; i++) {
1844                         int first = i / 6;
1845                         int remains = i % 6;
1846                         int second = remains / 3;
1847                         int third = remains % 3;
1848                         c1[first,second, third] = (char)(((int)'a')+i);
1849                         c2.SetValue(c1[first, second, third], first, second, third);
1850                 }
1851                 for (int i = 0; i < c1.GetLength(0); i++) {
1852                         for (int j = 0; j < c1.GetLength(1); j++) {
1853                                 for (int k = 0; k < c1.GetLength(2); k++) {
1854                                         Assert.AreEqual (c1[i, j, k], c2[i, j, k], "#M44(" + i + "," + j + " )");
1855                                 }
1856                         }
1857                 }
1858         }
1859
1860         [Test]
1861 #if NET_2_0
1862         [ExpectedException (typeof (ArgumentNullException))]
1863 #else
1864         [ExpectedException (typeof (NullReferenceException))]
1865 #endif
1866         public void TestSetValueLongArray ()
1867         {
1868                 char[] c = new Char[2];
1869                 c.SetValue("buh", (long [])null);
1870         }
1871
1872         [Test]
1873         public void TestSetValueN() {
1874                 {
1875                         bool errorThrown = false;
1876                         try {
1877                                 char[] c = new Char[2];
1878                                 c.SetValue("buh", (int [])null);
1879                         } catch (ArgumentNullException) {
1880                                 errorThrown = true;
1881                         }
1882                         Assert.IsTrue (errorThrown, "#M61a");
1883                 }
1884                 {
1885                         bool errorThrown = false;
1886                         try {
1887                                 char[] c = new Char[2];
1888                                 int[] coords = {1, 1};
1889                                 c.SetValue("buh", coords);
1890                         } catch (ArgumentException) {
1891                                 errorThrown = true;
1892                         }
1893                         Assert.IsTrue (errorThrown, "#M62");
1894                 }
1895                 {
1896                         bool errorThrown = false;
1897                         try {
1898                                 char[,] c = new Char[2,2];
1899                                 int[] coords = {-1, 1};
1900                                 c.SetValue("buh", coords);
1901                         } catch (IndexOutOfRangeException) {
1902                                 errorThrown = true;
1903                         }
1904                         Assert.IsTrue (errorThrown, "#M63");
1905                 }
1906                 {
1907                         bool errorThrown = false;
1908                         try {
1909                                 char[,] c = new Char[2,2];
1910                                 int[] coords = {4, 1};
1911                                 c.SetValue("buh", coords);
1912                         } catch (IndexOutOfRangeException) {
1913                                 errorThrown = true;
1914                         }
1915                         Assert.IsTrue (errorThrown, "#M64");
1916                 }
1917
1918                 char[,] c1 = new Char[4,6];
1919                 char[,] c2 = new Char[4,6];
1920                 for (int i = 0; i < 24; i++) {
1921                         int first = i / 6;
1922                         int second = i % 6;
1923                         c1[first,second] = (char)(((int)'a')+i);
1924                         int[] coords = {first, second};
1925                         c2.SetValue(c1[first,second], coords);
1926                 }
1927                 for (int i = 0; i < c1.GetLength(0); i++) {
1928                         for (int j = 0; j < c1.GetLength(1); j++) {
1929                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M65(" + i + "," + j + ")");
1930                         }
1931                 }
1932         }
1933
1934         [Test]
1935         public void TestSetValue4() {
1936                 {
1937                         int[] c1 = { 1, 2, 3 };
1938                         long[] c2 = new long [3];
1939
1940                         for (int i = 0; i < c1.Length; i++)
1941                                 c2.SetValue (c1 [i], i);
1942
1943                         for (int i = 0; i < c1.Length; i++) {
1944                                 Assert.IsTrue (c1[i] == c2[i], "#M81(" + i + ")");
1945                                 Assert.AreEqual (typeof (long), c2[i].GetType (), "#M82(" + i + ")");
1946                         }
1947                 }
1948                 {
1949                         long[] c1 = { 1, 2, 3 };
1950                         int[] c2 = new int [3];
1951                         bool errorThrown = false;
1952                         try {
1953                                 c2.SetValue (c1 [0], 0);
1954                         } catch (ArgumentException) {
1955                                 errorThrown = true;
1956                         }
1957                         Assert.IsTrue (errorThrown, "#M83");
1958                 }
1959                 {
1960                         int[] c1 = { 1, 2, 3 };
1961                         Object[] c2 = new Object [3];
1962
1963                         for (int i = 0; i < c1.Length; i++)
1964                                 c2.SetValue (c1 [i], i);
1965
1966                         for (int i = 0; i < c1.Length; i++)
1967                                 Assert.AreEqual (c1[i], Convert.ToInt32 (c2[i]), "#M84(" + i + ")");
1968                 }
1969                 {
1970                         Object[] c1 = new Object [3];
1971                         Object[] c2 = new Object [3];
1972                         c1[0] = new Object ();
1973
1974                         for (int i = 0; i < c1.Length; i++)
1975                                 c2.SetValue (c1 [i], i);
1976
1977                         for (int i = 0; i < c1.Length; i++)
1978                                 Assert.AreEqual (c1[i], c2[i], "#M85(" + i + ")");
1979                 }
1980                 {
1981                         Object[] c1 = new Object [3];
1982                         string[] c2 = new String [3];
1983                         string test = "hello";
1984                         c1[0] = test;
1985
1986                         c2.SetValue (c1 [0], 0);
1987                         Assert.AreEqual (c1[0], c2[0], "#M86");
1988                         Assert.AreEqual ("hello", c2[0], "#M87");
1989                 }
1990                 {
1991                         char[] c1 = { 'a', 'b', 'c' };
1992                         string[] c2 = new string [3];
1993                         try {
1994                                 c2.SetValue (c1 [0], 0);
1995                                 Assert.Fail ("#M88");
1996                         } catch (InvalidCastException) {}
1997                 }
1998                 {
1999                         Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
2000                         long[] c2 = new long [3];
2001                         try {
2002                                 c2.SetValue (c1 [0], 0);
2003                                 Assert.Fail ("#M89");
2004                         } catch (ArgumentException) {}
2005                 }
2006                 {
2007                         Type[] types = {
2008                                 typeof (Boolean),
2009                                 typeof (Byte),
2010                                 typeof (Char),
2011                                 typeof (Double),
2012                                 typeof (Int16),
2013                                 typeof (Int32),
2014                                 typeof (Int64),
2015                                 typeof (SByte),
2016                                 typeof (Single),
2017                                 typeof (UInt16),
2018                                 typeof (UInt32),
2019                                 typeof (UInt64)
2020                         };
2021
2022                         bool v1 = true;
2023                         Byte v2 = 1;
2024                         Char v3 = 'a';
2025                         Double v4 = -1.2;
2026                         Int16 v5 = -32;
2027                         Int32 v6 = -234;
2028                         Int64 v7 = -34523;
2029                         SByte v8 = -1;
2030                         Single v9 = -4.8F;
2031                         UInt16 v10 = 24234;
2032                         UInt32 v11 = 235354;
2033                         UInt64 v12 = 234552;
2034
2035                         Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
2036                         Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
2037                                          "-4.8F", "24234", "235354", "234552" };
2038
2039                         Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
2040
2041                         int[] arg_ex = {
2042                                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2043                                 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
2044                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2045                                 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
2046                                 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
2047                                 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
2048                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
2049                                 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
2050                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
2051                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2052                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
2053                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
2054                         };
2055
2056                         // SetValue
2057
2058                         for (int i = 0; i < types.Length; i++) {
2059                                 for (int j = 0; j < types.Length; j++) {
2060                                         Array array = Array.CreateInstance (types [j], 2);
2061
2062                                         Object value = vt[j][i];
2063
2064                                         bool errorThrown = false;
2065                                         try {
2066                                                 array.SetValue (value, 0);
2067                                         } catch (ArgumentException) {
2068                                                 errorThrown = true;
2069                                         }
2070
2071                                         int ex_index = (i * types.Length) + j;
2072
2073                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M90(" + types [i] + "," + types [j] + ")");
2074                                 }
2075                         }
2076
2077                         for (int i = 0; i < types.Length; i++) {
2078                                 String[] array = new String [2];
2079
2080                                 Object value = va1 [i];
2081
2082                                 bool errorThrown = false;
2083                                 try {
2084                                         array.SetValue (value, 0);
2085                                 } catch (InvalidCastException) {
2086                                         errorThrown = true;
2087                                 }
2088
2089                                 Assert.IsTrue (errorThrown, "#M91(" + types [i] + ")");
2090                         }
2091
2092                         for (int i = 0; i < types.Length; i++) {
2093                                 Array array = Array.CreateInstance (types [i], 2);
2094
2095                                 Object value = va2 [i];
2096
2097                                 bool errorThrown = false;
2098                                 try {
2099                                         array.SetValue (value, 0);
2100                                 } catch (InvalidCastException) {
2101                                         errorThrown = true;
2102                                 }
2103
2104                                 Assert.IsTrue (errorThrown, "#M92(" + types [i] + ")");
2105                         }
2106
2107                         for (int i = 0; i < types.Length; i++) {
2108                                 Array array = Array.CreateInstance (types [i], 2);
2109
2110                                 Object value = null;
2111
2112                                 bool errorThrown = false;
2113                                 try {
2114                                         array.SetValue (value, 0);
2115                                 } catch (InvalidCastException) {
2116                                         errorThrown = true;
2117                                 }
2118
2119                                 Assert.IsTrue (!errorThrown, "#M93(" + types [i] + ")");
2120                         }
2121
2122                         // Copy
2123
2124                         for (int i = 0; i < types.Length; i++) {
2125                                 for (int j = 0; j < types.Length; j++) {
2126                                         Array source = Array.CreateInstance (types [i], 2);
2127                                         Array array = Array.CreateInstance (types [j], 2);
2128
2129                                         source.SetValue (vt[j][i], 0);
2130                                         source.SetValue (vt[j][i], 1);
2131
2132                                         bool errorThrown = false;
2133                                         try {
2134                                                 Array.Copy (source, array, 2);
2135                                         } catch (ArrayTypeMismatchException) {
2136                                                 errorThrown = true;
2137                                         }
2138
2139                                         int ex_index = (i * types.Length) + j;
2140
2141                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M94(" + types [i] + "," + types [j] + ")");
2142                                 }
2143                         }
2144
2145                         for (int i = 0; i < types.Length; i++) {
2146                                 Array source = Array.CreateInstance (types [i], 2);
2147                                 String[] array = new String [2];
2148
2149                                 source.SetValue (va1 [i], 0);
2150                                 source.SetValue (va1 [i], 1);
2151
2152                                 bool errorThrown = false;
2153                                 try {
2154                                         Array.Copy (source, array, 2);
2155                                 } catch (ArrayTypeMismatchException) {
2156                                         errorThrown = true;
2157                                 }
2158
2159                                 Assert.IsTrue (errorThrown, "#M95(" + types [i] + ")");
2160                         }
2161
2162                         for (int i = 0; i < types.Length; i++) {
2163                                 String[] source = new String [2];
2164                                 Array array = Array.CreateInstance (types [i], 2);
2165
2166                                 source.SetValue (va2 [i], 0);
2167                                 source.SetValue (va2 [i], 1);
2168
2169                                 bool errorThrown = false;
2170                                 try {
2171                                         Array.Copy (source, array, 2);
2172                                 } catch (ArrayTypeMismatchException) {
2173                                         errorThrown = true;
2174                                 }
2175
2176                                 Assert.IsTrue (errorThrown, "#M96(" + types [i] + ")");
2177                         }
2178                 }
2179         }
2180
2181         [Test]
2182         public void TestSort() {
2183                 {
2184                         bool errorThrown = false;
2185                         try {
2186                                 Array.Sort(null);
2187                         } catch (ArgumentNullException) {
2188                                 errorThrown = true;
2189                         }
2190                         Assert.IsTrue (errorThrown, "#N01");
2191                 }
2192                 {
2193                         bool errorThrown = false;
2194                         try {
2195                                 Array.Sort(null, 0, 1);
2196                         } catch (ArgumentNullException) {
2197                                 errorThrown = true;
2198                         }
2199                         Assert.IsTrue (errorThrown, "#N02");
2200                 }
2201                 {
2202                         bool errorThrown = false;
2203                         try {
2204                                 char[] c1 = new Char[2];
2205                                 Array.Sort(null, c1);
2206                         } catch (ArgumentNullException) {
2207                                 errorThrown = true;
2208                         }
2209                         Assert.IsTrue (errorThrown, "#N03");
2210                 }
2211                 {
2212                         bool errorThrown = false;
2213                         try {
2214                                 char[] c1 = new Char[2];
2215                                 Array.Sort(null, c1, 0, 1);
2216                         } catch (ArgumentNullException) {
2217                                 errorThrown = true;
2218                         }
2219                         Assert.IsTrue (errorThrown, "#N04");
2220                 }
2221                 {
2222                         int tc = 5;
2223                         char[] arr = {'d', 'b', 'f', 'e', 'a', 'c'};
2224                         
2225                         try {
2226                                 Array.Sort (null, 0, 1);
2227                                 Assert.Fail ("#N" + tc.ToString ());
2228                         }
2229                         catch (ArgumentException) {}
2230                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2231                         tc++;
2232                         
2233                         try {
2234                                 Array.Sort (arr, -1, 3);
2235                                 Assert.Fail ("#N" + tc.ToString ());
2236                         }
2237                         catch (ArgumentException) {}
2238                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2239                         tc++;
2240                         
2241                         try {
2242                                 Array.Sort (arr, 1, -3);
2243                                 Assert.Fail ("#N" + tc.ToString ());
2244                         }
2245                         catch (ArgumentException) {}
2246                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2247                         tc++;
2248                         
2249                         try {
2250                                 Array.Sort (arr, arr.Length, arr.Length + 2);
2251                                 Assert.Fail ("#N" + tc.ToString ());
2252                         }
2253                         catch (ArgumentException) {}
2254                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2255                 }
2256                 
2257                 // note: null second array => just sort first array
2258                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
2259                 int[] starter1 = {1,2,3,4,5,6};
2260                 {
2261                         char[] c1 = (char[])starter.Clone();
2262                         Array.Sort(c1);
2263                         Assert.AreEqual ('a', c1[0], "#N21");
2264                         Assert.AreEqual ('b', c1[1], "#N22");
2265                         Assert.AreEqual ('c', c1[2], "#N23");
2266                         Assert.AreEqual ('d', c1[3], "#N24");
2267                         Assert.AreEqual ('e', c1[4], "#N25");
2268                         Assert.AreEqual ('f', c1[5], "#N26");
2269                 }
2270                 {
2271                         char[] c1 = (char[])starter.Clone();
2272                         int[] i1 = (int[])starter1.Clone();
2273                         Array.Sort(c1, i1);
2274                         Assert.AreEqual ('a', c1[0], "#N41");
2275                         Assert.AreEqual ('b', c1[1], "#N42");
2276                         Assert.AreEqual ('c', c1[2], "#N43");
2277                         Assert.AreEqual ('d', c1[3], "#N44");
2278                         Assert.AreEqual ('e', c1[4], "#N45");
2279                         Assert.AreEqual ('f', c1[5], "#N46");
2280                         Assert.AreEqual (5, i1[0], "#N47");
2281                         Assert.AreEqual (2, i1[1], "#N48");
2282                         Assert.AreEqual (6, i1[2], "#N49");
2283                         Assert.AreEqual (1, i1[3], "#N50");
2284                         Assert.AreEqual (4, i1[4], "#N51");
2285                         Assert.AreEqual (3, i1[5], "#N52");
2286                 }
2287                 {
2288                         char[] c1 = (char[])starter.Clone();
2289                         Array.Sort(c1, 1, 4);
2290                         Assert.AreEqual ('d', c1[0], "#N61");
2291                         Assert.AreEqual ('a', c1[1], "#N62");
2292                         Assert.AreEqual ('b', c1[2], "#N63");
2293                         Assert.AreEqual ('e', c1[3], "#N64");
2294                         Assert.AreEqual ('f', c1[4], "#N65");
2295                         Assert.AreEqual ('c', c1[5], "#N66");
2296                 }
2297                 {
2298                         char[] c1 = (char[])starter.Clone();
2299                         int[] i1 = (int[])starter1.Clone();
2300                         Array.Sort(c1, i1, 1, 4);
2301                         Assert.AreEqual ('d', c1[0], "#N81");
2302                         Assert.AreEqual ('a', c1[1], "#N82");
2303                         Assert.AreEqual ('b', c1[2], "#N83");
2304                         Assert.AreEqual ('e', c1[3], "#N84");
2305                         Assert.AreEqual ('f', c1[4], "#N85");
2306                         Assert.AreEqual ('c', c1[5], "#N86");
2307                         Assert.AreEqual (1, i1[0], "#N87");
2308                         Assert.AreEqual (5, i1[1], "#N88");
2309                         Assert.AreEqual (2, i1[2], "#N89");
2310                         Assert.AreEqual (4, i1[3], "#N90");
2311                         Assert.AreEqual (3, i1[4], "#N91");
2312                         Assert.AreEqual (6, i1[5], "#N92");
2313                 }
2314         }
2315
2316         [Test]
2317         public void TestInitializeEmpty()
2318         {
2319                 bool catched=false;
2320                 int[] a = {};
2321                 try
2322                 {
2323                         a.Initialize();
2324                 }
2325                 catch(Exception)
2326                 {
2327                         catched=true;
2328                 }
2329                 Assert.IsTrue (!catched, "#TI01");
2330         }
2331
2332         [Test]
2333         public void TestInitializeInt()
2334         {
2335                 int[] a = {1,2,0};
2336                 a.Initialize();
2337                 int[] b = {1,2,0};
2338                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2339                 {
2340                         Assert.AreEqual (a[i], b[i], "#TI02 " + i);
2341                 }
2342         }
2343
2344         [Test]
2345         public void TestInitializeDouble()
2346         {
2347                 double[] a = {1.0,2.0,0.0};
2348                 a.Initialize();
2349                 double[] b = {1.0,2.0,0.0};
2350                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2351                 {
2352                         Assert.AreEqual (a[i], b[i], "#TI03 " + i);
2353                 }
2354         }
2355
2356         [Test]
2357         public void TestInitializeFloat()
2358         {
2359                 float[] a = {1.0F,2.0F,0.0F};
2360                 a.Initialize();
2361                 float[] b = {1.0F,2.0F,0.0F};
2362                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2363                 {
2364                         Assert.AreEqual (a[i], b[i], "#TI04 " + i);
2365                 }
2366         }
2367
2368         [Test]
2369         public void TestInitializeChar()
2370         {
2371                 char[] a = {'1','.','0','F','2','.','0','F'};
2372                 a.Initialize();
2373                 char[] b = {'1','.','0','F','2','.','0','F'};
2374                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2375                 {
2376                         Assert.AreEqual (a[i], b[i], "#TI05 " + i);
2377                 }
2378         }
2379
2380         [Test]
2381         public void TestInitializeString()
2382         {
2383                 string[] a = {"hola","adios","menos","mas"};
2384                 a.Initialize();
2385                 string[] b = {"hola","adios","menos","mas"};
2386                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2387                 {
2388                         Assert.AreEqual (a[i], b[i], "#TI06 " + i);
2389                 }
2390         }
2391
2392         [Test]
2393         public void TestInitializeEnum()
2394         {
2395                 enua[] a = {enua.hola,enua.adios,enua.menos,enua.mas};
2396                 a.Initialize();
2397                 enua[] b = {enua.hola,enua.adios,enua.menos,enua.mas};
2398                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2399                 {
2400                         Assert.AreEqual (a[i], b[i], "#TI07 " + i);
2401                 }
2402         }
2403         
2404         [Test]
2405         public void TestInitializeIntNI()
2406         {
2407                 int[] a = new int[20];
2408                 a.Initialize();
2409                 foreach(int b in a)
2410                 {
2411                         Assert.AreEqual (b, 0, "#TI08");
2412                 }
2413         }
2414         
2415         [Test]
2416         public void TestInitializeCharNI()
2417         {
2418                 char[] a = new char[20];
2419                 a.Initialize();
2420                 foreach(char b in a)
2421                 {
2422                         Assert.AreEqual (b, 0, "#TI09");
2423                 }
2424         }
2425         
2426         [Test]
2427         public void TestInitializeDoubleNI()
2428         {
2429                 double[] a = new double[20];
2430                 a.Initialize();
2431                 foreach(double b in a)
2432                 {
2433                         Assert.AreEqual (b, 0.0, "#TI09");
2434                 }
2435         }
2436         
2437         [Test]
2438         public void TestInitializeStringNI()
2439         {
2440                 string[] a = new string[20];
2441                 a.Initialize();
2442                 foreach(string b in a)
2443                 {
2444                         Assert.AreEqual (b, null, "#TI10");
2445                 }
2446         }
2447         
2448         [Test]
2449         public void TestInitializeObjectNI()
2450         {
2451                 object[] a = new object[20];
2452                 a.Initialize();
2453                 foreach(object b in a)
2454                 {
2455                         Assert.AreEqual (b, null, "#TI11");
2456                 }
2457         }
2458
2459         [Test]
2460         public void TestInitializeAClassNI()
2461         {
2462                 AClass[] a = new AClass[20];
2463                 a.Initialize();
2464                 foreach(AClass b in a)
2465                 {
2466                         Assert.AreEqual (b, null, "#TI12");
2467                 }
2468         }
2469
2470
2471         [Test]
2472         public void TestInitializeAStructNI()
2473         {
2474                 AStruct[] a = new AStruct[20];
2475                 a.Initialize();
2476                 foreach(AStruct b in a)
2477                 {
2478                         Assert.AreEqual (b, new AStruct(), "#TI14");
2479                 }
2480         }
2481
2482         [Test]
2483         public void TestInitializeAStruct()
2484         {
2485                 AStruct[] a = new AStruct[3];
2486                 a[1].a = "ADIOS";
2487                 a[1].s = "HOLA";
2488                 a.Initialize();
2489                 AStruct[] b = new AStruct[3];
2490                 b[1].a = "ADIOS";
2491                 b[1].s = "HOLA";
2492                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2493                 {
2494                         Assert.AreEqual (a[i], b[i], "#TI15 " + i);
2495                 }
2496         }
2497
2498         [Test]
2499         public void TestInitializeDateTimeNI()
2500         {
2501                 DateTime[] a = new DateTime[20];
2502                 a.Initialize();
2503                 foreach(DateTime b in a)
2504                 {
2505                         Assert.AreEqual (b, new DateTime(), "#TI16");
2506                 }
2507         }
2508         
2509         [Test]
2510         [ExpectedException (typeof (ArgumentNullException))]
2511         public void MoreSort1 ()
2512         {
2513                 Array.Sort (null, 0, 1);
2514         }
2515
2516         [Test]
2517         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2518         public void MoreSort2 ()
2519         {
2520                 Array.Sort (arrsort, -1, 3);
2521         }
2522
2523         [Test]
2524         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2525         public void MoreSort3 ()
2526         {
2527                 Array.Sort (arrsort, 1, -3);
2528         }
2529
2530         [Test]
2531         [ExpectedException (typeof (ArgumentException))]
2532         public void MoreSort4 ()
2533         {
2534                 Array.Sort (arrsort, arrsort.Length, arrsort.Length + 2);
2535         }
2536
2537         [Test]
2538         [ExpectedException (typeof (RankException))]
2539         public void MoreSort5 ()
2540         {
2541                 char [,] arr = new char [,] {{'a'}, {'b'}};
2542                 Array.Sort (arr, 0, 1);
2543         }
2544
2545         [Test]
2546         public void MoreSort6 ()
2547         {
2548                 Array.Sort (arrsort, 0, 0);
2549         }
2550
2551         [Test]
2552         [ExpectedException (typeof (ArgumentException))]
2553         public void MoreSort7 ()
2554         {
2555                 Array.Sort (arrsort, arrsort.Length - 1, 2);
2556         }
2557
2558         [Test]
2559         [ExpectedException (typeof (ArgumentException))]
2560         public void MoreSort8 ()
2561         {
2562                 Array.Sort (arrsort, 0, arrsort.Length + 1);
2563         }
2564
2565         [Test]
2566         public void MoreSort9 ()
2567         {
2568                 Array.Sort (arrsort, null, 0, arrsort.Length, null);
2569         }
2570
2571         [Test]
2572         [ExpectedException (typeof (InvalidOperationException))]
2573         public void MoreSort10 ()
2574         {
2575                 object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
2576                 Array.Sort (array, (IComparer) null);
2577         }
2578
2579         [Test] // bug #81941
2580         public void Sort ()
2581         {
2582                 double [] a = new double [2] { 0.9, 0.3 };
2583                 uint [] b = new uint [2] { 4, 7 };
2584                 Array.Sort (a, b);
2585                 Assert.AreEqual (0.3, a [0], "#1");
2586                 Assert.AreEqual (0.9, a [1], "#2");
2587                 Assert.AreEqual (7, b [0], "#3");
2588                 Assert.AreEqual (4, b [1], "#4");
2589         }
2590
2591         [Test]
2592         public void ClearJaggedArray () 
2593         {
2594                 byte[][] matrix = new byte [8][];
2595                 for (int i=0; i < 8; i++) {
2596                         matrix [i] = new byte [8];
2597                         for (int j=0; j < 8; j++) {
2598                                 matrix [i][j] = 1;
2599                         }
2600                 }
2601                 Array.Clear (matrix, 0, 8);
2602                 for (int i=0; i < 8; i++) {
2603                         Assert.IsNull (matrix [i], i.ToString ());
2604                 }
2605         }
2606
2607         [Test]
2608         public void ClearMultidimentionalArray () 
2609         {
2610                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2611                 Array.Clear (matrix, 0, 2);
2612                 Assert.AreEqual (0, matrix [0, 0], "0,0");
2613                 Assert.AreEqual (0, matrix [0, 1], "0,1");
2614                 Assert.AreEqual (2, matrix [1, 0], "1,0");
2615                 Assert.AreEqual (2, matrix [1, 1], "1,1");
2616         }
2617
2618         [Test]
2619         [ExpectedException (typeof (IndexOutOfRangeException))]
2620         public void ClearOutsideMultidimentionalArray () 
2621         {
2622                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2623                 Array.Clear (matrix, 0, 5);
2624         }
2625
2626         [Test]
2627         [ExpectedException (typeof (IndexOutOfRangeException))]
2628         public void Clear_IndexOverflow () 
2629         {
2630                 byte[] array = new byte [16];
2631                 Array.Clear (array, 4, Int32.MaxValue);
2632         }
2633
2634         [Test]
2635         [ExpectedException (typeof (IndexOutOfRangeException))]
2636         public void Clear_LengthOverflow () 
2637         {
2638                 byte[] array = new byte [16];
2639                 Array.Clear (array, Int32.MaxValue, 4);
2640         }
2641
2642         [Test]
2643         [ExpectedException (typeof (ArgumentException))]
2644         public void Copy_SourceIndexOverflow () 
2645         {
2646                 byte[] array = new byte [16];
2647                 Array.Copy (array, Int32.MaxValue, array, 8, 8);
2648         }
2649
2650         [Test]
2651         [ExpectedException (typeof (ArgumentException))]
2652         public void Copy_DestinationIndexOverflow () 
2653         {
2654                 byte[] array = new byte [16];
2655                 Array.Copy (array, 8, array, Int32.MaxValue, 8);
2656         }
2657
2658         [Test]
2659         [ExpectedException (typeof (ArgumentException))]
2660         public void Copy_LengthOverflow () 
2661         {
2662                 byte[] array = new byte [16];
2663                 Array.Copy (array, 8, array, 8, Int32.MaxValue);
2664         }
2665
2666         [Test]
2667         [ExpectedException (typeof (ArgumentException))]
2668         public void Reverse_IndexOverflow () 
2669         {
2670                 byte[] array = new byte [16];
2671                 Array.Reverse (array, Int32.MaxValue, 8);
2672         }
2673
2674         [Test]
2675         [ExpectedException (typeof (ArgumentException))]
2676         public void Reverse_LengthOverflow () 
2677         {
2678                 byte[] array = new byte [16];
2679                 Array.Reverse (array, 8, Int32.MaxValue);
2680         }
2681         
2682         public struct CharX : IComparable {
2683                 public char c;
2684         
2685                 public CharX (char c)
2686                 {
2687                         this.c = c;
2688                 }
2689         
2690                 public int CompareTo (object obj)
2691                 {
2692                         if (obj is CharX)
2693                                 return c.CompareTo (((CharX) obj).c);
2694                         else
2695                                 return c.CompareTo (obj);
2696                 }
2697         }
2698
2699         [Test]
2700         public void BinarySearch_ArgPassingOrder ()
2701         {
2702                 //
2703                 // This tests that arguments are passed to the comprer in the correct
2704                 // order. The IComparable of the *array* elements must get called, not
2705                 // that of the search object.
2706                 //
2707                 CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX ('c') };
2708                 Assert.AreEqual (1, Array.BinarySearch (x, 'b'));
2709         }
2710
2711         class Comparer: IComparer {
2712
2713                 private bool called = false;
2714
2715                 public bool Called {
2716                         get {
2717                                 bool result = called;
2718                                 called = false;
2719                                 return called;
2720                         }
2721                 }
2722
2723                 public int Compare (object x, object y)
2724                 {
2725                         called = true;
2726                         return 0;
2727                 }
2728         }
2729
2730         [Test]
2731         public void BinarySearch1_EmptyList ()
2732         {
2733                 int[] array = new int[0];
2734                 Assert.AreEqual (- 1, Array.BinarySearch (array, 0), "BinarySearch");
2735         }
2736
2737         [Test]
2738         public void BinarySearch2_EmptyList ()
2739         {
2740                 int[] array = new int[0];
2741                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, 0), "BinarySearch");
2742         }
2743
2744         [Test]
2745         public void BinarySearch3_EmptyList ()
2746         {
2747                 Comparer comparer = new Comparer ();
2748                 int[] array = new int[0];
2749                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, comparer), "BinarySearch");
2750                 // bug 77030 - the comparer isn't called for an empty array/list
2751                 Assert.IsTrue (!comparer.Called, "Called");
2752         }
2753
2754         [Test]
2755         public void BinarySearch4_EmptyList ()
2756         {
2757                 Comparer comparer = new Comparer ();
2758                 int[] array = new int[0];
2759                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, comparer), "BinarySearch");
2760                 // bug 77030 - the comparer isn't called for an empty array/list
2761                 Assert.IsTrue (!comparer.Called, "Called");
2762         }
2763
2764 #if NET_2_0
2765         [Test]
2766         [ExpectedException (typeof (ArgumentNullException))]
2767         public void AsReadOnly_NullArray ()
2768         {
2769                 Array.AsReadOnly <int> (null);
2770         }
2771
2772         [Test]
2773         public void ReadOnly_Count ()
2774         {
2775                 Assert.AreEqual (10, Array.AsReadOnly (new int [10]).Count);
2776         }
2777
2778         [Test]
2779         public void ReadOnly_Contains ()
2780         {
2781                 int[] arr = new int [2];
2782                 arr [0] = 3;
2783                 arr [1] = 5;
2784                 IList<int> a = Array.AsReadOnly (arr);
2785
2786                 Assert.IsTrue (a.Contains (3));
2787                 Assert.IsTrue (!a.Contains (6));
2788         }
2789
2790         [Test]
2791         public void ReadOnly_IndexOf ()
2792         {
2793                 int[] arr = new int [2];
2794                 arr [0] = 3;
2795                 arr [1] = 5;
2796                 IList<int> a = Array.AsReadOnly (arr);
2797
2798                 Assert.AreEqual (0, a.IndexOf (3));
2799                 Assert.AreEqual (1, a.IndexOf (5));
2800                 Assert.AreEqual (-1, a.IndexOf (6));
2801         }
2802
2803         [Test]
2804         public void ReadOnly_Indexer ()
2805         {
2806                 int[] arr = new int [2];
2807                 arr [0] = 3;
2808                 arr [1] = 5;
2809                 IList<int> a = Array.AsReadOnly (arr);
2810
2811                 Assert.AreEqual (3, a [0]);
2812                 Assert.AreEqual (5, a [1]);
2813
2814                 /* Check that modifications to the original array are visible */
2815                 arr [0] = 6;
2816                 Assert.AreEqual (6, a [0]);
2817         }
2818
2819         [Test]
2820         public void ReadOnly_Enumerator ()
2821         {
2822                 int[] arr = new int [10];
2823
2824                 for (int i = 0; i < 10; ++i)
2825                         arr [i] = i;
2826
2827                 int sum = 0;
2828                 foreach (int i in Array.AsReadOnly (arr))
2829                         sum += i;
2830
2831                 Assert.AreEqual (45, sum);
2832         }
2833
2834         [Test]
2835         public void ReadOnly_CopyTo ()
2836         {
2837                 int[] arr = new int [2];
2838                 arr [0] = 3;
2839                 arr [1] = 5;
2840                 IList<int> a = Array.AsReadOnly (arr);
2841
2842                 int[] arr2 = new int [3];
2843                 a.CopyTo (arr2, 1);
2844
2845                 Assert.AreEqual (0, arr2 [0]);
2846                 Assert.AreEqual (3, arr2 [1]);
2847                 Assert.AreEqual (5, arr2 [2]);
2848         }
2849
2850         [Test]
2851         public void Resize ()
2852         {
2853                 int [] arr = new int [] { 1, 3, 5 };
2854                 Array.Resize <int> (ref arr, 3);
2855                 Assert.AreEqual (3, arr.Length, "#A1");
2856                 Assert.AreEqual (1, arr [0], "#A2");
2857                 Assert.AreEqual (3, arr [1], "#A3");
2858                 Assert.AreEqual (5, arr [2], "#A4");
2859
2860                 Array.Resize <int> (ref arr, 2);
2861                 Assert.AreEqual (2, arr.Length, "#B1");
2862                 Assert.AreEqual (1, arr [0], "#B2");
2863                 Assert.AreEqual (3, arr [1], "#B3");
2864
2865                 Array.Resize <int> (ref arr, 4);
2866                 Assert.AreEqual (4, arr.Length, "#C1");
2867                 Assert.AreEqual (1, arr [0], "#C2");
2868                 Assert.AreEqual (3, arr [1], "#C3");
2869                 Assert.AreEqual (0, arr [2], "#C4");
2870                 Assert.AreEqual (0, arr [3], "#C5");
2871         }
2872
2873         [Test]
2874         public void Resize_null ()
2875         {
2876                 int [] arr = null;
2877                 Array.Resize (ref arr, 10);
2878                 Assert.AreEqual (arr.Length, 10);
2879         }
2880
2881         [Test]
2882         public void Test_ContainsAndIndexOf_EquatableItem ()
2883         {
2884                 EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
2885
2886                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, list[0]), "#0");
2887                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)), "#1");
2888                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, list[0]), "#2");
2889                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)), "#3");
2890         }
2891
2892         public class EquatableClass : IEquatable<EquatableClass>
2893         {
2894                 int _x;
2895                 public EquatableClass (int x)
2896                 {
2897                         _x = x;
2898                 }
2899
2900                 public bool Equals (EquatableClass other)
2901                 {
2902                         return this._x == other._x;
2903                 }
2904         }
2905
2906         [Test]
2907         public void AsIList ()
2908         {
2909                 IList<int> arr = new int [10];
2910                 arr [0] = 5;
2911                 Assert.AreEqual (5, arr [0]);
2912
2913                 IList<FooStruct> arr2 = new FooStruct [10];
2914                 FooStruct s = new FooStruct ();
2915                 s.i = 11;
2916                 s.j = 22;
2917                 arr2 [5] = s;
2918                 s = arr2 [5];
2919                 Assert.AreEqual (11, s.i);
2920                 Assert.AreEqual (22, s.j);
2921
2922                 IList<string> arr3 = new string [10];
2923                 arr3 [5] = "ABC";
2924                 Assert.AreEqual ("ABC", arr3 [5]);
2925         }
2926
2927         struct FooStruct {
2928                 public int i, j;
2929         }
2930
2931 #if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
2932         [Test]
2933         // From bug #80563
2934         public void ICollectionNull ()
2935         {
2936                 ICollection<object> test;
2937                 
2938                 test = new List<object>();
2939                 Assert.AreEqual (test.Contains (null), false, "list<o>");
2940
2941                 test = new object[] {};
2942                 Assert.AreEqual (test.Contains (null), false, "empty array");
2943
2944                 test = new object[] {null};
2945                 Assert.AreEqual (test.Contains (null), true, "array with null");
2946
2947                 test = new List<object>(test);
2948                 Assert.AreEqual (test.Contains (null), true, "List<object> with test");
2949                 
2950                 test = new object[] {new object()};
2951                 Assert.AreEqual (test.Contains (null), false, "array with object");
2952
2953                 test = new List<object>(test);
2954                 Assert.AreEqual (test.Contains (null), false, "array with test");
2955         }
2956 #endif // TARGET_JVM
2957 #endif
2958
2959         #region Bug 80299
2960
2961         enum ByteEnum : byte {}
2962         enum IntEnum : int {}
2963
2964         [Test]
2965         public void TestByteEnumArrayToByteArray ()
2966         {
2967                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2968                 byte[] b = new byte[a.Length];
2969                 a.CopyTo (b, 0);
2970         }
2971
2972         [Test]
2973         public void TestByteEnumArrayToIntArray ()
2974         {
2975                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2976                 int[] b = new int[a.Length];
2977                 a.CopyTo (b, 0);
2978         }
2979
2980         [Test]
2981         [ExpectedException (typeof (ArrayTypeMismatchException))]
2982         public void TestIntEnumArrayToByteArray ()
2983         {
2984                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2985                 byte[] b = new byte[a.Length];
2986                 a.CopyTo (b, 0);
2987         }
2988
2989         [Test]
2990         public void TestIntEnumArrayToIntArray ()
2991         {
2992                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2993                 int[] b = new int[a.Length];
2994                 a.CopyTo (b, 0);
2995         }
2996
2997         #endregion
2998
2999 #if NET_2_0
3000         [Test] // bug #322248
3001         public void IEnumerator_Reset ()
3002         {
3003                 int[] array = new int[] { 1, 2, 3};
3004                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3005                 Assert.IsTrue (e.MoveNext (), "#A1");
3006                 Assert.AreEqual (1, e.Current, "#A2");
3007                 Assert.IsTrue (e.MoveNext (), "#A3");
3008                 Assert.AreEqual (2, e.Current, "#A4");
3009
3010                 e.Reset ();
3011
3012                 Assert.IsTrue (e.MoveNext (), "#C1");
3013                 Assert.AreEqual (1, e.Current, "#C2");
3014         }
3015
3016         [Test]
3017         public void IEnumerator_Current_Finished ()
3018         {
3019                 int[] array = new int[] { 1, 2, 3 };
3020                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3021                 Assert.IsTrue (e.MoveNext (), "#A1");
3022                 Assert.AreEqual (1, e.Current, "#A2");
3023                 Assert.IsTrue (e.MoveNext (), "#A3");
3024                 Assert.AreEqual (2, e.Current, "#A4");
3025                 Assert.IsTrue (e.MoveNext (), "#A5");
3026                 Assert.AreEqual (3, e.Current, "#A6");
3027                 Assert.IsTrue (!e.MoveNext (), "#A6");
3028
3029                 try {
3030                         Assert.Fail ("#B1:" + e.Current);
3031                 } catch (InvalidOperationException ex) {
3032                         // Enumeration already finished
3033                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3034                         Assert.IsNull (ex.InnerException, "#B3");
3035                         Assert.IsNotNull (ex.Message, "#B4");
3036                 }
3037         }
3038
3039         [Test]
3040         public void IEnumerator_Current_NotStarted ()
3041         {
3042                 int[] array = new int[] { 1, 2, 3 };
3043                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3044
3045                 try {
3046                         Assert.Fail ("#A1:" + e.Current);
3047                 } catch (InvalidOperationException ex) {
3048                         // Enumeration has not started. Call MoveNext
3049                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
3050                         Assert.IsNull (ex.InnerException, "#A3");
3051                         Assert.IsNotNull (ex.Message, "#A4");
3052                 }
3053         }
3054
3055         [Test]
3056         public void IEnumerator_Current_Reset ()
3057         {
3058                 int[] array = new int[] { 1, 2, 3 };
3059                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3060                 e.MoveNext ();
3061                 e.Reset ();
3062
3063                 try {
3064                         Assert.Fail ("#B1:" + e.Current);
3065                 } catch (InvalidOperationException ex) {
3066                         // Enumeration has not started. Call MoveNext
3067                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3068                         Assert.IsNull (ex.InnerException, "#B3");
3069                         Assert.IsNotNull (ex.Message, "#B4");
3070                 }
3071         }
3072
3073         public void ICollection_IsReadOnly() {
3074                 ICollection<string> arr = new string [10];
3075
3076                 Assert.IsTrue (arr.IsReadOnly);
3077         }
3078 #endif
3079
3080         [Test]
3081         [ExpectedException (typeof (NotSupportedException))]
3082         public void ArrayCreateInstanceOfVoid ()
3083         {
3084                 Array.CreateInstance (typeof (void), 42);
3085         }
3086
3087         class Foo<T> {}
3088
3089         [Test]
3090         [ExpectedException (typeof (NotSupportedException))]
3091         public void ArrayCreateInstanceOfOpenGenericType ()
3092         {
3093                 Array.CreateInstance (typeof (Foo<>), 42);
3094         }
3095
3096         [Test]
3097         [ExpectedException (typeof (IndexOutOfRangeException))]
3098         public void ClearNegativeLength ()
3099         {
3100                 Array.Clear (new int [] { 1, 2 }, 0, -1);
3101         }
3102
3103         [Test]
3104         [ExpectedException (typeof (ArgumentException))]
3105         public void MultiDimension_IList_setItem ()
3106         {
3107                 IList array = new int [1, 1];
3108                 array [0] = 2;
3109         }
3110
3111         [Test]
3112         [ExpectedException (typeof (ArgumentException))]
3113         public void MultiDimension_IList_getItem ()
3114         {
3115                 IList array = new int [1, 1];
3116                 int a = (int) array [0];
3117         }
3118
3119         [Test]
3120         public void SetValue_Nullable () {
3121                 Array array = Array.CreateInstance (typeof (int?), 7);
3122
3123                 object o = 42;
3124
3125                 array.SetValue (o, 0);
3126                 Assert.AreEqual (42, array.GetValue (0));
3127
3128                 array.SetValue (null, 0);
3129                 Assert.AreEqual (null, array.GetValue (0));
3130         }
3131
3132 #if NET_4_0
3133         [Test]
3134         [ExpectedException (typeof (ArgumentException))]
3135         public void CompareToWithJaggedArray () {
3136                 IStructuralComparable a = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3137                 IStructuralComparable b = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3138                 a.CompareTo (b, Comparer<object>.Default);
3139         }
3140
3141         [Test]
3142         [ExpectedException (typeof (ArgumentException))]
3143         public void CompareToWithArrayOfTheWrongKind () {
3144                 IStructuralComparable a = new int[] { 1, 2 };
3145                 IStructuralComparable b = new double[] { 1, 2 };
3146                 a.CompareTo (b, Comparer<object>.Default);
3147         }
3148
3149         [Test]
3150         [ExpectedException (typeof (ArgumentException))]
3151         public void CompareToWithNonArrayType () {
3152                 IStructuralComparable a = new int[] { 1, 2 };
3153                 a.CompareTo (99, Comparer<object>.Default);
3154         }
3155
3156         [Test]
3157         [ExpectedException (typeof (ArgumentException))]
3158         public void CompareToWithNonArrayOfDifferentSize () {
3159                 IStructuralComparable a = new int[] { 1, 2 };
3160                 IStructuralComparable b = new int[] { 1, 2, 3 };
3161                 a.CompareTo (b, Comparer<object>.Default);
3162         }
3163
3164         [Test]
3165         [ExpectedException (typeof (ArgumentException))]
3166         public void CompareToWithMultiDimArray1 () {
3167                 IStructuralComparable a = new int [2,2] { {10, 10 }, { 10, 10 } };
3168                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3169                 a.CompareTo (b, Comparer<object>.Default);
3170         }
3171
3172         [Test]
3173         [ExpectedException (typeof (ArgumentException))]
3174         public void CompareToWithMultiDimArray2 () {
3175                 IStructuralComparable a = new int [2] { 10, 10 };
3176                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3177                 a.CompareTo (b, Comparer<object>.Default);
3178         }
3179
3180         [Test]
3181         [ExpectedException (typeof (ArgumentException))]
3182         public void CompareToWithMultiDimArray3 () {
3183                 IStructuralComparable a = new int [4] { 10, 10, 10, 10 };
3184                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3185                 a.CompareTo (b, Comparer<object>.Default);
3186         }
3187
3188         [Test]
3189         [ExpectedException (typeof (IndexOutOfRangeException))]
3190         public void CompareToWithBoundedArray1 () {
3191                 IStructuralComparable a = new int [2] { 10, 10 };
3192                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3193                 IStructuralComparable b = ab;
3194                 ab.SetValue (10, 5);
3195                 ab.SetValue (10, 6);
3196
3197                 a.CompareTo (b, Comparer<object>.Default);
3198         }
3199
3200         [Test]
3201         [ExpectedException (typeof (IndexOutOfRangeException))]
3202         public void CompareToWithBoundedArray2 () {
3203                 IStructuralComparable a = new int [2] { 10, 10 };
3204                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3205                 IStructuralComparable b = ab;
3206                 ab.SetValue (10, 5);
3207                 ab.SetValue (10, 6);
3208
3209                 //Yes, CompareTo simply doesn't work with bounded arrays!
3210                 b.CompareTo (b, Comparer<object>.Default);
3211         }
3212
3213         [Test]
3214         [ExpectedException (typeof (NullReferenceException))]
3215         public void CompareToWithNullComparer () {
3216                 IStructuralComparable a = new int[] { 1, 2 };
3217                 IStructuralComparable b = new int[] { 1, 2 };
3218                 a.CompareTo (b, null);
3219         }
3220
3221         [Test]
3222         public void CompareToWithNullArray () {
3223                 IStructuralComparable a = new int[] { 1, 2 };
3224                 Assert.AreEqual (1, a.CompareTo (null, Comparer<object>.Default));
3225         }
3226
3227         [Test]
3228         public void CompareToWithGoodArrays () {
3229                 IStructuralComparable a = new int[] { 10, 20 };
3230                 Assert.AreEqual (0, a.CompareTo (a, Comparer<object>.Default));
3231                 Assert.AreEqual (0, a.CompareTo (new int [] { 10, 20 }, Comparer<object>.Default));
3232                 Assert.AreEqual (-1, a.CompareTo (new int [] { 11, 20 }, Comparer<object>.Default));
3233                 Assert.AreEqual (-1, a.CompareTo (new int [] { 10, 21 }, Comparer<object>.Default));
3234                 Assert.AreEqual (1, a.CompareTo (new int [] { 9, 20 }, Comparer<object>.Default));
3235                 Assert.AreEqual (1, a.CompareTo (new int [] { 10, 19 }, Comparer<object>.Default));
3236         }
3237
3238         [Test]
3239         public void IStructuralEquatable_Equals ()
3240         {
3241                 IStructuralEquatable array = new int[] {1, 2, 3};
3242                 IStructuralEquatable array2 = new int[] {1, 2, 3};
3243                 Assert.AreEqual (false, array.Equals (null, null));
3244                 Assert.AreEqual (true, array.Equals (array, null));
3245                 Assert.AreEqual (true, array.Equals (array2, EqualityComparer<int>.Default));
3246         }
3247
3248         [Test]
3249         [ExpectedException (typeof (NullReferenceException))]
3250         public void IStructuralEquatable_Equals_NoComparer ()
3251         {
3252                 IStructuralEquatable array = new int[] {1, 2, 3};
3253                 IStructuralComparable array2 = new int[] {1, 2, 3};
3254                 array.Equals (array2, null);
3255         }
3256
3257         [Test]
3258         [ExpectedException (typeof (ArgumentException))]
3259         public void IStructuralEquatable_Equals_ComparerThrows ()
3260         {
3261                 IStructuralEquatable array = new int[] {1, 2, 3};
3262                 IStructuralComparable array2 = new int[] {1, 2, 3};
3263                 array.Equals (array2, EqualityComparer<long>.Default);
3264         }
3265
3266 #endif
3267
3268 }
3269 }